1- import { expect , html , fixture , triggerFocusFor , nextFrame } from '@open-wc/testing' ;
2- import sinon from 'sinon' ;
1+ import { expect , html , fixture , nextFrame } from '@open-wc/testing' ;
32
43import { localizeTearDown } from '@lion/localize/test-helpers.js' ;
54
@@ -11,87 +10,6 @@ beforeEach(() => {
1110} ) ;
1211
1312describe ( '<lion-checkbox-group>' , ( ) => {
14- // Note: these requirements seem to hold for checkbox-group only, not for radio-group (since we
15- // cannot tab through all input elements).
16-
17- it ( `becomes "touched" once the last element of a group becomes blurred by keyboard
18- interaction (e.g. tabbing through the checkbox-group)` , async ( ) => {
19- const el = await fixture ( `
20- <lion-checkbox-group>
21- <label slot="label">My group</label>
22- <lion-checkbox name="myGroup[]" label="Option 1" value="1"></lion-checkbox>
23- <lion-checkbox name="myGroup[]" label="Option 2" value="2"></lion-checkbox>
24- </lion-checkbox-group>
25- ` ) ;
26- await nextFrame ( ) ;
27-
28- const button = await fixture ( `<button>Blur</button>` ) ;
29-
30- el . children [ 1 ] . focus ( ) ;
31- expect ( el . touched ) . to . equal ( false , 'initially, touched state is false' ) ;
32- el . children [ 2 ] . focus ( ) ;
33- expect ( el . touched ) . to . equal ( false , 'focus is on second checkbox' ) ;
34- button . focus ( ) ;
35- expect ( el . touched ) . to . equal (
36- true ,
37- `focus is on element behind second checkbox
38- (group has blurred)` ,
39- ) ;
40- } ) ;
41-
42- it ( `becomes "touched" once the group as a whole becomes blurred via mouse interaction after
43- keyboard interaction (e.g. focus is moved inside the group and user clicks somewhere outside
44- the group)` , async ( ) => {
45- const groupWrapper = await fixture ( `
46- <div tabindex="0">
47- <lion-checkbox-group>
48- <label slot="label">My group</label>
49- <lion-checkbox name="myGroup[]" label="Option 1" value="1"></lion-checkbox>
50- <lion-checkbox name="myGroup[]" label="Option 2" vallue="2"></lion-checkbox>
51- </lion-checkbox-group>
52- </div>
53- ` ) ;
54- await nextFrame ( ) ;
55-
56- const el = groupWrapper . children [ 0 ] ;
57- await el . children [ 1 ] . updateComplete ;
58- el . children [ 1 ] . focus ( ) ;
59- expect ( el . touched ) . to . equal ( false , 'initially, touched state is false' ) ;
60- el . children [ 2 ] . focus ( ) ; // simulate tab
61- expect ( el . touched ) . to . equal ( false , 'focus is on second checkbox' ) ;
62- // simulate click outside
63- sinon . spy ( el , '_setTouchedAndPrefilled' ) ;
64- groupWrapper . click ( ) ; // blur the group via a click
65- expect ( el . _setTouchedAndPrefilled . callCount ) . to . equal ( 1 ) ;
66- // For some reason, document.activeElement is not updated after groupWrapper.click() (this
67- // happens on user clicks, not on imperative clicks). So we check if the private callbacks
68- // for outside clicks are called (they trigger _setTouchedAndPrefilled call).
69- // To make sure focus is moved, we 'help' the test here to mimic browser behavior.
70- // groupWrapper.focus();
71- await triggerFocusFor ( groupWrapper ) ;
72- expect ( el . touched ) . to . equal ( true , 'focus is on element outside checkbox group' ) ;
73- } ) ;
74-
75- it ( `becomes "touched" once a single element of the group becomes "touched" via mouse interaction
76- (e.g. user clicks on checkbox)` , async ( ) => {
77- const el = await fixture ( `
78- <lion-checkbox-group>
79- <lion-checkbox name="myGroup[]"></lion-checkbox>
80- <lion-checkbox name="myGroup[]"></lion-checkbox>
81- </lion-checkbox-group>
82- ` ) ;
83- await nextFrame ( ) ;
84-
85- el . children [ 1 ] . focus ( ) ;
86- expect ( el . touched ) . to . equal ( false , 'initially, touched state is false' ) ;
87- el . children [ 1 ] . click ( ) ;
88- expect ( el . touched ) . to . equal (
89- true ,
90- `focus is initiated via a mouse event, thus
91- fieldset/checkbox-group as a whole is considered touched` ,
92- ) ;
93- } ) ;
94-
9513 it ( 'can be required' , async ( ) => {
9614 const el = await fixture ( html `
9715 < lion-checkbox-group .errorValidators =${ [ [ 'required' ] ] } >
0 commit comments