Skip to content

Commit

Permalink
added history related props to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joetannenbaum committed Oct 3, 2024
1 parent 7b473f4 commit da906d5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/Testing/AssertableInertia.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class AssertableInertia extends AssertableJson
/** @var string|null */
private $version;

/** @var bool */
private $encryptHistory;

/** @var bool */
private $clearHistory;

public static function fromTestResponse(TestResponse $response): self
{
try {
Expand All @@ -40,6 +46,8 @@ public static function fromTestResponse(TestResponse $response): self
$instance->component = $page['component'];
$instance->url = $page['url'];
$instance->version = $page['version'];
$instance->encryptHistory = $page['encryptHistory'];
$instance->clearHistory = $page['clearHistory'];

return $instance;
}
Expand Down Expand Up @@ -80,6 +88,8 @@ public function toArray()
'props' => $this->prop(),
'url' => $this->url,
'version' => $this->version,
'encryptHistory' => $this->encryptHistory,
'clearHistory' => $this->clearHistory,
];
}
}
2 changes: 2 additions & 0 deletions src/Testing/Concerns/PageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function toArray(): array
'props' => $this->props,
'url' => $this->url,
'version' => $this->version,
'encryptHistory' => $this->encryptHistory,
'clearHistory' => $this->clearHistory,
];
}
}
2 changes: 1 addition & 1 deletion tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function test_controller_returns_an_inertia_response(): void
],
'url' => '/',
'version' => '',
'clearHistory' => false,
'encryptHistory' => false,
'clearHistory' => false,
]);
}
}
8 changes: 4 additions & 4 deletions tests/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DirectiveTest extends TestCase
/**
* Example Page Objects.
*/
protected const EXAMPLE_PAGE_OBJECT = ['component' => 'Foo/Bar', 'props' => ['foo' => 'bar'], 'url' => '/test', 'version' => ''];
protected const EXAMPLE_PAGE_OBJECT = ['component' => 'Foo/Bar', 'props' => ['foo' => 'bar'], 'url' => '/test', 'version' => '', 'encryptHistory' => false, 'clearHistory' => false];

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

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

$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>';
$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>';

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

$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>';
$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>';

$this->assertSame($html, $this->renderView('@inertia(foo)', ['page' => self::EXAMPLE_PAGE_OBJECT]));
$this->assertSame($html, $this->renderView("@inertia('foo')", ['page' => self::EXAMPLE_PAGE_OBJECT]));
Expand Down
2 changes: 2 additions & 0 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function test_server_response(): void
$this->assertSame('Jonathan', $page['props']['user']['name']);
$this->assertSame('/user/123', $page['url']);
$this->assertSame('123', $page['version']);
$this->assertFalse($page['clearHistory']);
$this->assertFalse($page['encryptHistory']);
$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());
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Testing/TestResponseMacrosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function test_it_can_retrieve_the_inertia_page(): void
$this->assertSame(['bar' => 'baz'], $page['props']);
$this->assertSame('/example-url', $page['url']);
$this->assertSame('', $page['version']);
$this->assertFalse($page['encryptHistory']);
$this->assertFalse($page['clearHistory']);
});
}
}

0 comments on commit da906d5

Please sign in to comment.