From 2d65568c8a85fbef9dc94a86ede6c0faaf13c141 Mon Sep 17 00:00:00 2001 From: Clement Date: Wed, 24 Apr 2024 18:40:07 +0530 Subject: [PATCH] unit tests --- tests/src/MultiDomainPanel.php | 63 ++++++++++++++++++++++++++++ tests/src/Panels/Routes/NoDomain.php | 40 ++++++++++++++++++ tests/src/SingleDomainPanel.php | 63 ++++++++++++++++++++++++++++ tests/src/TestCase.php | 2 + 4 files changed, 168 insertions(+) create mode 100644 tests/src/MultiDomainPanel.php create mode 100644 tests/src/Panels/Routes/NoDomain.php create mode 100644 tests/src/SingleDomainPanel.php diff --git a/tests/src/MultiDomainPanel.php b/tests/src/MultiDomainPanel.php new file mode 100644 index 0000000000..ae1fcca1ce --- /dev/null +++ b/tests/src/MultiDomainPanel.php @@ -0,0 +1,63 @@ +default() + ->id('multi-domain') + ->domains(['first.local', 'second.local']) + ->login() + ->registration() + ->passwordReset() + ->emailVerification() + ->resources([ + PostResource::class, + PostCategoryResource::class, + ProductResource::class, + UserResource::class, + ]) + ->pages([ + Pages\Dashboard::class, + Actions::class, + Settings::class, + ]) + ->middleware([ + EncryptCookies::class, + AddQueuedCookiesToResponse::class, + StartSession::class, + AuthenticateSession::class, + ShareErrorsFromSession::class, + VerifyCsrfToken::class, + SubstituteBindings::class, + DisableBladeIconComponents::class, + DispatchServingFilamentEvent::class, + ]) + ->authMiddleware([ + Authenticate::class, + ]); + } +} diff --git a/tests/src/Panels/Routes/NoDomain.php b/tests/src/Panels/Routes/NoDomain.php new file mode 100644 index 0000000000..27cd934b00 --- /dev/null +++ b/tests/src/Panels/Routes/NoDomain.php @@ -0,0 +1,40 @@ +getByName($routeName); + expect($route)->not->toBeEmpty(); +}); + +it('admin panel with single domain should resolve to default routes', function () { + $routeName = 'filament.single-domain.auth.login'; + $route = Route::getRoutes()->getByName($routeName); + expect($route)->not->toBeEmpty(); + + $routeName = 'filament.single-domain.single.local.auth.login'; + $route = Route::getRoutes()->getByName($routeName); + expect($route)->toBeEmpty(); +}); + +it('admin panel with multi domain should resolve to their respective routes', function () { + $routeName = 'filament.multi-domain.auth.login'; + $route = Route::getRoutes()->getByName($routeName); + expect($route)->toBeEmpty(); // this route should never exists + + $routeName = 'filament.multi-domain.first.local.auth.login'; + $route = Route::getRoutes()->getByName($routeName); + expect($route)->not->toBeEmpty(); // it should exists + + $routeName = 'filament.multi-domain.second.local.auth.login'; + $route = Route::getRoutes()->getByName($routeName); + expect($route)->not->toBeEmpty(); // it should exists +}); \ No newline at end of file diff --git a/tests/src/SingleDomainPanel.php b/tests/src/SingleDomainPanel.php new file mode 100644 index 0000000000..445f6ff701 --- /dev/null +++ b/tests/src/SingleDomainPanel.php @@ -0,0 +1,63 @@ +default() + ->id('single-domain') + ->domain('single.local') + ->login() + ->registration() + ->passwordReset() + ->emailVerification() + ->resources([ + PostResource::class, + PostCategoryResource::class, + ProductResource::class, + UserResource::class, + ]) + ->pages([ + Pages\Dashboard::class, + Actions::class, + Settings::class, + ]) + ->middleware([ + EncryptCookies::class, + AddQueuedCookiesToResponse::class, + StartSession::class, + AuthenticateSession::class, + ShareErrorsFromSession::class, + VerifyCsrfToken::class, + SubstituteBindings::class, + DisableBladeIconComponents::class, + DispatchServingFilamentEvent::class, + ]) + ->authMiddleware([ + Authenticate::class, + ]); + } +} diff --git a/tests/src/TestCase.php b/tests/src/TestCase.php index 8cefc56327..b44b9ff6e8 100644 --- a/tests/src/TestCase.php +++ b/tests/src/TestCase.php @@ -48,6 +48,8 @@ abstract class TestCase extends BaseTestCase SlugsPanelProvider::class, TenancyPanelProvider::class, DomainTenancyPanelProvider::class, + SingleDomainPanel::class, + MultiDomainPanel::class, ]; }