-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #730 from open-formulieren/backport/2.4.x-select-d…
…atatype [Backport 2.4.x] 🐛 [open-formulieren/open-forms#4772] Fix select component with integer values
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import _ from 'lodash'; | ||
import {Formio} from 'react-formio'; | ||
|
||
import {BASE_URL} from 'api-mocks'; | ||
import OpenFormsModule from 'formio/module'; | ||
|
||
// Use our custom components | ||
Formio.use(OpenFormsModule); | ||
|
||
const selectForm = { | ||
type: 'form', | ||
components: [ | ||
{ | ||
type: 'select', | ||
key: 'selectWithInt', | ||
label: 'Select with integer values', | ||
data: { | ||
values: [ | ||
{ | ||
label: 'Optie 1', | ||
value: '1', | ||
}, | ||
{ | ||
label: 'Optie 2', | ||
value: '2', | ||
}, | ||
], | ||
}, | ||
validate: { | ||
required: true, | ||
}, | ||
}, | ||
], | ||
title: 'Test Select form', | ||
display: 'Test Select form', | ||
name: 'testSelectForm', | ||
path: 'testSelectForm', | ||
}; | ||
|
||
describe('Select Component', () => { | ||
test('Values are always strings', done => { | ||
let formJSON = _.cloneDeep(selectForm); | ||
|
||
const element = document.createElement('div'); | ||
|
||
Formio.createForm(element, formJSON, {baseUrl: BASE_URL}) | ||
.then(form => { | ||
form.setPristine(false); | ||
const select = form.getComponent('selectWithInt'); | ||
|
||
select.setValue('1'); | ||
|
||
form | ||
.submit() | ||
.then(submission => { | ||
// Verify that the value of the select component in the submission data is as expected | ||
expect(submission.data.selectWithInt).toEqual('1'); | ||
done(); | ||
}) | ||
.catch(done); | ||
}) | ||
.catch(done); | ||
}); | ||
}); |