Skip to content

Commit

Permalink
Fixes unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed May 11, 2024
1 parent 891e1bf commit 62f28a9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ exports[`Audit logs render when AuditLoggingSettings.enabled is true 1`] = `
}
}
dataSourcePickerReadOnly={false}
depsStart={Object {}}
navigation={Object {}}
selectedDataSource={
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe('Audit logs', () => {
http: 1,
};

const mockDepsStart = {};

beforeEach(() => {
jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]);
jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f());
Expand All @@ -54,7 +56,11 @@ describe('Audit logs', () => {
mockAuditLoggingUtils.getAuditLogging = jest.fn().mockReturnValue(mockAuditLoggingData);

const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
<AuditLogging
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);

const switchFound = component.find(EuiSwitch);
Expand All @@ -72,7 +78,13 @@ describe('Audit logs', () => {

mockAuditLoggingUtils.getAuditLogging = jest.fn().mockReturnValue(mockAuditLoggingData);

shallow(<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />);
shallow(
<AuditLogging
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);

process.nextTick(() => {
expect(mockAuditLoggingUtils.getAuditLogging).toHaveBeenCalledTimes(1);
Expand All @@ -90,7 +102,13 @@ describe('Audit logs', () => {
throw Error();
});

shallow(<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />);
shallow(
<AuditLogging
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);

process.nextTick(() => {
expect(mockAuditLoggingUtils.getAuditLogging).toHaveBeenCalledTimes(1);
Expand All @@ -116,7 +134,11 @@ describe('Audit logs', () => {

it('audit logging switch change', () => {
const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
<AuditLogging
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);
component.find('[data-test-subj="audit-logging-enabled-switch"]').simulate('change');
expect(mockAuditLoggingUtils.updateAuditLogging).toHaveBeenCalledTimes(1);
Expand All @@ -130,7 +152,11 @@ describe('Audit logs', () => {
throw Error();
});
const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
<AuditLogging
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);
component.find('[data-test-subj="audit-logging-enabled-switch"]').simulate('change');

Expand All @@ -142,7 +168,11 @@ describe('Audit logs', () => {
const auditLoggingSettings = { enabled: true };
jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]);
const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
<AuditLogging
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);
expect(component).toMatchSnapshot();
});
Expand All @@ -151,7 +181,11 @@ describe('Audit logs', () => {
const auditLoggingSettings = { enabled: true };
jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]);
const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
<AuditLogging
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);
component.find('[data-test-subj="general-settings-configure"]').simulate('click');
expect(window.location.hash).toBe(
Expand All @@ -163,7 +197,11 @@ describe('Audit logs', () => {
const auditLoggingSettings = { enabled: true };
jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]);
const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
<AuditLogging
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);
component.find('[data-test-subj="compliance-settings-configure"]').simulate('click');
expect(window.location.hash).toBe(
Expand Down
18 changes: 16 additions & 2 deletions public/apps/configuration/panels/auth-view/test/auth-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ describe('Auth view', () => {
http: 1,
};

const mockDepsStart = {};

const setState = jest.fn();

beforeEach(() => {
Expand All @@ -56,7 +58,13 @@ describe('Auth view', () => {

mockAuthViewUtils.getSecurityConfig = jest.fn().mockReturnValue(config);

shallow(<AuthView coreStart={mockCoreStart as any} navigation={{} as any} />);
shallow(
<AuthView
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);

process.nextTick(() => {
expect(mockAuthViewUtils.getSecurityConfig).toHaveBeenCalledTimes(1);
Expand All @@ -75,7 +83,13 @@ describe('Auth view', () => {

jest.spyOn(console, 'log').mockImplementationOnce(() => {});

shallow(<AuthView coreStart={mockCoreStart as any} navigation={{} as any} />);
shallow(
<AuthView
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
/>
);

process.nextTick(() => {
expect(mockAuthViewUtils.getSecurityConfig).toHaveBeenCalledTimes(1);
Expand Down
10 changes: 10 additions & 0 deletions public/apps/configuration/panels/test/role-list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('Role list', () => {
http: 1,
};

const mockDepsStart = {};

beforeEach(() => {
jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]);
});
Expand All @@ -72,6 +74,7 @@ describe('Role list', () => {
const component = shallow(
<RoleList
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
params={{} as any}
config={{} as any}
Expand All @@ -92,6 +95,7 @@ describe('Role list', () => {
shallow(
<RoleList
coreStart={{} as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
params={{} as any}
config={{} as any}
Expand Down Expand Up @@ -125,6 +129,7 @@ describe('Role list', () => {
shallow(
<RoleList
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
params={{} as any}
config={{} as any}
Expand All @@ -144,6 +149,7 @@ describe('Role list', () => {
shallow(
<RoleList
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
params={{} as any}
config={{} as any}
Expand All @@ -167,6 +173,7 @@ describe('Role list', () => {
shallow(
<RoleList
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
params={{} as any}
config={{} as any}
Expand Down Expand Up @@ -194,6 +201,7 @@ describe('Role list', () => {
component = shallow(
<RoleList
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
params={{} as any}
config={{} as any}
Expand Down Expand Up @@ -221,6 +229,7 @@ describe('Role list', () => {
const wrapper = shallow(
<RoleList
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
params={{} as any}
config={{} as any}
Expand All @@ -240,6 +249,7 @@ describe('Role list', () => {
const wrapper = shallow(
<RoleList
coreStart={mockCoreStart as any}
depsStart={mockDepsStart as any}
navigation={{} as any}
params={{} as any}
config={{} as any}
Expand Down

0 comments on commit 62f28a9

Please sign in to comment.