Skip to content

Commit decf801

Browse files
committed
test: checkbox
1 parent 8e34a4e commit decf801

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { describe, expect, it } from '@jest/globals';
2+
import Checkbox from './checkbox';
3+
import CheckboxConditionsHandler from './checkboxConditionsHandler';
4+
import CheckboxConditionValidator from './checkboxConditionValidator';
5+
6+
describe('Checkbox', () => {
7+
const fakeCheckBoxHandler = {
8+
init: jest.fn(),
9+
dispatchUpdateEvent(condition: any): boolean { return true; },
10+
addValueChangeListener(field: FieldInterface): void {},
11+
getConditions(): Condition[] { return []; },
12+
getIsDisabled(): boolean { return false; },
13+
validate(): void {}
14+
} as unknown as CheckboxConditionsHandler;
15+
const fakeCheckBoxValidator = {
16+
init: jest.fn(),
17+
validate(condition: Condition): boolean { return true; }
18+
} as unknown as CheckboxConditionValidator;
19+
const field = document.createElement('div');
20+
field.innerHTML = `<input type="checkbox" name="testField" value="1" checked><input type="checkbox" name="testField2" value="2">`;
21+
const choices = field.querySelectorAll('input[type="checkbox"]') as NodeListOf<HTMLInputElement>;
22+
23+
const checkBox = new Checkbox(
24+
field,
25+
choices,
26+
'testField',
27+
fakeCheckBoxValidator,
28+
fakeCheckBoxHandler
29+
)
30+
31+
it('init() initializes the conditions handler and validator', () => {
32+
checkBox.init({} as any);
33+
expect(fakeCheckBoxHandler.init).toHaveBeenCalledWith(checkBox, {} as any);
34+
expect(fakeCheckBoxValidator.init).toHaveBeenCalledWith(checkBox);
35+
});
36+
37+
it('getName() returns field name', () => {
38+
expect(checkBox.getName()).toBe('testField');
39+
});
40+
41+
it('getConditionsHandler() returns the conditions handler', () => {
42+
expect(checkBox.getConditionsHandler()).toBe(fakeCheckBoxHandler);
43+
});
44+
45+
it('getConditionValidator() returns the validation handler', () => {
46+
expect(checkBox.getConditionValidator()).toBe(fakeCheckBoxValidator);
47+
});
48+
49+
it('getChoices() returns the available choices', () => {
50+
expect(checkBox.getChoices()).toBe(choices);
51+
});
52+
53+
it('getField() returns the available choices', () => {
54+
expect(checkBox.getField()).toBe(field);
55+
});
56+
57+
it('getSelectedChoices() returns selected choices values', () => {
58+
expect(checkBox.getSelectedChoices()).toStrictEqual(["1"]);
59+
});
60+
});

source/js/fields/fieldBuilder.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { describe, expect, it } from '@jest/globals';
22
import FieldBuilder from './fieldBuilder';
33
import NullField from './field/nullField/nullField';
44
import Checkbox from './field/checkbox/checkbox';
5-
import { normalModuleLoaderHook } from 'webpack-manifest-plugin/dist/hooks';
65

76
describe('Field Builder', () => {
87
const fieldBuilder = new FieldBuilder();

0 commit comments

Comments
 (0)