Skip to content

Commit

Permalink
Fixes audit-logging test
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed May 22, 2024
1 parent 6e081db commit 8468545
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ describe('Audit logs', () => {
};

beforeEach(() => {
jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]);
// jest.spyOn(React, 'useState').mockImplementation((initialValue) => [initialValue, setState]);
jest.spyOn(React, 'useState').mockRestore();
jest
.spyOn(React, 'useState')
.mockImplementationOnce(() => [[], setState])
.mockImplementationOnce(() => [false, jest.fn()]);
jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f());
});

Expand Down Expand Up @@ -140,7 +145,11 @@ describe('Audit logs', () => {

it('render when AuditLoggingSettings.enabled is true', () => {
const auditLoggingSettings = { enabled: true };
jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]);
jest.spyOn(React, 'useState').mockRestore();
jest
.spyOn(React, 'useState')
.mockImplementationOnce(() => [auditLoggingSettings, setState])
.mockImplementationOnce(() => [false, jest.fn()]);
const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
);
Expand All @@ -149,7 +158,11 @@ describe('Audit logs', () => {

it('Click Configure button of general setting section', () => {
const auditLoggingSettings = { enabled: true };
jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]);
jest.spyOn(React, 'useState').mockRestore();
jest
.spyOn(React, 'useState')
.mockImplementationOnce(() => [auditLoggingSettings, setState])
.mockImplementationOnce(() => [false, jest.fn()]);
const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
);
Expand All @@ -161,7 +174,11 @@ describe('Audit logs', () => {

it('Click Configure button of Compliance settings section', () => {
const auditLoggingSettings = { enabled: true };
jest.spyOn(React, 'useState').mockImplementation(() => [auditLoggingSettings, setState]);
jest.spyOn(React, 'useState').mockRestore();
jest
.spyOn(React, 'useState')
.mockImplementationOnce(() => [auditLoggingSettings, setState])
.mockImplementationOnce(() => [false, jest.fn()]);
const component = shallow(
<AuditLogging coreStart={mockCoreStart as any} navigation={{} as any} />
);
Expand Down

0 comments on commit 8468545

Please sign in to comment.