Skip to content

Commit cdb0b68

Browse files
Copilotiamgergo
andcommitted
Add additional View component tests for Chart and Copyable, improve Alert test
Co-authored-by: iamgergo <[email protected]>
1 parent 7c3cc88 commit cdb0b68

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

tests/View/Components/AlertComponentTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,36 @@ public function test_alert_component_renders(): void
2323
$view = $component->render();
2424

2525
$this->assertSame('root::components.alert', $view->name());
26+
$this->assertSame('info', $view->getData()['type']);
27+
$this->assertFalse($view->getData()['closable']);
28+
}
29+
30+
public function test_alert_component_accepts_type(): void
31+
{
32+
$component = new AlertComponent('success');
33+
34+
$view = $component->render();
35+
36+
$this->assertSame('success', $view->getData()['type']);
37+
$this->assertSame('alert--success', $view->getData()['class']);
38+
}
39+
40+
public function test_alert_component_handles_error_type(): void
41+
{
42+
$component = new AlertComponent('error');
43+
44+
$view = $component->render();
45+
46+
$this->assertSame('error', $view->getData()['type']);
47+
$this->assertSame('alert--danger', $view->getData()['class']);
48+
}
49+
50+
public function test_alert_component_can_be_closable(): void
51+
{
52+
$component = new AlertComponent('info', true);
53+
54+
$view = $component->render();
55+
56+
$this->assertTrue($view->getData()['closable']);
2657
}
2758
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cone\Root\Tests\View\Components;
6+
7+
use Cone\Root\Tests\TestCase;
8+
use Cone\Root\View\Components\Chart;
9+
10+
final class ChartTest extends TestCase
11+
{
12+
public function test_chart_component_renders(): void
13+
{
14+
$component = new Chart();
15+
16+
$view = $component->render();
17+
18+
$this->assertSame('root::components.chart', $view->name());
19+
$this->assertSame([], $view->getData()['config']);
20+
}
21+
22+
public function test_chart_component_accepts_config(): void
23+
{
24+
$config = [
25+
'type' => 'bar',
26+
'data' => ['values' => [1, 2, 3]],
27+
];
28+
29+
$component = new Chart($config);
30+
31+
$view = $component->render();
32+
33+
$this->assertSame($config, $view->getData()['config']);
34+
}
35+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cone\Root\Tests\View\Components;
6+
7+
use Cone\Root\Tests\TestCase;
8+
use Cone\Root\View\Components\Copyable as CopyableComponent;
9+
10+
final class CopyableComponentTest extends TestCase
11+
{
12+
public function test_copyable_component_renders(): void
13+
{
14+
$component = new CopyableComponent('Display Text', 'Copy Value');
15+
16+
$view = $component->render();
17+
18+
$this->assertSame('root::components.copyable', $view->name());
19+
$this->assertSame('Display Text', $view->getData()['text']);
20+
$this->assertSame('Copy Value', $view->getData()['value']);
21+
}
22+
}

0 commit comments

Comments
 (0)