diff --git a/tests/integration/Twig/Components/DropdownSingle/InputTest.php b/tests/integration/Twig/Components/DropdownSingle/InputTest.php new file mode 100644 index 00000000..99e9d94b --- /dev/null +++ b/tests/integration/Twig/Components/DropdownSingle/InputTest.php @@ -0,0 +1,251 @@ +mountTwigComponent(Input::class, $this->baseProps(['value' => 'foo'])); + + self::assertInstanceOf( + Input::class, + $component, + 'Component should mount as DropdownSingle\\Input.' + ); + } + + public function testEmptyStateShowsPlaceholderAndHidesSelectedItems(): void + { + $crawler = $this->renderTwigComponent( + Input::class, + $this->baseProps() + )->crawler(); + + $select = $this->getSelect($crawler); + $selectedOption = $select->filter('option[selected]')->first(); + self::assertSame( + 'a', + $selectedOption->attr('value'), + 'Without a value, the first option should be selected by default.' + ); + self::assertSame( + 'Alpha', + trim($selectedOption->text('')), + 'The first option label should be shown as selected by default.' + ); + + $placeholder = $crawler->filter('.ids-dropdown__placeholder')->first(); + $selectedBox = $crawler->filter('.ids-dropdown__selection-info-items')->first(); + + self::assertNotNull( + $placeholder->attr('hidden'), + 'Placeholder should be hidden when no explicit value is selected.' + ); + self::assertNull( + $selectedBox->attr('hidden'), + 'Selection box should be visible when no explicit value is selected.' + ); + self::assertStringContainsString( + 'Alpha', + trim($selectedBox->text('')), + 'Selection box should show the first item label by default.' + ); + } + + public function testSelectedValueHidesPlaceholderAndShowsSelectedLabel(): void + { + $crawler = $this->renderTwigComponent(Input::class, $this->baseProps(['value' => 'b']))->crawler(); + + $select = $this->getSelect($crawler); + $selectedOption = $select->filter('option[selected]')->first(); + + self::assertSame( + 'b', + $selectedOption->attr('value'), + 'Selected