- Load stored users without re-checking role rules, so an intern whose supervisor was deleted no longer gets a 500 on every request; the rules apply again on the next change. - Refuse to deactivate or demote a supervisor of active interns (SupervisorHasInterns). - Lock active admin rows in the last-admin check so concurrent changes cannot remove every admin. - Creating a user survives mail failures: the error is reported and the admin is asked to resend the link (CreatedUserAccount result). - Session-ended redirect passes the reason in the URL (/login?access=ended), so Livewire requests also show it. - Same login message for a wrong password and a disabled account. - Forgot-password sends links only to users who may sign in today (RequestPasswordReset), with the same neutral message. - Use the default callout instead of the low-contrast warning variant. - Document make:class/make:test for module files in CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
97 lines
3.5 KiB
PHP
97 lines
3.5 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Pest\Browser\Api\AwaitableWebpage;
|
|
use Pest\Browser\Api\PendingAwaitablePage;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
$devicesAndSchemes = [
|
|
'desktop, light' => ['desktop', 'light'],
|
|
'desktop, dark' => ['desktop', 'dark'],
|
|
'mobile, light' => ['mobile', 'light'],
|
|
'mobile, dark' => ['mobile', 'dark'],
|
|
];
|
|
|
|
/**
|
|
* @param PendingAwaitablePage|AwaitableWebpage $page
|
|
*/
|
|
function onDeviceAndScheme(mixed $page, string $device, string $colorScheme): mixed
|
|
{
|
|
$page = $device === 'mobile' ? $page->on()->mobile() : $page->on()->desktop();
|
|
|
|
return $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
|
|
}
|
|
|
|
it('has no accessibility issues on the guest pages', function (string $routeName, string $device, string $colorScheme) {
|
|
$url = $routeName === 'password.reset'
|
|
? route($routeName, ['token' => 'token', 'email' => '[email protected]'])
|
|
: route($routeName);
|
|
|
|
onDeviceAndScheme(visit($url), $device, $colorScheme)
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
})->with([
|
|
'login' => 'login',
|
|
'forgot password' => 'password.request',
|
|
'reset password' => 'password.reset',
|
|
])->with($devicesAndSchemes);
|
|
|
|
it('has no accessibility issues on the user admin pages', function (string $page, string $device, string $colorScheme) {
|
|
$admin = User::factory()->admin()->create();
|
|
$intern = User::factory()->intern('2027-05-31')->create();
|
|
$this->actingAs($admin);
|
|
|
|
$url = match ($page) {
|
|
'list' => route('users.index'),
|
|
'create' => route('users.create'),
|
|
'edit intern' => route('users.edit', $intern->id),
|
|
};
|
|
|
|
onDeviceAndScheme(visit($url), $device, $colorScheme)
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
})->with(['list', 'create', 'edit intern'])->with($devicesAndSchemes);
|
|
|
|
it('shows a login error without accessibility issues', function (string $colorScheme) {
|
|
$page = onDeviceAndScheme(visit(route('login')), 'desktop', $colorScheme);
|
|
|
|
$page->fill('[wire\\:model="email"]', '[email protected]')
|
|
->fill('[wire\\:model="password"]', 'väärä-salasana')
|
|
->press('Kirjaudu')
|
|
->assertSee('Kirjautuminen ei onnistunut.')
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
})->with(['light', 'dark']);
|
|
|
|
it('sends a user who is deactivated mid-session to the login page with the reason', function () {
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
// visit() is lazy: load the form before the account is deactivated.
|
|
$page = visit(route('customers.create'))->assertSee('Uusi asiakas');
|
|
|
|
$user->update(['is_active' => false]);
|
|
|
|
$page->fill('[wire\\:model="form.name"]', 'Mainos Oy')
|
|
->press('Tallenna')
|
|
->assertPathIs('/login')
|
|
->assertSee('Käyttöoikeutesi on päättynyt. Ota yhteyttä pääkäyttäjään.')
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
});
|
|
|
|
it('logs in with the keyboard alone', function () {
|
|
User::factory()->create(['email' => '[email protected]']);
|
|
|
|
visit(route('login'))
|
|
->keys('html > body', 'Tab')
|
|
->keys('a[href="#main-content"]', 'Enter')
|
|
->keys('#main-content', 'Tab')
|
|
->assertScript('document.activeElement.getAttribute("wire:model")', 'email')
|
|
->type('[wire\\:model="email"]', '[email protected]')
|
|
->type('[wire\\:model="password"]', 'password')
|
|
->keys('[wire\\:model="password"]', 'Enter')
|
|
->assertPathIs('/')
|
|
->assertSee('Kirjaudu ulos');
|
|
});
|