-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(de aggregation type field): cover with tests
- Loading branch information
Showing
4 changed files
with
98 additions
and
67 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/pages/dataElements/fields/AggregationTypeField.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { render } from '@testing-library/react' | ||
import React from 'react' | ||
import { Form } from 'react-final-form' | ||
import { AGGREGATION_TYPE, useSchemas } from '../../../lib' | ||
import { AggregationTypeField } from './AggregationTypeField' | ||
|
||
const aggregationTypes = Object.keys(AGGREGATION_TYPE) | ||
|
||
jest.mock('../../../lib/schemas/schemaStore', () => { | ||
return { | ||
...jest.requireActual('../../../lib/schemas/schemaStore'), | ||
useSchemas: jest.fn(), | ||
} | ||
}) | ||
|
||
describe('<AggregationTypeField />', () => { | ||
const uS = useSchemas as jest.Mock | ||
uS.mockImplementation(() => ({ | ||
dataElement: { | ||
properties: { | ||
aggregationType: { constants: aggregationTypes }, | ||
}, | ||
}, | ||
})) | ||
|
||
const disabledValueTypes = [ | ||
'TEXT', | ||
'LONG_TEXT', | ||
'MULTI_TEXT', | ||
'LETTER', | ||
'PHONE_NUMBER', | ||
'EMAIL', | ||
'TRACKER_ASSOCIATE', | ||
'USERNAME', | ||
'FILE_RESOURCE', | ||
'COORDINATE', | ||
] | ||
const enabledValueTypes = aggregationTypes.filter( | ||
(aggregationType) => !disabledValueTypes.includes(aggregationType) | ||
) | ||
const disabelValueTypes = [ | ||
...enabledValueTypes.map((aggregationType) => [aggregationType, false]), | ||
...disabledValueTypes.map((aggregationType) => [aggregationType, true]), | ||
] | ||
describe.each(disabelValueTypes)( | ||
'disabled should be $disabled for $aggregationType', | ||
(valueType, disabled) => { | ||
test(`should be ${ | ||
disabled ? 'disabled' : 'enabled' | ||
} for valueType ${valueType}`, async () => { | ||
const initialValues = { | ||
valueType, | ||
aggregationType: 'SUM', | ||
} | ||
|
||
const result = render( | ||
<Form onSubmit={jest.fn()} initialValues={initialValues}> | ||
{({ handleSubmit }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<AggregationTypeField /> | ||
</form> | ||
)} | ||
</Form> | ||
) | ||
|
||
const input = await result.findByTestId( | ||
'dhis2-uicore-select-input' | ||
) | ||
expect(input.classList.contains('disabled')).toBe(disabled) | ||
|
||
const sumElement = result.queryByText('Sum') | ||
if (disabled) { | ||
expect(sumElement).toBeFalsy() | ||
} else { | ||
expect(sumElement).toBeTruthy() | ||
} | ||
}) | ||
} | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters