Skip to content

Commit

Permalink
FIO-8461: Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekotikov committed Jul 1, 2024
1 parent 657536a commit 4e330b8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
31 changes: 30 additions & 1 deletion src/components/checkbox/Checkbox.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
comp2,
comp3,
comp4,
comp5
comp5,
comp6
} from './fixtures';

describe('Checkbox Component', () => {
Expand Down Expand Up @@ -64,6 +65,34 @@ describe('Checkbox Component', () => {
});
});

it('Should be able to submit default checkbox data with the radio input type', (done) => {
const form = _.cloneDeep(comp6);
const element = document.createElement('div');
const inputName = form.components[0].name;

Formio.createForm(element, form).then(form => {
const submit = form.getComponent('submit');
const clickEvent = new Event('click');
const submitBtn = submit.refs.button;
submitBtn.dispatchEvent(clickEvent);

setTimeout(() => {
assert.equal(form.submission.data[inputName], '');
const radioCheckBox = form.getComponent('checkbox');
const radio = Harness.testElements(radioCheckBox, 'input[type="radio"]', 1)[0];
Harness.clickElement(radioCheckBox, radio);
setTimeout(() => {
assert.equal(form.submission.data[inputName], 'ok');
Harness.clickElement(radioCheckBox, radio);
setTimeout(() => {
assert.equal(form.submission.data[inputName], '');
done();
}, 200);
}, 200);
}, 200);
}).catch((err) => done(err));
});

it('Should render red asterisk for preview template of the modal required checkbox ', (done) => {
Harness.testCreate(CheckBoxComponent, comp3).then((component) => {
const label = component.element.querySelector('.control-label');
Expand Down
30 changes: 30 additions & 0 deletions src/components/checkbox/fixtures/comp6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default
{
name: 'ckeckbox',
path: 'ckeckbox',
type: 'form',
display: 'form',

components: [
{
label: 'Checkbox',
inputType: 'radio',
tableView: false,
defaultValue: false,
key: 'checkbox',
type: 'checkbox',
name: 'some name',
value: 'ok',
input: true,
'some name': false
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false
}
],
};
3 changes: 2 additions & 1 deletion src/components/checkbox/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import comp2 from './comp2';
import comp3 from './comp3';
import comp4 from './comp4';
import comp5 from './comp5';
export { comp1, comp2, comp3, comp4, comp5, customDefaultComponent };
import comp6 from './comp6';
export { comp1, comp2, comp3, comp4, comp5, comp6, customDefaultComponent };

0 comments on commit 4e330b8

Please sign in to comment.