-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(application-system): Make required a dynamic field (#16691)
* feat(application-system): Make required a dynamic field * Added tests --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
63a12a7
commit dc89848
Showing
10 changed files
with
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Field } from '@island.is/application/types' | ||
|
||
import { FieldComponents, FieldTypes } from '@island.is/application/types' | ||
|
||
import { Application } from '@island.is/application/types' | ||
import { buildFieldOptions, buildFieldRequired } from './fieldBuilders' | ||
|
||
describe('buildFieldOptions', () => { | ||
const mockApplication = { | ||
id: 'test-app', | ||
state: 'draft', | ||
answers: {}, | ||
} as Application | ||
|
||
const mockField = { | ||
id: 'test-field', | ||
type: FieldTypes.SELECT, | ||
component: FieldComponents.SELECT, | ||
} as Field | ||
|
||
it('should return options array when passed static options', () => { | ||
const staticOptions = [ | ||
{ label: 'Option 1', value: '1' }, | ||
{ label: 'Option 2', value: '2' }, | ||
] | ||
|
||
const result = buildFieldOptions(staticOptions, mockApplication, mockField) | ||
|
||
expect(result).toEqual(staticOptions) | ||
}) | ||
|
||
it('should call function with application and field when passed function', () => { | ||
const dynamicOptions = jest.fn().mockReturnValue([ | ||
{ label: 'Dynamic 1', value: 'd1' }, | ||
{ label: 'Dynamic 2', value: 'd2' }, | ||
]) | ||
|
||
const result = buildFieldOptions(dynamicOptions, mockApplication, mockField) | ||
|
||
expect(dynamicOptions).toHaveBeenCalledWith(mockApplication, mockField) | ||
expect(result).toEqual([ | ||
{ label: 'Dynamic 1', value: 'd1' }, | ||
{ label: 'Dynamic 2', value: 'd2' }, | ||
]) | ||
}) | ||
}) | ||
|
||
describe('buildFieldRequired', () => { | ||
const mockApplication = { | ||
id: 'test-app', | ||
state: 'draft', | ||
answers: {}, | ||
} as Application | ||
|
||
it('should return boolean value when passed static boolean', () => { | ||
expect(buildFieldRequired(mockApplication, true)).toBe(true) | ||
expect(buildFieldRequired(mockApplication, false)).toBe(false) | ||
}) | ||
|
||
it('should return undefined when passed undefined', () => { | ||
expect(buildFieldRequired(mockApplication, undefined)).toBeUndefined() | ||
}) | ||
|
||
it('should call function with application when passed function', () => { | ||
const dynamicRequired = jest.fn().mockReturnValue(true) | ||
|
||
const result = buildFieldRequired(mockApplication, dynamicRequired) | ||
|
||
expect(dynamicRequired).toHaveBeenCalledWith(mockApplication) | ||
expect(result).toBe(true) | ||
}) | ||
}) |
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
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
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