@@ -3,6 +3,7 @@ import { sendKeys } from "@web/test-runner-commands";
3
3
import BlSelect from "./bl-select" ;
4
4
import BlButton from "../button/bl-button" ;
5
5
import BlCheckbox from "../checkbox-group/checkbox/bl-checkbox" ;
6
+ import "../checkbox-group/checkbox/bl-checkbox" ;
6
7
import type BlSelectOption from "./option/bl-select-option" ;
7
8
8
9
describe ( "bl-select" , ( ) => {
@@ -181,6 +182,31 @@ describe("bl-select", () => {
181
182
expect ( el . selectedOptions . length ) . to . equal ( 0 ) ;
182
183
expect ( el . value ) . to . null ;
183
184
} ) ;
185
+ it ( "should keep selected disabled options when remove all clicked" , async ( ) => {
186
+ const el = await fixture < BlSelect > ( html `< bl-select multiple >
187
+ < bl-select-option value ="1 " disabled selected > Option 1</ bl-select-option >
188
+ < bl-select-option value ="2 " selected > Option 2</ bl-select-option >
189
+ </ bl-select > ` ) ;
190
+
191
+ const removeAll = el . shadowRoot ?. querySelector < BlButton > ( ".remove-all" ) ;
192
+
193
+ setTimeout ( ( ) => removeAll ?. click ( ) ) ;
194
+
195
+ const event = await oneEvent ( el , "bl-select" ) ;
196
+
197
+ expect ( el . shadowRoot ?. querySelector < BlButton > ( ".remove-all" ) ) . to . not . exist ;
198
+ expect ( event ) . to . exist ;
199
+ expect ( event . detail ) . to . deep . eq ( [
200
+ {
201
+ selected : true ,
202
+ text : "Option 1" ,
203
+ value : "1" ,
204
+ }
205
+ ] ) ;
206
+ expect ( el . options . length ) . to . equal ( 2 ) ;
207
+ expect ( el . selectedOptions . length ) . to . equal ( 1 ) ;
208
+ expect ( el . value ) . to . deep . eq ( [ "1" ] ) ;
209
+ } ) ;
184
210
it ( "should hide remove icon button on single required selection" , async ( ) => {
185
211
const el = await fixture < BlSelect > ( html `< bl-select required >
186
212
< bl-select-option value ="1 "> Option 1</ bl-select-option >
@@ -510,4 +536,118 @@ describe("bl-select", () => {
510
536
expect ( ( document . activeElement as BlSelectOption ) . value ) . to . equal ( firstOption ?. value ) ;
511
537
} ) ;
512
538
} ) ;
539
+
540
+ describe ( "select all" , ( ) => {
541
+ it ( "should select all options" , async ( ) => {
542
+ const el = await fixture < BlSelect > ( html `< bl-select multiple >
543
+ < bl-select-option value ="1 "> Option 1</ bl-select-option >
544
+ < bl-select-option value ="2 "> Option 2</ bl-select-option >
545
+ < bl-select-option value ="3 "> Option 3</ bl-select-option >
546
+ < bl-select-option value ="4 "> Option 4</ bl-select-option >
547
+ < bl-select-option value ="5 "> Option 5</ bl-select-option >
548
+ </ bl-select > ` ) ;
549
+
550
+
551
+ const selectAll = el . shadowRoot ! . querySelector < BlCheckbox > ( ".select-all" ) ! ;
552
+
553
+ setTimeout ( ( ) => selectAll . dispatchEvent (
554
+ new CustomEvent ( "bl-checkbox-change" , { detail : true } ) )
555
+ ) ;
556
+ const event = await oneEvent ( el , "bl-select" ) ;
557
+
558
+ expect ( event ) . to . exist ;
559
+ expect ( event . detail . length ) . to . equal ( 5 ) ;
560
+ expect ( el . selectedOptions . length ) . to . equal ( 5 ) ;
561
+ } ) ;
562
+
563
+ it ( "should deselect all options" , async ( ) => {
564
+ const el = await fixture < BlSelect > ( html `< bl-select multiple .value =${ [ "1" , "2" , "3" , "4" , "5" ] } >
565
+ < bl-select-option value ="1 "> Option 1</ bl-select-option >
566
+ < bl-select-option value ="2 "> Option 2</ bl-select-option >
567
+ < bl-select-option value ="3 "> Option 3</ bl-select-option >
568
+ < bl-select-option value ="4 "> Option 4</ bl-select-option >
569
+ < bl-select-option value ="5 "> Option 5</ bl-select-option >
570
+ </ bl-select > ` ) ;
571
+
572
+ expect ( el . selectedOptions . length ) . to . equal ( 5 ) ;
573
+
574
+ const selectAll = el . shadowRoot ! . querySelector < BlCheckbox > ( ".select-all" ) ! ;
575
+
576
+ setTimeout ( ( ) => selectAll . dispatchEvent (
577
+ new CustomEvent ( "bl-checkbox-change" , { detail : false } ) )
578
+ ) ;
579
+
580
+ const event = await oneEvent ( el , "bl-select" ) ;
581
+
582
+ expect ( event ) . to . exist ;
583
+ expect ( event . detail . length ) . to . equal ( 0 ) ;
584
+ expect ( el . selectedOptions . length ) . to . equal ( 0 ) ;
585
+ } ) ;
586
+
587
+ it ( "should not act on disabled options" , async ( ) => {
588
+ const el = await fixture < BlSelect > ( html `< bl-select multiple >
589
+ < bl-select-option value ="1 " disabled > Option 1</ bl-select-option >
590
+ < bl-select-option value ="2 "> Option 2</ bl-select-option >
591
+ < bl-select-option value ="3 "> Option 3</ bl-select-option >
592
+ < bl-select-option value ="4 "> Option 4</ bl-select-option >
593
+ < bl-select-option value ="5 "> Option 5</ bl-select-option >
594
+ </ bl-select > ` ) ;
595
+
596
+ const selectAll = el . shadowRoot ! . querySelector < BlCheckbox > ( ".select-all" ) ! ;
597
+
598
+ setTimeout ( ( ) => selectAll . dispatchEvent (
599
+ new CustomEvent ( "bl-checkbox-change" , { detail : true } ) )
600
+ ) ;
601
+
602
+ const event = await oneEvent ( el , "bl-select" ) ;
603
+
604
+ expect ( event ) . to . exist ;
605
+ expect ( event . detail . length ) . to . equal ( 4 ) ;
606
+ expect ( el . selectedOptions . length ) . to . equal ( 4 ) ;
607
+ expect ( el . selectedOptions [ 0 ] . value ) . to . equal ( "2" ) ;
608
+ } ) ;
609
+
610
+ it ( "should display indeterminate state when some options are selected" , async ( ) => {
611
+ const el = await fixture < BlSelect > ( html `< bl-select multiple >
612
+ < bl-select-option value ="1 " selected > Option 1</ bl-select-option >
613
+ < bl-select-option value ="2 "> Option 2</ bl-select-option >
614
+ < bl-select-option value ="3 "> Option 3</ bl-select-option >
615
+ < bl-select-option value ="4 "> Option 4</ bl-select-option >
616
+ < bl-select-option value ="5 "> Option 5</ bl-select-option >
617
+ </ bl-select > ` ) ;
618
+
619
+ const selectAll = el . shadowRoot ! . querySelector < BlCheckbox > ( ".select-all" ) ! ;
620
+
621
+ expect ( selectAll . indeterminate ) . to . be . true ;
622
+ expect ( selectAll . checked ) . to . be . false ;
623
+ } ) ;
624
+
625
+ it ( 'should uncheck "select all" checkbox when all available options are selected' , async ( ) => {
626
+ const el = await fixture < BlSelect > ( html `< bl-select multiple >
627
+ < bl-select-option value ="1 " disabled > Option 1</ bl-select-option >
628
+ < bl-select-option value ="2 " selected > Option 2</ bl-select-option >
629
+ < bl-select-option value ="3 " selected > Option 3</ bl-select-option >
630
+ < bl-select-option value ="4 " selected > Option 4</ bl-select-option >
631
+ < bl-select-option value ="5 " selected > Option 5</ bl-select-option >
632
+ </ bl-select > ` ) ;
633
+
634
+ const selectAll = el . shadowRoot ! . querySelector < BlCheckbox > ( ".select-all" ) ! ;
635
+
636
+ expect ( selectAll . indeterminate ) . to . be . true ;
637
+ expect ( selectAll . checked ) . to . be . false ;
638
+
639
+ setTimeout ( ( ) => selectAll . dispatchEvent (
640
+ new CustomEvent ( "bl-checkbox-change" , { detail : true } ) )
641
+ ) ;
642
+
643
+ const event = await oneEvent ( el , "bl-select" ) ;
644
+
645
+ expect ( event ) . to . exist ;
646
+ expect ( event . detail . length ) . to . equal ( 0 ) ;
647
+ expect ( el . selectedOptions . length ) . to . equal ( 0 ) ;
648
+
649
+ expect ( selectAll . indeterminate ) . to . be . false ;
650
+ expect ( selectAll . checked ) . to . be . false ;
651
+ } ) ;
652
+ } ) ;
513
653
} ) ;
0 commit comments