Skip to content

Commit

Permalink
chore(data elements new form test): fix tests after some restructurin…
Browse files Browse the repository at this point in the history
…g \w Birk
  • Loading branch information
Mohammer5 committed Mar 5, 2024
1 parent 562dfb7 commit 0311045
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/components/form/attributes/CustomAttributes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export function CustomAttributes() {
const customAttributes = formState.initialValues.attributeValues?.map(
(av) => av.attribute
)
console.log('> <CustomAttribute /> customAttributes:', customAttributes)

return (
<>
Expand Down
1 change: 0 additions & 1 deletion src/components/form/attributes/useCustomAttributesQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface QueryResponse {

export function useCustomAttributesQuery() {
const schemaSection = useSchemaSectionHandleOrThrow()

const customAttributes = useDataQuery<QueryResponse>(
CUSTOM_ATTRIBUTES_QUERY,
{ variables: { modelName: schemaSection.name } }
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElementGroups/fields/DataElementsField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function DataElementsField() {

return (
<Field
dataTest="dataelementsformfields-dataElementsets"
dataTest="formfields-dataElementsets"
error={!!meta.error}
validationText={meta.error?.toString()}
name={name}
Expand Down
26 changes: 17 additions & 9 deletions src/pages/dataElements/New.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import attributes from './__mocks__/attributes.json'
import categoryCombosPage1 from './__mocks__/categoryCombosPage1.json'
import { Component as New } from './New'

jest.mock('../../lib/routeUtils/useSectionHandle', () => ({
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.
Expand Down Expand Up @@ -66,10 +76,10 @@ describe('Data Elements / New', () => {
it('should return to the list view when cancelling', async () => {
const router = createMemoryRouter(
[
{ path: '/new', element: <New /> },
{ path: '/dataElements/new', element: <New /> },
{ path: '/dataElements', element: <div>List view</div> },
],
{ initialEntries: ['/new'] }
{ initialEntries: ['/dataElements/new'] }
)

const result = render(
Expand Down Expand Up @@ -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()
})
Expand All @@ -135,12 +143,12 @@ describe('Data Elements / New', () => {
})
const router = createMemoryRouter(
[
{ path: '/new', element: <New /> },
{ path: '/dataElements/new', element: <New /> },
{ path: '/dataElements', element: <div>List view</div> },
],
{
initialIndex: 0,
initialEntries: ['/new'],
initialEntries: ['/dataElements/new'],
}
)
const result = render(
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dataElements/fields/AggregationLevelsField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function AggregationLevelsField() {

return (
<EditableFieldWrapper
dataTest="dataelementsformfields-aggregationlevels"
dataTest="formfields-aggregationlevels"
onRefresh={() => aggregationLevelHandle.current.refetch()}
onAddNew={() => window.open(newAggregationLevelLink, '_blank')}
>
Expand All @@ -43,7 +43,7 @@ export function AggregationLevelsField() {
)}
validationText={meta.touched ? meta.error : undefined}
error={meta.touched && !!meta.error}
dataTest="dataelementsformfields-aggregationlevels"
dataTest="formfields-aggregationlevels"
>
<AggregationLevelMultiSelect
ref={aggregationLevelHandle}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/AggregationTypeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function AggregationTypeField() {
key={disabled ? 0 : 1}
disabled={disabled}
component={SingleSelectFieldFF}
dataTest="dataelementsformfields-aggregationtype"
dataTest="formfields-aggregationtype"
required={!disabled}
inputWidth="400px"
name="aggregationType"
Expand Down
4 changes: 1 addition & 3 deletions src/pages/dataElements/fields/CategoryComboField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ describe('<CategoryComboField />', () => {
fireEvent.click(submitButton)

expect(
result.getByTestId(
'dataelementsformfields-categorycombo-validation'
)
result.getByTestId('formfields-categorycombo-validation')
).toBeTruthy()
expect(onSubmit).toHaveBeenCalledTimes(0)
})
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dataElements/fields/CategoryComboField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function CategoryComboField() {

return (
<EditableFieldWrapper
dataTest="dataelementsformfields-categorycombo"
dataTest="formfields-categorycombo"
onRefresh={() => categoryComboHandle.current.refetch()}
onAddNew={() => window.open(newCategoryComboLink, '_blank')}
>
Expand All @@ -66,7 +66,7 @@ export function CategoryComboField() {
)}
error={meta.touched && !!meta.error}
validationText={meta.touched ? meta.error : undefined}
dataTest="dataelementsformfields-categorycombo"
dataTest="formfields-categorycombo"
>
<CategoryComboSelect
required
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/ColorAndIconField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function ColorAndIconField() {

return (
<Field
dataTest="dataelementsformfields-colorandicon"
dataTest="formfields-colorandicon"
label={i18n.t('Color and icon')}
helpText={i18n.t(
'A color and icon are helpful for identifying data elements in information-dense screens.'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/DomainField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function DomainField() {
return (
<Field
required
dataTest="dataelementsformfields-domaintype"
dataTest="formfields-domaintype"
name={name}
label={i18n.t('{{fieldLabel}} (required)', {
fieldLabel: i18n.t('Domain'),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/FieldMaskField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function FieldMaskField() {
<FieldRFF
component={InputFieldFF}
inputWidth="400px"
dataTest="dataelementsformfields-fieldmask"
dataTest="formfields-fieldmask"
name="fieldMask"
label={i18n.t('Field mask')}
helpText={i18n.t(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/FormNameField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function FormNameField() {
return (
<FieldRFF
component={InputFieldFF}
dataTest="dataelementsformfields-formname"
dataTest="formfields-formname"
inputWidth="400px"
name="formName"
label={i18n.t('Form name')}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/LegendSetField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function LegendSetField() {

return (
<Field
dataTest="dataelementsformfields-legendsets"
dataTest="formfields-legendsets"
error={!!meta.error}
validationText={meta.error?.toString()}
name={name}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dataElements/fields/OptionSetCommentField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function OptionSetCommentField() {

return (
<EditableFieldWrapper
dataTest="dataelementsformfields-commentoptionset"
dataTest="formfields-commentoptionset"
onRefresh={() => optionSetHandle.current.refetch()}
onAddNew={() => window.open(newOptionSetLink, '_blank')}
>
Expand All @@ -41,7 +41,7 @@ export function OptionSetCommentField() {
)}
validationText={meta.touched ? meta.error : undefined}
error={meta.touched && !!meta.error}
dataTest="dataelementsformfields-commentoptionset"
dataTest="formfields-commentoptionset"
>
<OptionSetSelect
showAllOption
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dataElements/fields/OptionSetField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function OptionSetField() {

return (
<EditableFieldWrapper
dataTest="dataelementsformfields-optionset"
dataTest="formfields-optionset"
onRefresh={() => optionSetHandle.current.refetch()}
onAddNew={() => window.open(newOptionSetLink, '_blank')}
>
Expand All @@ -36,7 +36,7 @@ export function OptionSetField() {
)}
validationText={meta.touched ? meta.error : undefined}
error={meta.touched && !!meta.error}
dataTest="dataelementsformfields-optionset"
dataTest="formfields-optionset"
>
<OptionSetSelect
showAllOption
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/UrlField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function UrlField() {
return (
<FieldRFF
component={InputFieldFF}
dataTest="dataelementsformfields-url"
dataTest="formfields-url"
inputWidth="400px"
name="url"
label={i18n.t('Url')}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/ValueTypeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function ValueTypeField() {
required
disabled={disabled}
component={SingleSelectFieldFF}
dataTest="dataelementsformfields-valuetype"
dataTest="formfields-valuetype"
inputWidth="400px"
name="valueType"
label={i18n.t('{{fieldLabel}} (required)', {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dataElements/fields/ZeroIsSignificantField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function ZeroIsSignificantField() {
return (
<FieldRFF
component={CheckboxFieldFF}
dataTest="dataelementsformfields-zeroissignificant"
dataTest="formfields-zeroissignificant"
name="zeroIsSignificant"
label={i18n.t('Store zero data values')}
type="checkbox"
Expand Down

0 comments on commit 0311045

Please sign in to comment.