user pagination

This commit is contained in:
Saufi
2026-05-11 12:20:39 +08:00
parent a461f0bb42
commit 3e79e74cb7
5 changed files with 95 additions and 35 deletions

View File

@@ -15,11 +15,33 @@ test('authenticated users can view the users page', function () {
->assertViewIs('users.index');
});
test('users page lists all users', function () {
$users = User::factory()->count(3)->create();
test('users page passes paginated users to view', function () {
$user = User::factory()->create();
$this->actingAs($users->first())
$this->actingAs($user)
->get('/users')
->assertOk()
->assertViewHas('users', fn ($viewUsers) => $viewUsers->count() === User::count());
->assertViewHas('users');
});
test('ajax request returns table partial', function () {
$user = User::factory()->create();
$this->actingAs($user)
->withHeader('X-Requested-With', 'XMLHttpRequest')
->get('/users')
->assertOk()
->assertViewIs('users._table');
});
test('ajax pagination returns correct page', function () {
$user = User::factory()->create();
User::factory()->count(15)->create();
$this->actingAs($user)
->withHeader('X-Requested-With', 'XMLHttpRequest')
->get('/users?page=2')
->assertOk()
->assertViewIs('users._table')
->assertViewHas('users', fn ($users) => $users->currentPage() === 2);
});