assertInstanceOf(PopoverComponent::class, $component); $this->assertFalse($component->state->isVisible); $this->assertEquals('top', $component->state->position); $this->assertEquals('test-anchor', $component->state->anchorId); } public function testShowActionShowsPopover(): void { $component = new PopoverComponent( id: ComponentId::fromString('popover:test') ); $newState = $component->show('Test Content', 'Test Title', 'test-anchor', 'bottom'); $this->assertTrue($newState->isVisible); $this->assertEquals('Test Content', $newState->content); $this->assertEquals('Test Title', $newState->title); $this->assertEquals('test-anchor', $newState->anchorId); $this->assertEquals('bottom', $newState->position); } public function testHideActionHidesPopover(): void { $component = new PopoverComponent( id: ComponentId::fromString('popover:test'), isVisible: true ); $newState = $component->hide(); $this->assertFalse($newState->isVisible); } public function testToggleActionTogglesPopover(): void { $component = new PopoverComponent( id: ComponentId::fromString('popover:test'), isVisible: false ); $visibleState = $component->toggle(); $this->assertTrue($visibleState->isVisible); // Simulate state update $component = new PopoverComponent( id: ComponentId::fromString('popover:test'), initialData: ComponentData::fromArray($visibleState->toArray()) ); $hiddenState = $component->toggle(); $this->assertFalse($hiddenState->isVisible); } public function testUpdatePositionActionUpdatesPosition(): void { $component = new PopoverComponent( id: ComponentId::fromString('popover:test'), position: 'top' ); $newState = $component->updatePosition('right'); $this->assertEquals('right', $newState->position); } public function testUpdateAnchorActionUpdatesAnchor(): void { $component = new PopoverComponent( id: ComponentId::fromString('popover:test'), anchorId: 'old-anchor' ); $newState = $component->updateAnchor('new-anchor'); $this->assertEquals('new-anchor', $newState->anchorId); } public function testPopoverStateFromArray(): void { $data = [ 'is_visible' => true, 'position' => 'bottom', 'anchor_id' => 'test-anchor', 'content' => 'Test Content', 'title' => 'Test Title', 'show_arrow' => true, 'offset' => 10, 'close_on_outside_click' => true, 'z_index' => 1060, ]; $state = PopoverState::fromArray($data); $this->assertTrue($state->isVisible); $this->assertEquals('bottom', $state->position); $this->assertEquals('test-anchor', $state->anchorId); } public function testPopoverStateToArray(): void { $state = new PopoverState( isVisible: true, position: 'top', anchorId: 'test-anchor' ); $array = $state->toArray(); $this->assertTrue($array['is_visible']); $this->assertEquals('top', $array['position']); $this->assertEquals('test-anchor', $array['anchor_id']); } public function testPopoverStateIsAutoPosition(): void { $autoState = new PopoverState(position: 'auto'); $topState = new PopoverState(position: 'top'); $this->assertTrue($autoState->isAutoPosition()); $this->assertFalse($topState->isAutoPosition()); } public function testPopoverStateGetPositionClass(): void { $state = new PopoverState(position: 'top'); $this->assertEquals('popover--top', $state->getPositionClass()); $state = new PopoverState(position: 'bottom'); $this->assertEquals('popover--bottom', $state->getPositionClass()); } }