Skip to content

Commit

Permalink
unit tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SKarolFolio committed Dec 10, 2024
1 parent 562a99e commit 2771cf7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import '@src/test/__mocks__/common/hooks/useServicesContext.mock';
import { useProcessedRecordAndSchema } from '@common/hooks/useProcessedRecordAndSchema.hook';
import { act, renderHook } from '@testing-library/react';
import { useSetRecoilState } from 'recoil';

jest.mock('recoil');
import { setInitialGlobalState } from '@src/test/__mocks__/store';
import { useInputsStore, useStatusStore } from '@src/store';

describe('useProcessedRecordAndSchema', () => {
const mockSetState = jest.fn();
const mockSetRecord = jest.fn();
const props = {
baseSchema: {} as Schema,
userValues: {},
record: { key: 'value' },
};

beforeEach(() => {
(useSetRecoilState as jest.Mock).mockReturnValueOnce(mockSetState).mockReturnValueOnce(jest.fn());
setInitialGlobalState([
{
store: useStatusStore,
state: { addStatusMessage: jest.fn() },
},
{
store: useInputsStore,
state: { setRecord: mockSetRecord },
},
]);
});

test("doesn't update state when asked not to", () => {
Expand All @@ -24,7 +32,7 @@ describe('useProcessedRecordAndSchema', () => {
result.current.getProcessedRecordAndSchema({ ...props, noStateUpdate: true });
});

expect(mockSetState).not.toHaveBeenCalled();
expect(mockSetRecord).not.toHaveBeenCalled();
});

test('updates state when not asked to not update state', () => {
Expand All @@ -34,6 +42,6 @@ describe('useProcessedRecordAndSchema', () => {
result.current.getProcessedRecordAndSchema(props);
});

expect(mockSetState).toHaveBeenCalled();
expect(mockSetRecord).toHaveBeenCalled();
});
});
3 changes: 0 additions & 3 deletions src/test/__tests__/components/InstancesList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import '@src/test/__mocks__/common/hooks/useRecordControls.mock';
import '@src/test/__mocks__/common/hooks/useNavigateToEditPage.mock';
import { navigateToEditPage } from '@src/test/__mocks__/common/hooks/useNavigateToEditPage.mock';
import { getRecordAndInitializeParsing } from '@src/test/__mocks__/common/hooks/useRecordControls.mock';
import * as RecordFormatter from '@common/helpers/recordFormatting.helper';
import { InstancesList } from '@components/InstancesList';
import { fireEvent, render } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';

jest.mock('recoil');
jest.mock('@common/constants/build.constants', () => ({ IS_EMBEDDED_MODE: true }));

describe('InstancesList', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/test/__tests__/components/TitledPreview.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import '@src/test/__mocks__/common/hooks/useNavigateToEditPage.mock';
import { navigateToEditPage } from '@src/test/__mocks__/common/hooks/useNavigateToEditPage.mock';
import { fireEvent, render } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import { ITitledPreview, TitledPreview } from '@components/Preview/TitledPreview';

jest.mock('recoil');
jest.mock('@common/constants/build.constants', () => ({ IS_EMBEDDED_MODE: true }));

describe('TitledPreview', () => {
Expand Down

0 comments on commit 2771cf7

Please sign in to comment.