Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel Dusk fix #465

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/Http/Controllers/EnableEmailOptinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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', '/'));
}
Expand Down
11 changes: 7 additions & 4 deletions resources/views/components/email-optin-banner.blade.php
Original file line number Diff line number Diff line change
@@ -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

<x-success-message class="mb-10">
Stay updated! Get an email whenever a new RFC is added.
{{ EnableEmailOptinController::STAY_UPDATED_MESSAGE }}

<a href="{{ $url }}" class="font-bold text-font-second hover:text-font underline">
Enable notifications
{{ EnableEmailOptinController::BUTTON_MESSAGE }}
</a>
</x-success-message>
@endif
3 changes: 2 additions & 1 deletion tests/Browser/HomePageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Browser;

use App\Http\Controllers\EnableEmailOptinController;
use App\Models\Argument;
use App\Models\ArgumentVote;
use App\Models\Rfc;
Expand Down Expand Up @@ -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);
});
}

Expand Down
5 changes: 3 additions & 2 deletions tests/Browser/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}

Expand Down