|
| 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="{"component":"TestComponent","props":{"key":"value"},"url":"\/test-url","version":"1.0.0","clearHistory":false,"encryptHistory":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="{"component":"TestComponent","props":{"key":"value"},"url":"\/test-url","version":"1.0.0","clearHistory":false,"encryptHistory":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="{"component":"TestComponent","props":{"key":"value"},"url":"\/test-url","version":"1.0.0","clearHistory":false,"encryptHistory":false}"></div>', |
| 54 | + actual: $output, |
| 55 | + ); |
| 56 | + } |
| 57 | +} |
0 commit comments