diff --git a/app/Http/Controllers/EnableEmailOptinController.php b/app/Http/Controllers/EnableEmailOptinController.php index 5f205604..e23464d6 100644 --- a/app/Http/Controllers/EnableEmailOptinController.php +++ b/app/Http/Controllers/EnableEmailOptinController.php @@ -7,6 +7,13 @@ final readonly class EnableEmailOptinController { + public const string STAY_UPDATED_MESSAGE = 'Stay updated! Get an email whenever a new RFC is added.'; + + public const string BUTTON_MESSAGE = 'Enable notifications'; + + public const string ENABLED_MESSAGE = 'Your email preferences were updated! + You can change them at any time in your Settings.'; + public function __invoke(Request $request): RedirectResponse { $user = $request->user(); @@ -17,10 +24,7 @@ public function __invoke(Request $request): RedirectResponse $user->update(['email_optin' => true]); - flash(<<<'HTML' - Your email preferences were updated! - You can change them at any time in your Settings. - HTML); + flash(self::ENABLED_MESSAGE); return redirect()->to($request->get('back', '/')); } diff --git a/resources/views/components/email-optin-banner.blade.php b/resources/views/components/email-optin-banner.blade.php index 8798843d..fa4c9cab 100644 --- a/resources/views/components/email-optin-banner.blade.php +++ b/resources/views/components/email-optin-banner.blade.php @@ -1,15 +1,18 @@ +@use('App\Http\Controllers\EnableEmailOptinController') +@use('App\Http\Controllers\LoginController') + @if(! $user?->email_optin) @php $url = $user - ? action(App\Http\Controllers\EnableEmailOptinController::class, ['back' => request()->url()]) - : action(App\Http\Controllers\LoginController::class) + ? action(EnableEmailOptinController::class, ['back' => request()->url()]) + : action(LoginController::class) @endphp - Stay updated! Get an email whenever a new RFC is added. + {{ EnableEmailOptinController::STAY_UPDATED_MESSAGE }} - Enable notifications + {{ EnableEmailOptinController::BUTTON_MESSAGE }} @endif diff --git a/tests/Browser/HomePageTest.php b/tests/Browser/HomePageTest.php index df524458..540406ef 100644 --- a/tests/Browser/HomePageTest.php +++ b/tests/Browser/HomePageTest.php @@ -2,6 +2,7 @@ namespace Tests\Browser; +use App\Http\Controllers\EnableEmailOptinController; use App\Models\Argument; use App\Models\ArgumentVote; use App\Models\Rfc; @@ -64,7 +65,7 @@ public function test_it_renders_email_notification_disclaimer_for_auth_users_tha ->assertPresent('@disclaimer') ->click('@disclaimer a') ->assertPathIs('/') - ->assertNotPresent('@disclaimer'); + ->assertSee(EnableEmailOptinController::ENABLED_MESSAGE); }); } diff --git a/tests/Browser/RegistrationTest.php b/tests/Browser/RegistrationTest.php index a9f6049c..384b16fb 100644 --- a/tests/Browser/RegistrationTest.php +++ b/tests/Browser/RegistrationTest.php @@ -2,6 +2,7 @@ namespace Tests\Browser; +use App\Http\Controllers\EnableEmailOptinController; use App\Models\User; use Illuminate\Foundation\Testing\DatabaseTruncation; use Laravel\Dusk\Browser; @@ -51,8 +52,8 @@ public function test_it_displays_information_about_email_notifications_to_newly_ confirmPassword: 'password', )->assertPathIs('/') ->assertAuthenticated() - ->assertSee('Stay updated! Get an email whenever a new RFC is added.') - ->assertSeeLink('Enable it here'); + ->assertSee(EnableEmailOptinController::STAY_UPDATED_MESSAGE) + ->assertSeeLink(EnableEmailOptinController::BUTTON_MESSAGE); }); }