Skip to content

Commit

Permalink
Fixes a call to dataSource id causing test failures
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed May 13, 2024
1 parent 7a26e9f commit 6e8284d
Show file tree
Hide file tree
Showing 26 changed files with 316 additions and 2,876 deletions.
Original file line number Diff line number Diff line change
@@ -1,91 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Audit logs edit Render unable to access dataSource when enabled and inaccessible 1`] = `
<div
className="panel-restrict-width"
>
<Memo()
coreStart={
Object {
"http": 1,
}
<Memo()
coreStart={
Object {
"http": 1,
}
dataSourcePickerReadOnly={true}
depsStart={
Object {
"dataSource": Object {
"dataSourceEnabled": true,
},
}
}
depsStart={
Object {
"dataSource": Object {
"dataSourceEnabled": true,
},
}
navigation={Object {}}
selectedDataSource={
Object {
"id": "test",
}
}
setDataSource={[MockFunction]}
/>
<EuiPageHeader>
<EuiTitle
size="l"
>
<h1>
Compliance settings
</h1>
</EuiTitle>
</EuiPageHeader>
<EuiPanel>
<EditSettingGroup
config={Object {}}
handleChange={[Function]}
settingGroup={
Object {
"settings": Array [
Object {
"description": "Enable or disable compliance logging.",
"path": "compliance.enabled",
"title": "Compliance logging",
"type": "bool",
},
],
"title": "Compliance mode",
}
}
/>
</EuiPanel>
<EuiSpacer />
<EuiFlexGroup
justifyContent="flexEnd"
>
<EuiFlexItem
grow={false}
>
<EuiButton
data-test-subj="cancel"
onClick={[Function]}
>
Cancel
</EuiButton>
</EuiFlexItem>
<EuiFlexItem
grow={false}
>
<EuiButton
data-test-subj="save"
fill={true}
isDisabled={false}
onClick={[Function]}
>
Save
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
<EuiGlobalToastList
dismissToast={[Function]}
side="right"
toastLifeTimeMs={10000}
toasts={Array []}
/>
</div>
}
navigation={Object {}}
/>
`;
Original file line number Diff line number Diff line change
@@ -1,113 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Audit logs Render unable to access dataSource when enabled and inaccessible 1`] = `
<div
className="panel-restrict-width"
>
<Memo()
coreStart={
Object {
"http": 1,
}
}
dataSourcePickerReadOnly={false}
depsStart={
Object {
"dataSource": Object {
"dataSourceEnabled": true,
},
}
}
navigation={Object {}}
selectedDataSource={
Object {
"id": "test",
}
}
setDataSource={[MockFunction]}
/>
<EuiPanel>
<EuiTitle>
<h3>
Audit logging
</h3>
</EuiTitle>
<EuiHorizontalRule
margin="m"
/>
<EuiForm>
<EuiDescribedFormGroup
className="described-form-group"
title={
<h3>
Storage location
</h3>
}
>
<EuiFormRow
className="form-row"
describedByIds={Array []}
display="row"
fullWidth={false}
hasChildLabel={true}
hasEmptyLabelSpace={false}
labelType="label"
>
<EuiText
color="subdued"
grow={false}
>
<FormattedMessage
defaultMessage="Configure the output location and storage types in {opensearchCode}. The default storage location is {internalOpenSearchCode}, which stores the logs in an index on this cluster."
id="audit.logs.storageInstruction"
values={
Object {
"internalOpenSearchCode": <EuiCode>
internal_opensearch
</EuiCode>,
"opensearchCode": <EuiCode>
opensearch.yml
</EuiCode>,
}
}
/>
<ExternalLink
href="https://opensearch.org/docs/latest/security-plugin/audit-logs/storage-types/"
/>
</EuiText>
</EuiFormRow>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup
className="described-form-group"
title={
<h3>
Enable audit logging
</h3>
}
>
<EuiFormRow
describedByIds={Array []}
display="row"
fullWidth={false}
hasChildLabel={true}
hasEmptyLabelSpace={false}
labelType="label"
>
<EuiSwitch
checked={false}
data-test-subj="audit-logging-enabled-switch"
label="Disabled"
name="auditLoggingEnabledSwitch"
onChange={[Function]}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
</EuiForm>
</EuiPanel>
</div>
`;

exports[`Audit logs render compliance settings 1`] = `
<Fragment>
<ViewSettingGroup
Expand Down Expand Up @@ -753,3 +645,21 @@ exports[`Audit logs render when AuditLoggingSettings.enabled is true 1`] = `
</EuiPanel>
</div>
`;

exports[`Audit logs Render unable to access dataSource when enabled and inaccessible 1`] = `
<Memo()
coreStart={
Object {
"http": 1,
}
}
depsStart={
Object {
"dataSource": Object {
"dataSourceEnabled": true,
},
}
}
navigation={Object {}}
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ describe('Audit logs edit', () => {
jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]);
});

afterEach(() => {
React.useContext.mockRestore();
React.useContext.mockReturnValue({
dataSource: { id: 'test' },
setDataSource: jest.fn(),
});
});

it('Render edit general settings', (done) => {
jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f());

Expand Down Expand Up @@ -174,6 +182,10 @@ describe('Audit logs edit', () => {
});

it('Render unable to access dataSource when enabled and inaccessible', () => {
React.useContext.mockImplementation(() => ({
dataSource: undefined,
setDataSource: jest.fn(),
}));
const depsStart = {
dataSource: {
dataSourceEnabled: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ describe('Audit logs', () => {
jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f());
});

afterEach(() => {
React.useContext.mockRestore();
React.useContext.mockReturnValue({
dataSource: { id: 'test' },
setDataSource: jest.fn(),
});
});

it('Render disabled', () => {
const mockAuditLoggingData = {
enabled: false,
Expand Down Expand Up @@ -210,6 +218,10 @@ describe('Audit logs', () => {
});

it('Render unable to access dataSource when enabled and inaccessible', () => {
React.useContext.mockImplementation(() => ({
dataSource: undefined,
setDataSource: jest.fn(),
}));
const depsStart = {
dataSource: {
dataSourceEnabled: true,
Expand Down
2 changes: 2 additions & 0 deletions public/apps/configuration/panels/auth-view/auth-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export function AuthView(props: AppDependencies) {
}, [props.coreStart.http, dataSource]);

if (isEmpty(authentication)) {
console.log(dataSource);
console.log(dataSourceEnabled);
if (dataSourceEnabled && dataSource === undefined) {
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports[`Auth view Render unable to access dataSource when enabled and inaccessi
"http": 1,
}
}
dataSourcePickerReadOnly={false}
depsStart={
Object {
"dataSource": Object {
Expand All @@ -17,14 +16,7 @@ exports[`Auth view Render unable to access dataSource when enabled and inaccessi
}
}
navigation={Object {}}
selectedDataSource={
Object {
"id": "test",
}
}
setDataSource={[MockFunction]}
/>
<InstructionView />
</Fragment>
`;

Expand All @@ -36,7 +28,6 @@ exports[`Auth view Render unable to access dataSource when enabled and inaccessi
"http": 1,
}
}
dataSourcePickerReadOnly={false}
depsStart={
Object {
"dataSource": Object {
Expand All @@ -45,13 +36,6 @@ exports[`Auth view Render unable to access dataSource when enabled and inaccessi
}
}
navigation={Object {}}
selectedDataSource={
Object {
"id": "test",
}
}
setDataSource={[MockFunction]}
/>
<InstructionView />
</Fragment>
`;
17 changes: 17 additions & 0 deletions public/apps/configuration/panels/auth-view/test/auth-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ describe('Auth view', () => {
jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f());
});

afterEach(() => {
React.useContext.mockRestore();
React.useContext.mockReturnValue({
dataSource: { id: 'test' },
setDataSource: jest.fn(),
});
});

it('valid data', (done) => {
const config = {
authc: {
Expand Down Expand Up @@ -101,6 +109,10 @@ describe('Auth view', () => {
});

it('Render unable to access dataSource when enabled and inaccessible', () => {
React.useContext.mockImplementation(() => ({
dataSource: undefined,
setDataSource: jest.fn(),
}));
const depsStart = {
dataSource: {
dataSourceEnabled: true,
Expand All @@ -117,6 +129,11 @@ describe('Auth view', () => {
});

it('Render unable to access dataSource when enabled and inaccessible: Empty Authentication', () => {
React.useContext.mockImplementation(() => ({
dataSource: undefined,
setDataSource: jest.fn(),
}));

mockAuthViewUtils.getSecurityConfig = jest.fn().mockImplementationOnce(() => {
throw Error();
});
Expand Down
Loading

0 comments on commit 6e8284d

Please sign in to comment.