From 9849eeebea673045231fca609f7c273e116a9970 Mon Sep 17 00:00:00 2001 From: KSneijders Date: Tue, 19 Nov 2024 14:24:52 +0100 Subject: [PATCH 1/2] Added test for translated notifications --- tests/src/LanguageSwitcherTest.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/src/LanguageSwitcherTest.php b/tests/src/LanguageSwitcherTest.php index 44efd0d..577f02c 100644 --- a/tests/src/LanguageSwitcherTest.php +++ b/tests/src/LanguageSwitcherTest.php @@ -1,8 +1,8 @@ toBeTrue(); }); + +it('sends a notification in the newly selected language', function (string $locale) { + $response = get(route('languages.switcher', [ + 'model' => get_class(auth('web')->user()), + 'model_id' => auth()->user()->id, + 'lang' => $locale, + ])); + + // Ensure the response status is OK (200) + $response->assertStatus(302); + + Notification::assertNotified( + Notification::make() + ->title(trans('filament-language-switcher::translation.notification', locale: $locale)) + ->icon('heroicon-o-check-circle') + ->iconColor('success') + ); +})->with(['locale' => ['en', 'nl', 'ar', 'de']]); From 714714292a58ff28e56c537d8eb29a3e745e7d74 Mon Sep 17 00:00:00 2001 From: KSneijders Date: Tue, 19 Nov 2024 14:25:11 +0100 Subject: [PATCH 2/2] Added logic to LanguageController to show notification in the new language --- src/Http/Controllers/LanguageController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/Controllers/LanguageController.php b/src/Http/Controllers/LanguageController.php index 1f1ec58..18c484b 100644 --- a/src/Http/Controllers/LanguageController.php +++ b/src/Http/Controllers/LanguageController.php @@ -41,7 +41,7 @@ public function index(Request $request): RedirectResponse } Notification::make() - ->title(trans('filament-language-switcher::translation.notification')) + ->title(trans('filament-language-switcher::translation.notification', locale: $request->get('lang'))) ->icon('heroicon-o-check-circle') ->iconColor('success') ->send();