Skip to content

WIP accepted rule #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions __tests__/suits/rules/checked.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Validator } from '@/Validator';
import checked from '@/rules/checked';

describe('test checked rule', (): void => {
beforeEach((): void => {
Validator.extend('checked', checked);
});

it('should always validate correct elements', async (): Promise<void> => {
const checkbox = document.createElement('input');
checkbox.setAttribute('type', 'checkbox');
checkbox.setAttribute('checked', 'checked');

const radio1 = document.createElement('input');
radio1.setAttribute('type', 'radio');
radio1.setAttribute('name', 'test');
const radio2 = document.createElement('input');
radio2.setAttribute('type', 'radio');
radio2.setAttribute('name', 'test');
document.body.append(radio1, radio2);

const immediate_radio = document.createElement('input');
immediate_radio.setAttribute('type', 'radio');
immediate_radio.setAttribute('checked', 'checked');

const canvas = document.createElement('canvas');

const validator_radios = new Validator([
radio1,
radio2,
],
['checked'],
'');

const validator_checkbox = new Validator([
checkbox
],
['checked'],
'');

const validator_canvas = new Validator([
canvas,
],
['checked'],
'');

const validator_immediate_radio = new Validator([
immediate_radio,
],
['checked'],
'');

await validator_radios.validate();
expect(validator_radios.getErrors().length).toBe(1);

await validator_checkbox.validate();
expect(validator_checkbox.getErrors().length).toBe(0);

await validator_canvas.validate();
expect(validator_canvas.getErrors().length).toBe(0);

await validator_immediate_radio.validate();
expect(validator_immediate_radio.getErrors().length).toBe(0);
});
})
Loading