@@ -515,33 +515,65 @@ test.describe('Props', () => {
515
515
await expect ( await getValue ( ) ) . toEqual ( 'Select an option' ) ;
516
516
} ) ;
517
517
518
- test ( `GIVEN an uncontrolled select with a value prop on the root component
518
+ test . describe ( 'uncontrolled' , ( ) => {
519
+ test ( `GIVEN an uncontrolled select with a value prop on the root component
519
520
WHEN the value data matches the fourth option
520
521
THEN the selected value should be the data passed to the value prop` , async ( {
521
- page,
522
- } ) => {
523
- const { getValue } = await setup ( page , 'select-uncontrolled-test' ) ;
522
+ page,
523
+ } ) => {
524
+ const { getValue, getOptions } = await setup ( page , 'select-uncontrolled-test' ) ;
524
525
525
- await expect ( await getValue ( ) ) . toEqual ( 'Jessie' ) ;
526
- } ) ;
526
+ const options = await getOptions ( ) ;
527
527
528
- test ( `GIVEN an uncontrolled select with a value prop on the root component
529
- WHEN the value data matches the fourth option
528
+ expect ( await getValue ( ) ) . toEqual ( await options [ 3 ] . textContent ( ) ) ;
529
+ } ) ;
530
+
531
+ test ( `GIVEN an uncontrolled select with a value prop on the root component
532
+ WHEN the value prop data matches the fourth option
530
533
THEN the fourth option should have data-highlighted set to true` , async ( {
531
- page,
532
- } ) => {
533
- const { getValue, getOptions } = await setup ( page , 'select-uncontrolled-test' ) ;
534
+ page,
535
+ } ) => {
536
+ const { getValue, getOptions } = await setup ( page , 'select-uncontrolled-test' ) ;
534
537
535
- expect ( await getValue ( ) ) . toEqual ( 'Jessie' ) ;
536
- const options = await getOptions ( ) ;
537
- await expect ( options [ 3 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
538
+ const options = await getOptions ( ) ;
539
+ expect ( await getValue ( ) ) . toEqual ( await options [ 3 ] . textContent ( ) ) ;
540
+ await expect ( options [ 3 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
541
+ } ) ;
542
+
543
+ test ( `GIVEN an uncontrolled select with a value prop on the root component
544
+ WHEN the value prop data matches the fourth option
545
+ THEN the fourth option should have aria-selected set to true` , async ( {
546
+ page,
547
+ } ) => {
548
+ const { getValue, getOptions } = await setup ( page , 'select-uncontrolled-test' ) ;
549
+
550
+ const options = await getOptions ( ) ;
551
+ expect ( await getValue ( ) ) . toEqual ( await options [ 3 ] . textContent ( ) ) ;
552
+ await expect ( options [ 3 ] ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
553
+ } ) ;
554
+
555
+ test ( `GIVEN an uncontrolled select with a value prop on the root component
556
+ WHEN the value data does NOT match any option
557
+ THEN fallback to the placeholder` , async ( { page } ) => {
558
+ const { getValue } = await setup ( page , 'select-wrong-value-test' ) ;
559
+
560
+ /**
561
+ we also currently give a console warning in the terminal if an option does not match. Ideally, I would like to have a union type of options, and it gives an error if there is no matching option
562
+ */
563
+ expect ( await getValue ( ) ) . toEqual ( 'wrong value placeholder' ) ;
564
+ } ) ;
538
565
} ) ;
539
566
540
- // test(`GIVEN an uncontrolled select with a value prop on the root component
541
- // WHEN the value data does NOT match any option
542
- // THEN throw an error`, async ({ page }) => {
543
- // const { getValue } = await setup(page, 'select-wrong-value-test');
567
+ // test.describe('controlled', () => {
568
+ // test(`GIVEN a controlled select with a bind:value prop on the root component
569
+ // WHEN the signal data matches the second option
570
+ // THEN the selected value should be the data passed to the value prop`, async ({
571
+ // page,
572
+ // }) => {
573
+ // const { getValue, getOptions } = await setup(page, 'select-uncontrolled-test');
544
574
545
- // expect(await getValue()).toEqual('Jessi');
575
+ // const options = await getOptions();
576
+ // expect(await getValue()).toEqual(await options[1].textContent());
577
+ // });
546
578
// });
547
579
} ) ;
0 commit comments