Some checks failed
Deploy Application / deploy (push) Has been cancelled
160 lines
4.7 KiB
PHP
160 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\LiveComponents\Drawer;
|
|
|
|
use App\Application\LiveComponents\Drawer\DrawerComponent;
|
|
use App\Application\LiveComponents\Drawer\DrawerState;
|
|
use App\Framework\LiveComponents\ValueObjects\ComponentData;
|
|
use App\Framework\LiveComponents\ValueObjects\ComponentId;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class DrawerComponentTest extends TestCase
|
|
{
|
|
public function testDrawerComponentCanBeCreated(): void
|
|
{
|
|
$component = new DrawerComponent(
|
|
id: ComponentId::fromString('drawer:test'),
|
|
isOpen: false,
|
|
position: 'left',
|
|
width: '400px'
|
|
);
|
|
|
|
$this->assertInstanceOf(DrawerComponent::class, $component);
|
|
$this->assertFalse($component->state->isOpen);
|
|
$this->assertEquals('left', $component->state->position);
|
|
}
|
|
|
|
public function testOpenActionOpensDrawer(): void
|
|
{
|
|
$component = new DrawerComponent(
|
|
id: ComponentId::fromString('drawer:test')
|
|
);
|
|
|
|
$newState = $component->open('Test Title', 'Test Content', 'right', '500px');
|
|
|
|
$this->assertTrue($newState->isOpen);
|
|
$this->assertEquals('Test Title', $newState->title);
|
|
$this->assertEquals('Test Content', $newState->content);
|
|
$this->assertEquals('right', $newState->position);
|
|
$this->assertEquals('500px', $newState->width);
|
|
}
|
|
|
|
public function testCloseActionClosesDrawer(): void
|
|
{
|
|
$component = new DrawerComponent(
|
|
id: ComponentId::fromString('drawer:test'),
|
|
isOpen: true
|
|
);
|
|
|
|
$newState = $component->close();
|
|
|
|
$this->assertFalse($newState->isOpen);
|
|
}
|
|
|
|
public function testToggleActionTogglesDrawer(): void
|
|
{
|
|
$component = new DrawerComponent(
|
|
id: ComponentId::fromString('drawer:test'),
|
|
isOpen: false
|
|
);
|
|
|
|
$openedState = $component->toggle();
|
|
$this->assertTrue($openedState->isOpen);
|
|
|
|
// Simulate state update
|
|
$component = new DrawerComponent(
|
|
id: ComponentId::fromString('drawer:test'),
|
|
initialData: ComponentData::fromArray($openedState->toArray())
|
|
);
|
|
|
|
$closedState = $component->toggle();
|
|
$this->assertFalse($closedState->isOpen);
|
|
}
|
|
|
|
public function testUpdateContentActionUpdatesContent(): void
|
|
{
|
|
$component = new DrawerComponent(
|
|
id: ComponentId::fromString('drawer:test'),
|
|
isOpen: true,
|
|
content: 'Old Content'
|
|
);
|
|
|
|
$newState = $component->updateContent('New Content');
|
|
|
|
$this->assertEquals('New Content', $newState->content);
|
|
$this->assertTrue($newState->isOpen); // State should remain open
|
|
}
|
|
|
|
public function testChangePositionActionChangesPosition(): void
|
|
{
|
|
$component = new DrawerComponent(
|
|
id: ComponentId::fromString('drawer:test'),
|
|
position: 'left'
|
|
);
|
|
|
|
$newState = $component->changePosition('right');
|
|
|
|
$this->assertEquals('right', $newState->position);
|
|
}
|
|
|
|
public function testDrawerStateFromArray(): void
|
|
{
|
|
$data = [
|
|
'is_open' => true,
|
|
'position' => 'right',
|
|
'width' => '500px',
|
|
'show_overlay' => true,
|
|
'title' => 'Test',
|
|
'content' => 'Content',
|
|
'close_on_overlay' => true,
|
|
'close_on_escape' => true,
|
|
'animation' => 'slide',
|
|
'z_index' => 1050,
|
|
];
|
|
|
|
$state = DrawerState::fromArray($data);
|
|
|
|
$this->assertTrue($state->isOpen);
|
|
$this->assertEquals('right', $state->position);
|
|
$this->assertEquals('500px', $state->width);
|
|
}
|
|
|
|
public function testDrawerStateToArray(): void
|
|
{
|
|
$state = new DrawerState(
|
|
isOpen: true,
|
|
position: 'left',
|
|
width: '400px'
|
|
);
|
|
|
|
$array = $state->toArray();
|
|
|
|
$this->assertTrue($array['is_open']);
|
|
$this->assertEquals('left', $array['position']);
|
|
$this->assertEquals('400px', $array['width']);
|
|
}
|
|
|
|
public function testDrawerStatePositionHelpers(): void
|
|
{
|
|
$leftState = new DrawerState(position: 'left');
|
|
$rightState = new DrawerState(position: 'right');
|
|
|
|
$this->assertTrue($leftState->isLeft());
|
|
$this->assertFalse($leftState->isRight());
|
|
$this->assertTrue($rightState->isRight());
|
|
$this->assertFalse($rightState->isLeft());
|
|
}
|
|
|
|
public function testDrawerStateGetPositionClass(): void
|
|
{
|
|
$state = new DrawerState(position: 'left');
|
|
$this->assertEquals('drawer--left', $state->getPositionClass());
|
|
|
|
$state = new DrawerState(position: 'right');
|
|
$this->assertEquals('drawer--right', $state->getPositionClass());
|
|
}
|
|
}
|
|
|