Skip to content

Commit 2ce5df9

Browse files
chore: test component renders correctly
1 parent c1fb5f1 commit 2ce5df9

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/Integration/ViewTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NeoIsRecursive\Inertia\Tests\Integration;
6+
7+
use NeoIsRecursive\Inertia\Tests\TestCase;
8+
use NeoIsRecursive\Inertia\Views\InertiaBaseView;
9+
10+
final class ViewTest extends TestCase
11+
{
12+
public function test_inertia_component_renders_correctly(): void
13+
{
14+
$output = $this->render(<<<HTML
15+
<x-inertia :page="new \NeoIsRecursive\Inertia\PageData('TestComponent', ['key' => 'value'], '/test-url', '1.0.0', false, false)" id="app" />
16+
HTML);
17+
18+
static::assertSnippetsMatch(
19+
expected: '<div id="app" data-page="{&quot;component&quot;:&quot;TestComponent&quot;,&quot;props&quot;:{&quot;key&quot;:&quot;value&quot;},&quot;url&quot;:&quot;\/test-url&quot;,&quot;version&quot;:&quot;1.0.0&quot;,&quot;clearHistory&quot;:false,&quot;encryptHistory&quot;:false}"></div>',
20+
actual: $output,
21+
);
22+
}
23+
24+
public function test_inertia_page_can_render_compnent(): void
25+
{
26+
$output = $this->render(new InertiaBaseView(
27+
<<<HTML
28+
<x-inertia />
29+
HTML,
30+
new \NeoIsRecursive\Inertia\PageData(
31+
component: 'TestComponent',
32+
props: ['key' => 'value'],
33+
url: '/test-url',
34+
version: '1.0.0',
35+
clearHistory: false,
36+
encryptHistory: false,
37+
),
38+
));
39+
40+
static::assertSnippetsMatch(
41+
expected: '<div id="app" data-page="{&quot;component&quot;:&quot;TestComponent&quot;,&quot;props&quot;:{&quot;key&quot;:&quot;value&quot;},&quot;url&quot;:&quot;\/test-url&quot;,&quot;version&quot;:&quot;1.0.0&quot;,&quot;clearHistory&quot;:false,&quot;encryptHistory&quot;:false}"></div>',
42+
actual: $output,
43+
);
44+
}
45+
46+
public function test_renders_id_attribute_correctly(): void
47+
{
48+
$output = $this->render(<<<HTML
49+
<x-inertia id="custom-id" :page="new \NeoIsRecursive\Inertia\PageData('TestComponent', ['key' => 'value'], '/test-url', '1.0.0', false, false)" />
50+
HTML);
51+
52+
static::assertSnippetsMatch(
53+
expected: '<div id="custom-id" data-page="{&quot;component&quot;:&quot;TestComponent&quot;,&quot;props&quot;:{&quot;key&quot;:&quot;value&quot;},&quot;url&quot;:&quot;\/test-url&quot;,&quot;version&quot;:&quot;1.0.0&quot;,&quot;clearHistory&quot;:false,&quot;encryptHistory&quot;:false}"></div>',
54+
actual: $output,
55+
);
56+
}
57+
}

0 commit comments

Comments
 (0)