Skip to content

Commit da906d5

Browse files
committed
added history related props to tests
1 parent 7b473f4 commit da906d5

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

src/Testing/AssertableInertia.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class AssertableInertia extends AssertableJson
1919
/** @var string|null */
2020
private $version;
2121

22+
/** @var bool */
23+
private $encryptHistory;
24+
25+
/** @var bool */
26+
private $clearHistory;
27+
2228
public static function fromTestResponse(TestResponse $response): self
2329
{
2430
try {
@@ -40,6 +46,8 @@ public static function fromTestResponse(TestResponse $response): self
4046
$instance->component = $page['component'];
4147
$instance->url = $page['url'];
4248
$instance->version = $page['version'];
49+
$instance->encryptHistory = $page['encryptHistory'];
50+
$instance->clearHistory = $page['clearHistory'];
4351

4452
return $instance;
4553
}
@@ -80,6 +88,8 @@ public function toArray()
8088
'props' => $this->prop(),
8189
'url' => $this->url,
8290
'version' => $this->version,
91+
'encryptHistory' => $this->encryptHistory,
92+
'clearHistory' => $this->clearHistory,
8393
];
8494
}
8595
}

src/Testing/Concerns/PageObject.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public function toArray(): array
4949
'props' => $this->props,
5050
'url' => $this->url,
5151
'version' => $this->version,
52+
'encryptHistory' => $this->encryptHistory,
53+
'clearHistory' => $this->clearHistory,
5254
];
5355
}
5456
}

tests/ControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function test_controller_returns_an_inertia_response(): void
2828
],
2929
'url' => '/',
3030
'version' => '',
31-
'clearHistory' => false,
3231
'encryptHistory' => false,
32+
'clearHistory' => false,
3333
]);
3434
}
3535
}

tests/DirectiveTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DirectiveTest extends TestCase
3030
/**
3131
* Example Page Objects.
3232
*/
33-
protected const EXAMPLE_PAGE_OBJECT = ['component' => 'Foo/Bar', 'props' => ['foo' => 'bar'], 'url' => '/test', 'version' => ''];
33+
protected const EXAMPLE_PAGE_OBJECT = ['component' => 'Foo/Bar', 'props' => ['foo' => 'bar'], 'url' => '/test', 'version' => '', 'encryptHistory' => false, 'clearHistory' => false];
3434

3535
public function setUp(): void
3636
{
@@ -39,7 +39,7 @@ public function setUp(): void
3939
$this->app->bind(Gateway::class, FakeGateway::class);
4040
$this->filesystem = m::mock(Filesystem::class);
4141

42-
$this->compiler = new BladeCompiler($this->filesystem, __DIR__.'/cache/views');
42+
$this->compiler = new BladeCompiler($this->filesystem, __DIR__ . '/cache/views');
4343
$this->compiler->directive('inertia', [Directive::class, 'compile']);
4444
$this->compiler->directive('inertiaHead', [Directive::class, 'compileHead']);
4545
}
@@ -94,7 +94,7 @@ public function test_inertia_directive_renders_the_root_element(): void
9494
{
9595
Config::set(['inertia.ssr.enabled' => false]);
9696

97-
$html = '<div id="app" data-page="{&quot;component&quot;:&quot;Foo\/Bar&quot;,&quot;props&quot;:{&quot;foo&quot;:&quot;bar&quot;},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;&quot;}"></div>';
97+
$html = '<div id="app" data-page="{&quot;component&quot;:&quot;Foo\/Bar&quot;,&quot;props&quot;:{&quot;foo&quot;:&quot;bar&quot;},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;&quot;,&quot;encryptHistory&quot;:false,&quot;clearHistory&quot;:false}"></div>';
9898

9999
$this->assertSame($html, $this->renderView('@inertia', ['page' => self::EXAMPLE_PAGE_OBJECT]));
100100
$this->assertSame($html, $this->renderView('@inertia()', ['page' => self::EXAMPLE_PAGE_OBJECT]));
@@ -116,7 +116,7 @@ public function test_inertia_directive_can_use_a_different_root_element_id(): vo
116116
{
117117
Config::set(['inertia.ssr.enabled' => false]);
118118

119-
$html = '<div id="foo" data-page="{&quot;component&quot;:&quot;Foo\/Bar&quot;,&quot;props&quot;:{&quot;foo&quot;:&quot;bar&quot;},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;&quot;}"></div>';
119+
$html = '<div id="foo" data-page="{&quot;component&quot;:&quot;Foo\/Bar&quot;,&quot;props&quot;:{&quot;foo&quot;:&quot;bar&quot;},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;&quot;,&quot;encryptHistory&quot;:false,&quot;clearHistory&quot;:false}"></div>';
120120

121121
$this->assertSame($html, $this->renderView('@inertia(foo)', ['page' => self::EXAMPLE_PAGE_OBJECT]));
122122
$this->assertSame($html, $this->renderView("@inertia('foo')", ['page' => self::EXAMPLE_PAGE_OBJECT]));

tests/ResponseTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function test_server_response(): void
4646
$this->assertSame('Jonathan', $page['props']['user']['name']);
4747
$this->assertSame('/user/123', $page['url']);
4848
$this->assertSame('123', $page['version']);
49+
$this->assertFalse($page['clearHistory']);
50+
$this->assertFalse($page['encryptHistory']);
4951
$this->assertSame('<div id="app" data-page="{&quot;component&quot;:&quot;User\/Edit&quot;,&quot;props&quot;:{&quot;user&quot;:{&quot;name&quot;:&quot;Jonathan&quot;}},&quot;url&quot;:&quot;\/user\/123&quot;,&quot;version&quot;:&quot;123&quot;,&quot;clearHistory&quot;:false,&quot;encryptHistory&quot;:false}"></div>', $view->render());
5052
}
5153

tests/Testing/TestResponseMacrosTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function test_it_can_retrieve_the_inertia_page(): void
4646
$this->assertSame(['bar' => 'baz'], $page['props']);
4747
$this->assertSame('/example-url', $page['url']);
4848
$this->assertSame('', $page['version']);
49+
$this->assertFalse($page['encryptHistory']);
50+
$this->assertFalse($page['clearHistory']);
4951
});
5052
}
5153
}

0 commit comments

Comments
 (0)