Files
ppeasy_vg12/tests/Browser/RolesTest.php
T
2026-10-09 08:21:06 +02:00

62 lines
1.7 KiB
PHP

<?php
use App\Models\Role;
beforeEach(function () {
$this->artisan('db:seed');
});
it('lists the seeded roles', function () {
browserLogin();
visit('/roles')
->assertNoJavaScriptErrors()
->assertSee('Roles')
->assertSee('Display Name')
->assertSee('# of users with this role')
->assertSee('Admin')
->assertSee('User');
});
it('creates a role', function () {
browserLogin();
visit('/roles/create')
->assertSee('Create New Role')
->assertSee('Role Details')
->fill('#name', 'Editor')
->fill('#display_name', 'Content Editor')
->fill('#description', 'Edits the content.')
->click('Create Role')
->assertSee('Role created successfully.');
expect(Role::where('name', 'Editor')->exists())->toBeTrue();
});
it('edits a role', function () {
browserLogin();
$role = Role::factory()->create(['name' => 'Reviewer', 'display_name' => 'Reviewer']);
visit("/roles/{$role->id}/edit")
->assertSee('Role Details')
->fill('#display_name', 'Peer Reviewer')
->click('Update Role')
->assertSee('Role updated successfully.');
expect($role->fresh()->display_name)->toBe('Peer Reviewer');
});
it('asks for confirmation before deleting a role', function () {
browserLogin();
Role::factory()->create(['name' => 'Temporary', 'display_name' => 'Temporary']);
// Only removable roles render the delete control, so the seeded roles do
// not add a second match for this locator.
visit('/roles')
->assertSee('Temporary')
->click('[aria-label="Delete Role"]')
->assertSee('Are you sure that you want to delete this role?');
});