From 62f28a9e2292158ddc63d0b5baf201cfcc98f98c Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Sat, 11 May 2024 13:34:34 -0400 Subject: [PATCH] Fixes unit tests Signed-off-by: Darshit Chanpura --- .../__snapshots__/audit-logging.test.tsx.snap | 1 + .../audit-logging/test/audit-logging.test.tsx | 54 ++++++++++++++++--- .../panels/auth-view/test/auth-view.test.tsx | 18 ++++++- .../panels/test/role-list.test.tsx | 10 ++++ 4 files changed, 73 insertions(+), 10 deletions(-) diff --git a/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging.test.tsx.snap b/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging.test.tsx.snap index 9fdee791a..f5c891359 100644 --- a/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging.test.tsx.snap +++ b/public/apps/configuration/panels/audit-logging/test/__snapshots__/audit-logging.test.tsx.snap @@ -248,6 +248,7 @@ exports[`Audit logs render when AuditLoggingSettings.enabled is true 1`] = ` } } dataSourcePickerReadOnly={false} + depsStart={Object {}} navigation={Object {}} selectedDataSource={ Object { diff --git a/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx b/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx index 3f5c6e8da..bbbe43064 100644 --- a/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx +++ b/public/apps/configuration/panels/audit-logging/test/audit-logging.test.tsx @@ -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()); @@ -54,7 +56,11 @@ describe('Audit logs', () => { mockAuditLoggingUtils.getAuditLogging = jest.fn().mockReturnValue(mockAuditLoggingData); const component = shallow( - + ); const switchFound = component.find(EuiSwitch); @@ -72,7 +78,13 @@ describe('Audit logs', () => { mockAuditLoggingUtils.getAuditLogging = jest.fn().mockReturnValue(mockAuditLoggingData); - shallow(); + shallow( + + ); process.nextTick(() => { expect(mockAuditLoggingUtils.getAuditLogging).toHaveBeenCalledTimes(1); @@ -90,7 +102,13 @@ describe('Audit logs', () => { throw Error(); }); - shallow(); + shallow( + + ); process.nextTick(() => { expect(mockAuditLoggingUtils.getAuditLogging).toHaveBeenCalledTimes(1); @@ -116,7 +134,11 @@ describe('Audit logs', () => { it('audit logging switch change', () => { const component = shallow( - + ); component.find('[data-test-subj="audit-logging-enabled-switch"]').simulate('change'); expect(mockAuditLoggingUtils.updateAuditLogging).toHaveBeenCalledTimes(1); @@ -130,7 +152,11 @@ describe('Audit logs', () => { throw Error(); }); const component = shallow( - + ); component.find('[data-test-subj="audit-logging-enabled-switch"]').simulate('change'); @@ -142,7 +168,11 @@ describe('Audit logs', () => { const auditLoggingSettings = { enabled: true }; jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); const component = shallow( - + ); expect(component).toMatchSnapshot(); }); @@ -151,7 +181,11 @@ describe('Audit logs', () => { const auditLoggingSettings = { enabled: true }; jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); const component = shallow( - + ); component.find('[data-test-subj="general-settings-configure"]').simulate('click'); expect(window.location.hash).toBe( @@ -163,7 +197,11 @@ describe('Audit logs', () => { const auditLoggingSettings = { enabled: true }; jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]); const component = shallow( - + ); component.find('[data-test-subj="compliance-settings-configure"]').simulate('click'); expect(window.location.hash).toBe( diff --git a/public/apps/configuration/panels/auth-view/test/auth-view.test.tsx b/public/apps/configuration/panels/auth-view/test/auth-view.test.tsx index 8a97113ec..192913cad 100644 --- a/public/apps/configuration/panels/auth-view/test/auth-view.test.tsx +++ b/public/apps/configuration/panels/auth-view/test/auth-view.test.tsx @@ -30,6 +30,8 @@ describe('Auth view', () => { http: 1, }; + const mockDepsStart = {}; + const setState = jest.fn(); beforeEach(() => { @@ -56,7 +58,13 @@ describe('Auth view', () => { mockAuthViewUtils.getSecurityConfig = jest.fn().mockReturnValue(config); - shallow(); + shallow( + + ); process.nextTick(() => { expect(mockAuthViewUtils.getSecurityConfig).toHaveBeenCalledTimes(1); @@ -75,7 +83,13 @@ describe('Auth view', () => { jest.spyOn(console, 'log').mockImplementationOnce(() => {}); - shallow(); + shallow( + + ); process.nextTick(() => { expect(mockAuthViewUtils.getSecurityConfig).toHaveBeenCalledTimes(1); diff --git a/public/apps/configuration/panels/test/role-list.test.tsx b/public/apps/configuration/panels/test/role-list.test.tsx index becbfe806..a87f295bd 100644 --- a/public/apps/configuration/panels/test/role-list.test.tsx +++ b/public/apps/configuration/panels/test/role-list.test.tsx @@ -50,6 +50,8 @@ describe('Role list', () => { http: 1, }; + const mockDepsStart = {}; + beforeEach(() => { jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]); }); @@ -72,6 +74,7 @@ describe('Role list', () => { const component = shallow( { shallow( { shallow( { shallow( { shallow( { component = shallow( { const wrapper = shallow( { const wrapper = shallow(