42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
use App\Models\Role;
|
|
use App\Models\User;
|
|
|
|
test('guests are redirected to login from roles page', function () {
|
|
$this->get('/roles')->assertRedirect('/login');
|
|
});
|
|
|
|
test('authenticated users can view the roles page', function () {
|
|
$this->actingAs(User::factory()->create())
|
|
->get('/roles')
|
|
->assertOk()
|
|
->assertViewIs('roles.index');
|
|
});
|
|
|
|
test('roles page passes paginated roles to view', function () {
|
|
$this->actingAs(User::factory()->create())
|
|
->get('/roles')
|
|
->assertOk()
|
|
->assertViewHas('roles');
|
|
});
|
|
|
|
test('ajax request returns roles table partial', function () {
|
|
$this->actingAs(User::factory()->create())
|
|
->withHeader('X-Requested-With', 'XMLHttpRequest')
|
|
->get('/roles')
|
|
->assertOk()
|
|
->assertViewIs('roles._table');
|
|
});
|
|
|
|
test('ajax pagination returns correct page', function () {
|
|
Role::factory()->count(15)->create();
|
|
|
|
$this->actingAs(User::factory()->create())
|
|
->withHeader('X-Requested-With', 'XMLHttpRequest')
|
|
->get('/roles?page=2')
|
|
->assertOk()
|
|
->assertViewIs('roles._table')
|
|
->assertViewHas('roles', fn ($roles) => $roles->currentPage() === 2);
|
|
});
|