From 4ed77a9c5113bcd907f0e6171d7b661eeea4a0cd Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Thu, 5 Oct 2023 22:17:37 +0200 Subject: [PATCH] Fix tests --- .../__stories__/MatchColumns.stories.tsx | 2 +- .../__stories__/SelectHeader.stories.tsx | 2 +- .../__stories__/SelectSheet.stories.tsx | 2 +- .../components/__stories__/Upload.stories.tsx | 2 +- .../__stories__/Validation.stories.tsx | 2 +- .../spreadsheet-import/tests/mockRsiValues.ts | 171 ++++++++++++++++++ 6 files changed, 176 insertions(+), 5 deletions(-) create mode 100644 front/src/modules/spreadsheet-import/tests/mockRsiValues.ts diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/MatchColumns.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/MatchColumns.stories.tsx index 7b484dd17..a0ee07056 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/MatchColumns.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/MatchColumns.stories.tsx @@ -3,7 +3,7 @@ import { Meta } from '@storybook/react'; import { ModalWrapper } from '@/spreadsheet-import/components/ModalWrapper'; import { Providers } from '@/spreadsheet-import/components/Providers'; import { MatchColumnsStep } from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep'; -import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues.test'; +import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues'; const meta: Meta = { title: 'Modules/SpreadsheetImport/MatchColumnsStep', diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectHeader.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectHeader.stories.tsx index a3c859467..8a28599df 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectHeader.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectHeader.stories.tsx @@ -6,7 +6,7 @@ import { SelectHeaderStep } from '@/spreadsheet-import/steps/components/SelectHe import { headerSelectionTableFields, mockRsiValues, -} from '@/spreadsheet-import/tests/mockRsiValues.test'; +} from '@/spreadsheet-import/tests/mockRsiValues'; const meta: Meta = { title: 'Modules/SpreadsheetImport/SelectHeaderStep', diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectSheet.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectSheet.stories.tsx index 6bfc34910..4ec059c66 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectSheet.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectSheet.stories.tsx @@ -3,7 +3,7 @@ import { Meta } from '@storybook/react'; import { ModalWrapper } from '@/spreadsheet-import/components/ModalWrapper'; import { Providers } from '@/spreadsheet-import/components/Providers'; import { SelectSheetStep } from '@/spreadsheet-import/steps/components/SelectSheetStep/SelectSheetStep'; -import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues.test'; +import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues'; const meta: Meta = { title: 'Modules/SpreadsheetImport/SelectSheetStep', diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/Upload.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/Upload.stories.tsx index 11d3ee1f9..8ff0b5808 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/Upload.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/Upload.stories.tsx @@ -3,7 +3,7 @@ import { Meta } from '@storybook/react'; import { ModalWrapper } from '@/spreadsheet-import/components/ModalWrapper'; import { Providers } from '@/spreadsheet-import/components/Providers'; import { UploadStep } from '@/spreadsheet-import/steps/components/UploadStep/UploadStep'; -import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues.test'; +import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues'; const meta: Meta = { title: 'Modules/SpreadsheetImport/UploadStep', diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/Validation.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/Validation.stories.tsx index 6aacc76c5..32fc9547b 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/Validation.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/Validation.stories.tsx @@ -6,7 +6,7 @@ import { ValidationStep } from '@/spreadsheet-import/steps/components/Validation import { editableTableInitialData, mockRsiValues, -} from '@/spreadsheet-import/tests/mockRsiValues.test'; +} from '@/spreadsheet-import/tests/mockRsiValues'; const meta: Meta = { title: 'Modules/SpreadsheetImport/ValidationStep', diff --git a/front/src/modules/spreadsheet-import/tests/mockRsiValues.ts b/front/src/modules/spreadsheet-import/tests/mockRsiValues.ts new file mode 100644 index 000000000..3621a7941 --- /dev/null +++ b/front/src/modules/spreadsheet-import/tests/mockRsiValues.ts @@ -0,0 +1,171 @@ +import { defaultSpreadsheetImportProps } from '@/spreadsheet-import/provider/components/SpreadsheetImport'; +import { Fields, SpreadsheetOptions } from '@/spreadsheet-import/types'; + +const fields = [ + { + icon: null, + label: 'Name', + key: 'name', + alternateMatches: ['first name', 'first'], + fieldType: { + type: 'input', + }, + example: 'Stephanie', + validations: [ + { + rule: 'required', + errorMessage: 'Name is required', + }, + ], + }, + { + icon: null, + label: 'Surname', + key: 'surname', + alternateMatches: ['second name', 'last name', 'last'], + fieldType: { + type: 'input', + }, + example: 'McDonald', + validations: [ + { + rule: 'unique', + errorMessage: 'Last name must be unique', + level: 'info', + }, + ], + description: 'Family / Last name', + }, + { + icon: null, + label: 'Age', + key: 'age', + alternateMatches: ['years'], + fieldType: { + type: 'input', + }, + example: '23', + validations: [ + { + rule: 'regex', + value: '^\\d+$', + errorMessage: 'Age must be a number', + level: 'warning', + }, + ], + }, + { + icon: null, + label: 'Team', + key: 'team', + alternateMatches: ['department'], + fieldType: { + type: 'select', + options: [ + { label: 'Team One', value: 'one' }, + { label: 'Team Two', value: 'two' }, + ], + }, + example: 'Team one', + validations: [ + { + rule: 'required', + errorMessage: 'Team is required', + }, + ], + }, + { + icon: null, + label: 'Is manager', + key: 'is_manager', + alternateMatches: ['manages'], + fieldType: { + type: 'checkbox', + booleanMatches: {}, + }, + example: 'true', + }, +] as Fields; + +const mockComponentBehaviourForTypes = ( + props: SpreadsheetOptions, +) => props; + +export const mockRsiValues = mockComponentBehaviourForTypes({ + ...defaultSpreadsheetImportProps, + fields: fields, + onSubmit: async () => { + return; + }, + isOpen: true, + onClose: () => { + return; + }, + uploadStepHook: async (data) => { + await new Promise((resolve) => { + setTimeout(() => resolve(data), 4000); + }); + return data; + }, + selectHeaderStepHook: async (hData, data) => { + await new Promise((resolve) => { + setTimeout( + () => + resolve({ + headerValues: hData, + data, + }), + 4000, + ); + }); + return { + headerValues: hData, + data, + }; + }, + // Runs after column matching and on entry change, more performant + matchColumnsStepHook: async (data) => { + await new Promise((resolve) => { + setTimeout(() => resolve(data), 4000); + }); + return data; + }, +}); + +export const editableTableInitialData = [ + { + name: 'Hello', + surname: 'Hello', + age: '123123', + team: 'one', + is_manager: true, + }, + { + name: 'Hello', + surname: 'Hello', + age: '12312zsas3', + team: 'two', + is_manager: true, + }, + { + name: 'Whooaasdasdawdawdawdiouasdiuasdisdhasd', + surname: 'Hello', + age: '123123', + team: undefined, + is_manager: false, + }, + { + name: 'Goodbye', + surname: 'Goodbye', + age: '111', + team: 'two', + is_manager: true, + }, +]; + +export const headerSelectionTableFields = [ + ['text', 'num', 'select', 'bool'], + ['Hello', '123', 'one', 'true'], + ['Hello', '123', 'one', 'true'], + ['Hello', '123', 'one', 'true'], +];