From 0311045f5da79be423428458c2351c50ca8e5504 Mon Sep 17 00:00:00 2001 From: Mohammer5 Date: Mon, 4 Mar 2024 12:46:15 +0800 Subject: [PATCH] chore(data elements new form test): fix tests after some restructuring \w Birk --- .../form/attributes/CustomAttributes.tsx | 1 - .../attributes/useCustomAttributesQuery.ts | 1 - .../fields/DataElementsField.tsx | 2 +- src/pages/dataElements/New.spec.tsx | 26 ++++++++++++------- .../fields/AggregationLevelsField.tsx | 4 +-- .../fields/AggregationTypeField.tsx | 2 +- .../fields/CategoryComboField.test.tsx | 4 +-- .../fields/CategoryComboField.tsx | 4 +-- .../dataElements/fields/ColorAndIconField.tsx | 2 +- src/pages/dataElements/fields/DomainField.tsx | 2 +- .../dataElements/fields/FieldMaskField.tsx | 2 +- .../dataElements/fields/FormNameField.tsx | 2 +- .../dataElements/fields/LegendSetField.tsx | 2 +- .../fields/OptionSetCommentField.tsx | 4 +-- .../dataElements/fields/OptionSetField.tsx | 4 +-- src/pages/dataElements/fields/UrlField.tsx | 2 +- .../dataElements/fields/ValueTypeField.tsx | 2 +- .../fields/ZeroIsSignificantField.tsx | 2 +- 18 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/components/form/attributes/CustomAttributes.tsx b/src/components/form/attributes/CustomAttributes.tsx index e6d44b4b..c02ba003 100644 --- a/src/components/form/attributes/CustomAttributes.tsx +++ b/src/components/form/attributes/CustomAttributes.tsx @@ -86,7 +86,6 @@ export function CustomAttributes() { const customAttributes = formState.initialValues.attributeValues?.map( (av) => av.attribute ) - console.log('> customAttributes:', customAttributes) return ( <> diff --git a/src/components/form/attributes/useCustomAttributesQuery.ts b/src/components/form/attributes/useCustomAttributesQuery.ts index 0c01b58b..97d2209e 100644 --- a/src/components/form/attributes/useCustomAttributesQuery.ts +++ b/src/components/form/attributes/useCustomAttributesQuery.ts @@ -28,7 +28,6 @@ interface QueryResponse { export function useCustomAttributesQuery() { const schemaSection = useSchemaSectionHandleOrThrow() - const customAttributes = useDataQuery( CUSTOM_ATTRIBUTES_QUERY, { variables: { modelName: schemaSection.name } } diff --git a/src/pages/dataElementGroups/fields/DataElementsField.tsx b/src/pages/dataElementGroups/fields/DataElementsField.tsx index c030ac95..6ad0fe10 100644 --- a/src/pages/dataElementGroups/fields/DataElementsField.tsx +++ b/src/pages/dataElementGroups/fields/DataElementsField.tsx @@ -51,7 +51,7 @@ export function DataElementsField() { return ( ({ + useSchemaSectionHandleOrThrow: jest.fn(() => ({ + name: 'dataElement', + namePlural: 'dataElements', + parentSectionKey: 'dataElement', + title: 'Data element', + titlePlural: 'Data elements', + })), +})) + // @TODO: For some reason string interpolation somewhere within the Transfer // component does not get transpiled correctly for the cjs build when // building the UI library. We'll have to address that at some point. @@ -66,10 +76,10 @@ describe('Data Elements / New', () => { it('should return to the list view when cancelling', async () => { const router = createMemoryRouter( [ - { path: '/new', element: }, + { path: '/dataElements/new', element: }, { path: '/dataElements', element:
List view
}, ], - { initialEntries: ['/new'] } + { initialEntries: ['/dataElements/new'] } ) const result = render( @@ -111,19 +121,17 @@ describe('Data Elements / New', () => { ).toHaveLength(3) const nameRequiredError = await result.findByText('Required', { - selector: '[data-test="dataelementsformfields-name-validation"]', + selector: '[data-test="formfields-name-validation"]', }) expect(nameRequiredError).toBeTruthy() const shortNameRequiredError = await result.findByText('Required', { - selector: - '[data-test="dataelementsformfields-shortname-validation"]', + selector: '[data-test="formfields-shortname-validation"]', }) expect(shortNameRequiredError).toBeTruthy() const categoryComboRequiredError = await result.findByText('Required', { - selector: - '[data-test="dataelementsformfields-categorycombo-validation"]', + selector: '[data-test="formfields-categorycombo-validation"]', }) expect(categoryComboRequiredError).toBeTruthy() }) @@ -135,12 +143,12 @@ describe('Data Elements / New', () => { }) const router = createMemoryRouter( [ - { path: '/new', element: }, + { path: '/dataElements/new', element: }, { path: '/dataElements', element:
List view
}, ], { initialIndex: 0, - initialEntries: ['/new'], + initialEntries: ['/dataElements/new'], } ) const result = render( diff --git a/src/pages/dataElements/fields/AggregationLevelsField.tsx b/src/pages/dataElements/fields/AggregationLevelsField.tsx index c3c8610f..4f372083 100644 --- a/src/pages/dataElements/fields/AggregationLevelsField.tsx +++ b/src/pages/dataElements/fields/AggregationLevelsField.tsx @@ -30,7 +30,7 @@ export function AggregationLevelsField() { return ( aggregationLevelHandle.current.refetch()} onAddNew={() => window.open(newAggregationLevelLink, '_blank')} > @@ -43,7 +43,7 @@ export function AggregationLevelsField() { )} validationText={meta.touched ? meta.error : undefined} error={meta.touched && !!meta.error} - dataTest="dataelementsformfields-aggregationlevels" + dataTest="formfields-aggregationlevels" > ', () => { fireEvent.click(submitButton) expect( - result.getByTestId( - 'dataelementsformfields-categorycombo-validation' - ) + result.getByTestId('formfields-categorycombo-validation') ).toBeTruthy() expect(onSubmit).toHaveBeenCalledTimes(0) }) diff --git a/src/pages/dataElements/fields/CategoryComboField.tsx b/src/pages/dataElements/fields/CategoryComboField.tsx index 50e9f434..aa785bb8 100644 --- a/src/pages/dataElements/fields/CategoryComboField.tsx +++ b/src/pages/dataElements/fields/CategoryComboField.tsx @@ -50,7 +50,7 @@ export function CategoryComboField() { return ( categoryComboHandle.current.refetch()} onAddNew={() => window.open(newCategoryComboLink, '_blank')} > @@ -66,7 +66,7 @@ export function CategoryComboField() { )} error={meta.touched && !!meta.error} validationText={meta.touched ? meta.error : undefined} - dataTest="dataelementsformfields-categorycombo" + dataTest="formfields-categorycombo" > optionSetHandle.current.refetch()} onAddNew={() => window.open(newOptionSetLink, '_blank')} > @@ -41,7 +41,7 @@ export function OptionSetCommentField() { )} validationText={meta.touched ? meta.error : undefined} error={meta.touched && !!meta.error} - dataTest="dataelementsformfields-commentoptionset" + dataTest="formfields-commentoptionset" > optionSetHandle.current.refetch()} onAddNew={() => window.open(newOptionSetLink, '_blank')} > @@ -36,7 +36,7 @@ export function OptionSetField() { )} validationText={meta.touched ? meta.error : undefined} error={meta.touched && !!meta.error} - dataTest="dataelementsformfields-optionset" + dataTest="formfields-optionset" >