Files
mytodos/tests/Feature/AdminNotesLimitsTest.php
T

73 lines
2.1 KiB
PHP
Raw Normal View History

2026-09-17 23:01:26 -07:00
<?php
use App\Models\User;
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();
});
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');
});
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()->notes_limit)->toBe(1000);
});