Files
mytodos/tests/Feature/AdminNotesLimitsTest.php
T

176 lines
5.4 KiB
PHP
Raw Normal View History

2026-09-17 23:01:26 -07:00
<?php
2026-10-15 20:59:32 -07:00
use App\Models\Organization;
2026-09-17 23:01:26 -07:00
use App\Models\User;
2026-10-15 20:59:32 -07:00
use App\OrganizationRole;
2026-09-17 23:01:26 -07:00
use Livewire\Livewire;
test('guests are redirected from the notes limits page', function () {
$this->get(route('admin.notes-limits'))
->assertRedirect(route('login'));
});
test('non-admins cannot access the notes limits page', function () {
$user = User::factory()->create();
$this->actingAs($user);
$this->get(route('admin.notes-limits'))->assertForbidden();
});
2026-10-15 20:59:32 -07:00
test('workspace admins are not site admins and cannot access the notes limits page', function () {
$workspaceAdmin = User::factory()->create();
$organization = Organization::factory()->family()
->withMember($workspaceAdmin, OrganizationRole::Admin)
->create();
$this->actingAs($workspaceAdmin);
expect($organization->userHasRole($workspaceAdmin, OrganizationRole::Admin))->toBeTrue();
$this->get(route('admin.notes-limits'))->assertForbidden();
});
test('a non-admin cannot save a notes limit through a direct action call', function () {
$admin = User::factory()->asAdmin()->create();
$this->actingAs($admin);
$member = User::factory()->create();
$component = Livewire::test('pages::admin.notes-limits')->call('startEditLimit', $member->id);
$this->actingAs($member);
$component->set('notesLimitInput', '2500')->call('saveNotesLimit')->assertForbidden();
expect($member->fresh()->notesLimit())->toBe(1000);
2026-10-15 20:59:32 -07:00
});
2026-09-17 23:01:26 -07:00
test('non-admins do not see the notes limits navigation item', function () {
$user = User::factory()->create();
$this->actingAs($user);
$this->get(route('dashboard'))
->assertOk()
->assertDontSee('Notes limits');
});
test('admins see the notes limits navigation item', function () {
$user = User::factory()->asAdmin()->create();
$this->actingAs($user);
$this->get(route('dashboard'))
->assertOk()
->assertSee('Notes limits');
});
2026-10-15 20:59:32 -07:00
test('site admins see the site admin navigation group', function () {
$user = User::factory()->asAdmin()->create();
$this->actingAs($user);
$this->get(route('dashboard'))
->assertOk()
->assertSee('Site admin');
});
test('workspace admins do not see the site admin navigation group', function () {
$workspaceAdmin = User::factory()->create();
Organization::factory()->family()
->withMember($workspaceAdmin, OrganizationRole::Admin)
->create();
$this->actingAs($workspaceAdmin);
$this->get(route('dashboard'))
->assertOk()
->assertDontSee('Site admin');
});
test('the notes limits page identifies site administrators', function () {
$admin = User::factory()->asAdmin()->create();
$this->actingAs($admin);
Livewire::test('pages::admin.notes-limits')
->assertSee('Site admin');
});
2026-09-17 23:01:26 -07:00
test('admins can view the notes limits page', function () {
$user = User::factory()->asAdmin()->create();
$this->actingAs($user);
$this->get(route('admin.notes-limits'))->assertOk();
});
test('admins can update a user notes limit', function () {
$admin = User::factory()->asAdmin()->create();
$this->actingAs($admin);
$member = User::factory()->create(['name' => 'Member One']);
Livewire::test('pages::admin.notes-limits')
->call('startEditLimit', $member->id)
->assertSet('notesLimitInput', '1000')
->set('notesLimitInput', '2500')
->call('saveNotesLimit')
->assertSet('showLimitForm', false);
expect($member->fresh()->notes_limit)->toBe(2500);
});
test('a notes limit must be a valid positive number', function () {
$admin = User::factory()->asAdmin()->create();
$this->actingAs($admin);
$member = User::factory()->create(['name' => 'Member One']);
Livewire::test('pages::admin.notes-limits')
->call('startEditLimit', $member->id)
->set('notesLimitInput', '0')
->call('saveNotesLimit')
->assertHasErrors('notesLimitInput');
expect($member->fresh()->notesLimit())->toBe(1000);
2026-09-17 23:01:26 -07:00
});
2026-10-15 20:59:32 -07:00
test('admins can search users by name or email', function () {
$admin = User::factory()->asAdmin()->create();
$this->actingAs($admin);
$match = User::factory()->create(['name' => 'Ada Lovelace', 'email' => 'ada@example.com']);
$emailMatch = User::factory()->create(['name' => 'Grace Hopper', 'email' => 'grace@searchable.test']);
$other = User::factory()->create(['name' => 'Alan Turing', 'email' => 'alan@example.com']);
Livewire::test('pages::admin.notes-limits')
->set('search', 'lovelace')
->assertSee('Ada Lovelace')
->assertDontSee('Alan Turing')
->set('search', 'searchable.test')
->assertSee('Grace Hopper')
->assertDontSee($match->name)
->assertDontSee($other->name);
});
test('searching resets the page', function () {
$admin = User::factory()->asAdmin()->create();
$this->actingAs($admin);
User::factory()->count(11)->create();
Livewire::test('pages::admin.notes-limits')
->call('gotoPage', 2)
->assertSet('paginators.page', 2)
->set('search', 'anything')
->assertSet('paginators.page', 1);
});
test('the notes limits list is paginated', function () {
$admin = User::factory()->asAdmin()->create();
$this->actingAs($admin);
User::factory()->count(12)->create();
$component = Livewire::test('pages::admin.notes-limits');
expect($component->instance()->users->perPage())->toBe(10)
->and($component->instance()->users->total())->toBe(13);
});