-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIREC-284-settings-for-number-generator add NumberGeneratorSettingsFo…
…rm.test.js, cleaning
- Loading branch information
Showing
4 changed files
with
141 additions
and
33 deletions.
There are no files selected for viewing
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
98 changes: 98 additions & 0 deletions
98
src/Settings/NumberGeneratorSettings/NumberGeneratorSettingsForm.test.js
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,98 @@ | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import { | ||
render, | ||
screen, | ||
} from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import NumberGeneratorSettingsForm from './NumberGeneratorSettingsForm'; | ||
import { | ||
BARCODE_SETTING, | ||
NUMBER_GENERATOR_OPTIONS, | ||
} from '../../common/constants/numberGenerator'; | ||
|
||
jest.mock('@folio/stripes/core', () => ({ | ||
useStripes: jest.fn(), | ||
})); | ||
|
||
const onSubmitMock = jest.fn(); | ||
|
||
const renderComponent = () => render( | ||
<NumberGeneratorSettingsForm | ||
initialValues={{ [BARCODE_SETTING]: NUMBER_GENERATOR_OPTIONS.USE_BOTH }} | ||
onSubmit={(values) => onSubmitMock(values)} | ||
/>, | ||
{ wrapper: MemoryRouter }, | ||
); | ||
|
||
describe('NumberGeneratorSettingsForm', () => { | ||
it('should render the component with initial values', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByText('ui-receiving.settings.numberGenerator.options')).toBeInTheDocument(); | ||
expect(screen.getByText('ui-receiving.settings.numberGenerator.info')).toBeInTheDocument(); | ||
expect(screen.getAllByText('ui-receiving.settings.numberGenerator.setManually')).toHaveLength(3); | ||
expect(screen.getAllByText('ui-receiving.settings.numberGenerator.setGeneratorOrManually')).toHaveLength(3); | ||
expect(screen.getAllByText('ui-receiving.settings.numberGenerator.setGenerator')).toHaveLength(3); | ||
expect(screen.getByText('ui-receiving.settings.numberGenerator.accessionNumberEqualCallNumber')).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'stripes-core.button.save' })).toBeDisabled(); | ||
}); | ||
|
||
it('should call onSubmit with correct values', async () => { | ||
renderComponent(); | ||
|
||
const barcodeUseManually = document.getElementById('barcodeUseTextField'); | ||
|
||
expect(barcodeUseManually).toBeInTheDocument(); | ||
|
||
const saveButton = screen.getByRole('button', { name: 'stripes-core.button.save' }); | ||
|
||
await userEvent.click(barcodeUseManually); | ||
expect(saveButton).toBeEnabled(); | ||
|
||
await userEvent.click(saveButton); | ||
expect(onSubmitMock).toHaveBeenCalledWith({ | ||
[BARCODE_SETTING]: NUMBER_GENERATOR_OPTIONS.USE_TEXT_FIELD, | ||
}); | ||
}); | ||
|
||
it('should disable useSharedNumber-checkbox if clicking callNumber or accessionNumber to use manually', async () => { | ||
renderComponent(); | ||
|
||
const callNumberUseManually = document.getElementById('callNumberUseTextField'); | ||
const callNumberUseBoth = document.getElementById('callNumberUseBoth'); | ||
const accessionNumberUseManually = document.getElementById('accessionNumberUseTextField'); | ||
const useSharedNumberCheckbox = document.getElementById('useSharedNumber'); | ||
|
||
expect(callNumberUseManually).toBeInTheDocument(); | ||
expect(callNumberUseBoth).toBeInTheDocument(); | ||
expect(accessionNumberUseManually).toBeInTheDocument(); | ||
expect(useSharedNumberCheckbox).toBeInTheDocument(); | ||
|
||
await userEvent.click(callNumberUseManually); | ||
expect(useSharedNumberCheckbox).toHaveAttribute('disabled'); | ||
|
||
await userEvent.click(callNumberUseBoth); | ||
expect(useSharedNumberCheckbox).not.toHaveAttribute('disabled'); | ||
|
||
await userEvent.click(accessionNumberUseManually); | ||
expect(useSharedNumberCheckbox).toHaveAttribute('disabled'); | ||
}); | ||
|
||
it('should disable callNumber or accessionNumber to use manually if clicking useSharedNumber-checkbox', async () => { | ||
renderComponent(); | ||
|
||
const callNumberUseManually = document.getElementById('callNumberUseTextField'); | ||
const accessionNumberUseManually = document.getElementById('accessionNumberUseTextField'); | ||
const useSharedNumberCheckbox = document.getElementById('useSharedNumber'); | ||
|
||
expect(callNumberUseManually).toBeInTheDocument(); | ||
expect(accessionNumberUseManually).toBeInTheDocument(); | ||
expect(useSharedNumberCheckbox).toBeInTheDocument(); | ||
|
||
await userEvent.click(useSharedNumberCheckbox); | ||
expect(callNumberUseManually).toHaveAttribute('disabled'); | ||
expect(accessionNumberUseManually).toHaveAttribute('disabled'); | ||
}); | ||
}); |
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,11 @@ | ||
export const NUMBER_GENERATOR_OPTIONS = { | ||
USE_BOTH: 'useBoth', | ||
USE_GENERATOR: 'useGenerator', | ||
USE_TEXT_FIELD: 'useTextField', | ||
}; | ||
|
||
export const ACCESSION_NUMBER_SETTING = 'accessionNumber'; | ||
export const BARCODE_SETTING = 'barcode'; | ||
export const CALL_NUMBER_SETTING = 'callNumber'; | ||
|
||
export const USE_SHARED_NUMBER = 'useSharedNumber'; |