Skip to content

Commit 7f1dece

Browse files
Adds test for inertia redirects.
1 parent 48e3135 commit 7f1dece

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/Http/Middleware/AddAlertsToInertiaTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tests\Http\Middleware;
44

5+
use Illuminate\Contracts\Http\Kernel;
56
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
67
use Inertia\Inertia;
78
use Inertia\Middleware;
@@ -90,4 +91,28 @@ function () {
9091
->where('_alerts', []);
9192
});
9293
}
94+
95+
public function test_adds_alerts_to_inertia_after_redirection(): void
96+
{
97+
$router = $this->app->make('router');
98+
99+
$router->get('redirect', function () {
100+
alert('test-alert');
101+
102+
return redirect()->to('/test');
103+
})->middleware(['web', Middleware::class, 'alerts.inertia']);
104+
105+
$router->get('test', fn () => Inertia::render('test', ['foo' => 'bar']))
106+
->middleware(['web', Middleware::class, 'alerts.inertia']);
107+
108+
$this->followingRedirects()
109+
->get('redirect')
110+
->assertInertia(static function (AssertableInertia $page): void {
111+
$page->component('test')
112+
->where('foo', 'bar')
113+
->where('_alerts', [
114+
['dismissible' => false, 'message' => 'test-alert', 'metadata' => [], 'types' => []]
115+
]);
116+
});
117+
}
93118
}

0 commit comments

Comments
 (0)