@@ -0,0 +1,72 @@
|
||||
<?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);
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
test('login screen can be rendered', function () {
|
||||
$response = $this->get(route('login'));
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('users can authenticate using the login screen', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('dashboard', absolute: false));
|
||||
|
||||
$this->assertAuthenticated();
|
||||
});
|
||||
|
||||
test('users can not authenticate with invalid password', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrorsIn('email');
|
||||
|
||||
$this->assertGuest();
|
||||
});
|
||||
|
||||
test('users with two factor enabled are redirected to two factor challenge', function () {
|
||||
$this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
|
||||
|
||||
Features::twoFactorAuthentication([
|
||||
'confirm' => true,
|
||||
'confirmPassword' => true,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withTwoFactor()->create();
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('two-factor.login'));
|
||||
$this->assertGuest();
|
||||
});
|
||||
|
||||
test('users can logout', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('logout'));
|
||||
|
||||
$response->assertRedirect(route('home'));
|
||||
|
||||
$this->assertGuest();
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->skipUnlessFortifyHas(Features::emailVerification());
|
||||
});
|
||||
|
||||
test('email verification screen can be rendered', function () {
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('verification.notice'));
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('email can be verified', function () {
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
Event::fake();
|
||||
|
||||
$verificationUrl = URL::temporarySignedRoute(
|
||||
'verification.verify',
|
||||
now()->addMinutes(60),
|
||||
['id' => $user->id, 'hash' => sha1($user->email)],
|
||||
);
|
||||
|
||||
$response = $this->actingAs($user)->get($verificationUrl);
|
||||
|
||||
Event::assertDispatched(Verified::class);
|
||||
|
||||
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
|
||||
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
|
||||
});
|
||||
|
||||
test('email is not verified with invalid hash', function () {
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
$verificationUrl = URL::temporarySignedRoute(
|
||||
'verification.verify',
|
||||
now()->addMinutes(60),
|
||||
['id' => $user->id, 'hash' => sha1('wrong-email')],
|
||||
);
|
||||
|
||||
$this->actingAs($user)->get($verificationUrl);
|
||||
|
||||
expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
|
||||
});
|
||||
|
||||
test('already verified user visiting verification link is redirected without firing event again', function () {
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
|
||||
Event::fake();
|
||||
|
||||
$verificationUrl = URL::temporarySignedRoute(
|
||||
'verification.verify',
|
||||
now()->addMinutes(60),
|
||||
['id' => $user->id, 'hash' => sha1($user->email)],
|
||||
);
|
||||
|
||||
$this->actingAs($user)->get($verificationUrl)
|
||||
->assertRedirect(route('dashboard', absolute: false).'?verified=1');
|
||||
|
||||
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
|
||||
Event::assertNotDispatched(Verified::class);
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
test('confirm password screen can be rendered', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route('password.confirm'));
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->skipUnlessFortifyHas(Features::resetPasswords());
|
||||
});
|
||||
|
||||
test('reset password link screen can be rendered', function () {
|
||||
$response = $this->get(route('password.request'));
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('reset password link can be requested', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post(route('password.request'), ['email' => $user->email]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class);
|
||||
});
|
||||
|
||||
test('reset password screen can be rendered', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post(route('password.request'), ['email' => $user->email]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
|
||||
$response = $this->get(route('password.reset', $notification->token));
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
test('password can be reset with valid token', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post(route('password.request'), ['email' => $user->email]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
|
||||
$response = $this->post(route('password.update'), [
|
||||
'token' => $notification->token,
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('login', absolute: false));
|
||||
|
||||
return true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->skipUnlessFortifyHas(Features::registration());
|
||||
});
|
||||
|
||||
test('registration screen can be rendered', function () {
|
||||
$response = $this->get(route('register'));
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('new users can register', function () {
|
||||
$response = $this->post(route('register.store'), [
|
||||
'name' => 'John Doe',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('dashboard', absolute: false));
|
||||
|
||||
$this->assertAuthenticated();
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
|
||||
});
|
||||
|
||||
test('two factor challenge redirects to login when not authenticated', function () {
|
||||
$response = $this->get(route('two-factor.login'));
|
||||
|
||||
$response->assertRedirect(route('login'));
|
||||
});
|
||||
|
||||
test('two factor challenge can be rendered', function () {
|
||||
Features::twoFactorAuthentication([
|
||||
'confirm' => true,
|
||||
'confirmPassword' => true,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withTwoFactor()->create();
|
||||
|
||||
$this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
])->assertRedirect(route('two-factor.login'));
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Seeders\BaseDatabaseSeeder;
|
||||
|
||||
use function Pest\Laravel\seed;
|
||||
|
||||
test('base data includes a default admin user', function () {
|
||||
seed(BaseDatabaseSeeder::class);
|
||||
|
||||
$admin = User::where('email', 'admin@example.com')->first();
|
||||
|
||||
expect($admin)->not->toBeNull()
|
||||
->and($admin->name)->toBe('Administrator')
|
||||
->and($admin->notes_limit)->toBe(1000);
|
||||
$this->assertTrue($admin->isAdmin());
|
||||
});
|
||||
|
||||
test('base data seeding is idempotent', function () {
|
||||
seed(BaseDatabaseSeeder::class);
|
||||
seed(BaseDatabaseSeeder::class);
|
||||
|
||||
expect(User::where('email', 'admin@example.com')->count())->toBe(1);
|
||||
});
|
||||
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Folder;
|
||||
use App\Models\Todo;
|
||||
use App\Models\User;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('guests are redirected to the login page', function () {
|
||||
$response = $this->get(route('dashboard'));
|
||||
$response->assertRedirect(route('login'));
|
||||
});
|
||||
|
||||
test('authenticated users can visit the dashboard', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->get(route('dashboard'));
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('dashboard shows open, overdue, due-today and completed counts', function () {
|
||||
$this->travelTo('2026-09-18 09:00:00');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Open future', 'due_date' => today()->addDays(3)]);
|
||||
Todo::factory()->recycle($user)->for($folder)->overdue()->create();
|
||||
Todo::factory()->recycle($user)->for($folder)->dueToday()->create();
|
||||
Todo::factory()->recycle($user)->for($folder)->completed()->create();
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->assertSet('todoCounts.open', 3)
|
||||
->assertSet('todoCounts.overdue', 1)
|
||||
->assertSet('todoCounts.dueToday', 1)
|
||||
->assertSet('todoCounts.completed', 1);
|
||||
});
|
||||
|
||||
test('todo list filters by status', function () {
|
||||
$this->travelTo('2026-09-18 09:00:00');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$personal = Folder::factory()->for($user)->create(['name' => 'Personal']);
|
||||
|
||||
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Review design', 'due_date' => today()->addDays(5)]);
|
||||
Todo::factory()->recycle($user)->for($personal)->overdue()->create(['description' => 'Pay invoice']);
|
||||
Todo::factory()->recycle($user)->for($personal)->completed()->create(['description' => 'Buy milk']);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->set('status', 'overdue')
|
||||
->assertDontSee('Review design')
|
||||
->assertSee('Pay invoice')
|
||||
->assertDontSee('Buy milk');
|
||||
});
|
||||
|
||||
test('todo list filters by search', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Review design', 'due_date' => today()->addDays(5)]);
|
||||
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Review proposal', 'due_date' => today()->addDays(4)]);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->set('search', 'proposal')
|
||||
->assertDontSee('Review design')
|
||||
->assertSee('Review proposal');
|
||||
});
|
||||
|
||||
test('filtering by a top-level folder includes its sub-folders', function () {
|
||||
$this->travelTo('2026-09-18 09:00:00');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$acme = Folder::factory()->childOf($work)->create(['name' => 'Acme Corp']);
|
||||
|
||||
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Standup notes', 'due_date' => today()->addDays(2)]);
|
||||
Todo::factory()->recycle($user)->for($acme)->create(['description' => 'Q3 roadmap', 'due_date' => today()->addDays(3)]);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->set('folderId', $work->id)
|
||||
->assertSee('Standup notes')
|
||||
->assertSee('Q3 roadmap');
|
||||
});
|
||||
|
||||
test('users can create a todo from the dashboard', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openCreateForm')
|
||||
->set('description', 'Write proposal')
|
||||
->set('dueDate', '2026-09-25')
|
||||
->set('formFolderId', $folder->id)
|
||||
->call('saveTodo')
|
||||
->assertSet('showTodoForm', false);
|
||||
|
||||
$this->assertDatabaseHas('todos', [
|
||||
'user_id' => $user->id,
|
||||
'folder_id' => $folder->id,
|
||||
'description' => 'Write proposal',
|
||||
]);
|
||||
|
||||
$todo = Todo::where('description', 'Write proposal')->firstOrFail();
|
||||
expect($todo->due_date->toDateString())->toBe('2026-09-25');
|
||||
});
|
||||
|
||||
test('a todo requires a description and folder', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('saveTodo')
|
||||
->assertHasErrors(['description', 'formFolderId'])
|
||||
->assertHasNoErrors(['dueDate', 'notes']);
|
||||
});
|
||||
|
||||
test('todos can be created without a due date', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openCreateForm')
|
||||
->set('description', 'Plan trip')
|
||||
->set('formFolderId', $folder->id)
|
||||
->call('saveTodo')
|
||||
->assertSet('showTodoForm', false);
|
||||
|
||||
$todo = Todo::where('description', 'Plan trip')->firstOrFail();
|
||||
expect($todo->due_date)->toBeNull();
|
||||
});
|
||||
|
||||
test('users can save and update notes on a todo', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openCreateForm')
|
||||
->set('description', 'Prepare talk')
|
||||
->set('formFolderId', $folder->id)
|
||||
->set('notes', 'Slides + handouts')
|
||||
->call('saveTodo');
|
||||
|
||||
$todo = Todo::where('description', 'Prepare talk')->firstOrFail();
|
||||
expect($todo->notes)->toBe('Slides + handouts');
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openEditForm', $todo->id)
|
||||
->set('notes', 'Slides + handouts + demo')
|
||||
->call('saveTodo');
|
||||
|
||||
expect($todo->fresh()->notes)->toBe('Slides + handouts + demo');
|
||||
});
|
||||
|
||||
test('notes are validated against the user notes limit', function () {
|
||||
$user = User::factory()->withNotesLimit(10)->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openCreateForm')
|
||||
->set('description', 'Exceeds limit')
|
||||
->set('formFolderId', $folder->id)
|
||||
->set('notes', str_repeat('a', 11))
|
||||
->call('saveTodo')
|
||||
->assertHasErrors('notes');
|
||||
|
||||
$this->assertDatabaseCount('todos', 0);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openCreateForm')
|
||||
->set('description', 'Within limit')
|
||||
->set('formFolderId', $folder->id)
|
||||
->set('notes', str_repeat('a', 10))
|
||||
->call('saveTodo')
|
||||
->assertHasNoErrors('notes');
|
||||
|
||||
$this->assertDatabaseCount('todos', 1);
|
||||
});
|
||||
|
||||
test('users can edit an existing todo', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$todo = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Old description']);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openEditForm', $todo->id)
|
||||
->set('description', 'New description')
|
||||
->set('dueDate', '2026-10-01')
|
||||
->call('saveTodo');
|
||||
|
||||
expect($todo->fresh()->description)->toBe('New description');
|
||||
expect($todo->fresh()->due_date->format('Y-m-d'))->toBe('2026-10-01');
|
||||
});
|
||||
|
||||
test('users can clear the due date when editing a todo', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$todo = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Someday maybe', 'due_date' => today()->addDays(3)]);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openEditForm', $todo->id)
|
||||
->set('dueDate', '')
|
||||
->call('saveTodo');
|
||||
|
||||
expect($todo->fresh()->due_date)->toBeNull();
|
||||
});
|
||||
|
||||
test('users can mark a todo done and reopen it', function () {
|
||||
$this->travelTo('2026-09-18 09:00:00');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$todo = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Buy milk', 'due_date' => today()->addDays(2)]);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('toggleComplete', $todo->id)
|
||||
->assertSet('todoCounts.completed', 1);
|
||||
|
||||
expect($todo->fresh()->completed_at)->not->toBeNull();
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('toggleComplete', $todo->id)
|
||||
->assertSet('todoCounts.completed', 0);
|
||||
|
||||
expect($todo->fresh()->completed_at)->toBeNull();
|
||||
});
|
||||
|
||||
test('users can delete a todo', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$todo = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Delete me']);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('confirmTodoDelete', $todo->id)
|
||||
->call('deleteTodo');
|
||||
|
||||
expect(Todo::find($todo->id))->toBeNull();
|
||||
$this->assertDatabaseCount('todos', 0);
|
||||
});
|
||||
|
||||
test('dashboard pre-filters to the folder from the query string', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$personal = Folder::factory()->for($user)->create(['name' => 'Personal']);
|
||||
|
||||
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Inside work folder', 'due_date' => today()->addDays(2)]);
|
||||
Todo::factory()->recycle($user)->for($personal)->create(['description' => 'Inside personal folder', 'due_date' => today()->addDays(2)]);
|
||||
|
||||
$this->get(route('dashboard', ['folder' => $work->id]))
|
||||
->assertOk()
|
||||
->assertSee('Inside work folder')
|
||||
->assertDontSee('Inside personal folder');
|
||||
});
|
||||
|
||||
test('a foreign folder query string is ignored', function () {
|
||||
$owner = User::factory()->create();
|
||||
$ownerFolder = Folder::factory()->for($owner)->create(['name' => 'Owner Folder']);
|
||||
|
||||
$intruder = User::factory()->create();
|
||||
$this->actingAs($intruder);
|
||||
|
||||
$ownFolder = Folder::factory()->for($intruder)->create(['name' => 'My Folder']);
|
||||
Todo::factory()->recycle($intruder)->for($ownFolder)->create(['description' => 'My own todo', 'due_date' => today()->addDays(2)]);
|
||||
|
||||
$this->get(route('dashboard', ['folder' => $ownerFolder->id]))
|
||||
->assertOk()
|
||||
->assertSee('My own todo')
|
||||
->assertDontSee('Owner Folder');
|
||||
});
|
||||
|
||||
test('users do not see another user todos or folders', function () {
|
||||
$owner = User::factory()->create();
|
||||
$ownerFolder = Folder::factory()->for($owner)->create(['name' => 'Owner Folder']);
|
||||
Todo::factory()->recycle($owner)->for($ownerFolder)->create(['description' => 'Owner secret', 'due_date' => today()->addDay()]);
|
||||
|
||||
$intruder = User::factory()->create();
|
||||
$this->actingAs($intruder);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->assertDontSee('Owner secret')
|
||||
->assertDontSee('Owner Folder');
|
||||
});
|
||||
|
||||
test('users cannot create todos in another user folders', function () {
|
||||
$owner = User::factory()->create();
|
||||
$folder = Folder::factory()->for($owner)->create(['name' => 'Work']);
|
||||
|
||||
$intruder = User::factory()->create();
|
||||
$this->actingAs($intruder);
|
||||
|
||||
Livewire::test('pages::dashboard')
|
||||
->call('openCreateForm')
|
||||
->set('description', 'Snooping')
|
||||
->set('dueDate', '2026-09-25')
|
||||
->set('formFolderId', $folder->id)
|
||||
->call('saveTodo')
|
||||
->assertHasErrors('formFolderId');
|
||||
|
||||
$this->assertDatabaseCount('todos', 0);
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
test('returns a successful response', function () {
|
||||
$response = $this->get(route('home'));
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Folder;
|
||||
use App\Models\Todo;
|
||||
use App\Models\User;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('guests are redirected to the login page', function () {
|
||||
$response = $this->get(route('folders'));
|
||||
$response->assertRedirect(route('login'));
|
||||
});
|
||||
|
||||
test('authenticated users can visit the folders page', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = $this->get(route('folders'));
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('users can create a top-level folder', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->set('newFolderName', 'Health')
|
||||
->call('createTopLevelFolder')
|
||||
->assertSet('newFolderName', '');
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Health',
|
||||
'parent_id' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('users can create a nested folder under another folder', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->call('startChildCreate', $work->id)
|
||||
->set('newChildName', 'Acme Corp')
|
||||
->call('createChildFolder')
|
||||
->assertSet('creatingChildOf', null)
|
||||
->assertSet('newChildName', '');
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Acme Corp',
|
||||
'parent_id' => $work->id,
|
||||
]);
|
||||
});
|
||||
|
||||
test('a folder name is required', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->call('createTopLevelFolder')
|
||||
->assertHasErrors('newFolderName');
|
||||
});
|
||||
|
||||
test('top-level folder names must be unique per user', function () {
|
||||
$user = User::factory()->create();
|
||||
Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->set('newFolderName', 'Work')
|
||||
->call('createTopLevelFolder')
|
||||
->assertHasErrors('newFolderName');
|
||||
});
|
||||
|
||||
test('users can rename a folder', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->call('startRename', $work->id)
|
||||
->set('renameName', 'Employment')
|
||||
->call('saveRename')
|
||||
->assertSet('renamingFolderId', null);
|
||||
|
||||
expect($work->fresh()->name)->toBe('Employment');
|
||||
});
|
||||
|
||||
test('deleting a folder removes its children and todos', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
$acme = Folder::factory()->childOf($work)->create(['name' => 'Acme Corp']);
|
||||
Todo::factory()->recycle($user)->for($acme)->create();
|
||||
|
||||
$this->assertDatabaseCount('folders', 2);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->call('confirmFolderDelete', $work->id)
|
||||
->call('deleteFolder')
|
||||
->assertSet('confirmingFolderDelete', null);
|
||||
|
||||
$this->assertDatabaseCount('folders', 0);
|
||||
$this->assertDatabaseCount('todos', 0);
|
||||
});
|
||||
|
||||
test('users do not see another user folders', function () {
|
||||
$owner = User::factory()->create();
|
||||
Folder::factory()->for($owner)->create(['name' => 'Owner Private Folder']);
|
||||
|
||||
$intruder = User::factory()->create();
|
||||
$this->actingAs($intruder);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->assertDontSee('Owner Private Folder');
|
||||
});
|
||||
|
||||
test('users can add a todo to a folder from the folders page', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->call('startTodoCreate', $work->id)
|
||||
->set('todoDescription', 'Write proposal')
|
||||
->set('todoDueDate', '2026-10-01')
|
||||
->set('todoNotes', 'Client revision A')
|
||||
->call('saveFolderTodo')
|
||||
->assertSet('showTodoForm', false);
|
||||
|
||||
$todo = Todo::where('description', 'Write proposal')->firstOrFail();
|
||||
expect($todo->folder_id)->toBe($work->id);
|
||||
expect($todo->user_id)->toBe($user->id);
|
||||
expect($todo->due_date->toDateString())->toBe('2026-10-01');
|
||||
expect($todo->notes)->toBe('Client revision A');
|
||||
});
|
||||
|
||||
test('notes added from the folders page respect the user notes limit', function () {
|
||||
$user = User::factory()->withNotesLimit(5)->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->call('startTodoCreate', $work->id)
|
||||
->set('todoDescription', 'Too long')
|
||||
->set('todoNotes', str_repeat('a', 6))
|
||||
->call('saveFolderTodo')
|
||||
->assertHasErrors('todoNotes');
|
||||
|
||||
$this->assertDatabaseCount('todos', 0);
|
||||
});
|
||||
|
||||
test('users can add a todo without a due date from the folders page', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->call('startTodoCreate', $work->id)
|
||||
->set('todoDescription', 'Someday task')
|
||||
->call('saveFolderTodo');
|
||||
|
||||
$todo = Todo::where('description', 'Someday task')->firstOrFail();
|
||||
expect($todo->due_date)->toBeNull();
|
||||
});
|
||||
|
||||
test('the view-todos button links to the filtered dashboard', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->assertSee((string) route('dashboard', ['folder' => $work->id]));
|
||||
});
|
||||
|
||||
test('a todo description is required when adding from the folders page', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||||
|
||||
Livewire::test('pages::folders')
|
||||
->call('startTodoCreate', $work->id)
|
||||
->call('saveFolderTodo')
|
||||
->assertHasErrors('todoDescription');
|
||||
|
||||
$this->assertDatabaseCount('todos', 0);
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Livewire\Livewire;
|
||||
|
||||
test('profile page is displayed', function () {
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
|
||||
$this->get(route('profile.edit'))->assertOk();
|
||||
});
|
||||
|
||||
test('profile information can be updated', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('pages::settings.profile')
|
||||
->set('name', 'Test User')
|
||||
->set('email', 'test@example.com')
|
||||
->call('updateProfileInformation');
|
||||
|
||||
$response->assertHasNoErrors();
|
||||
|
||||
$user->refresh();
|
||||
|
||||
expect($user->name)->toEqual('Test User');
|
||||
expect($user->email)->toEqual('test@example.com');
|
||||
expect($user->email_verified_at)->toBeNull();
|
||||
});
|
||||
|
||||
test('email verification status is unchanged when email address is unchanged', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('pages::settings.profile')
|
||||
->set('name', 'Test User')
|
||||
->set('email', $user->email)
|
||||
->call('updateProfileInformation');
|
||||
|
||||
$response->assertHasNoErrors();
|
||||
|
||||
expect($user->refresh()->email_verified_at)->not->toBeNull();
|
||||
});
|
||||
|
||||
test('user can delete their account', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('pages::settings.delete-user-modal')
|
||||
->set('password', 'password')
|
||||
->call('deleteUser');
|
||||
|
||||
$response
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect('/');
|
||||
|
||||
expect($user->fresh())->toBeNull();
|
||||
expect(auth()->check())->toBeFalse();
|
||||
});
|
||||
|
||||
test('correct password must be provided to delete account', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('pages::settings.delete-user-modal')
|
||||
->set('password', 'wrong-password')
|
||||
->call('deleteUser');
|
||||
|
||||
$response->assertHasErrors(['password']);
|
||||
|
||||
expect($user->fresh())->not->toBeNull();
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Laravel\Fortify\Features;
|
||||
use Livewire\Livewire;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
|
||||
|
||||
Features::twoFactorAuthentication([
|
||||
'confirm' => true,
|
||||
'confirmPassword' => true,
|
||||
]);
|
||||
Features::passkeys([
|
||||
'confirmPassword' => true,
|
||||
]);
|
||||
});
|
||||
|
||||
test('security settings page can be rendered', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->withSession(['auth.password_confirmed_at' => time()])
|
||||
->get(route('security.edit'));
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$response->assertSee('Passkeys');
|
||||
$response->assertSee('No passkeys yet');
|
||||
$response->assertSee('Two-factor authentication');
|
||||
$response->assertSee('Enable 2FA');
|
||||
});
|
||||
|
||||
test('security settings page requires password confirmation when enabled', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->get(route('security.edit'));
|
||||
|
||||
$response->assertRedirect(route('password.confirm'));
|
||||
});
|
||||
|
||||
test('security settings page renders without two factor when feature is disabled', function () {
|
||||
config(['fortify.features' => []]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->withSession(['auth.password_confirmed_at' => time()])
|
||||
->get(route('security.edit'))
|
||||
->assertOk()
|
||||
->assertSee('Update password')
|
||||
->assertDontSee('Manage your passkeys for passwordless sign-in')
|
||||
->assertDontSee('Add a passkey to sign in without a password')
|
||||
->assertDontSee('Two-factor authentication');
|
||||
});
|
||||
|
||||
test('two factor authentication disabled when confirmation abandoned between requests', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$user->forceFill([
|
||||
'two_factor_secret' => encrypt('test-secret'),
|
||||
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
|
||||
'two_factor_confirmed_at' => null,
|
||||
])->save();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$component = Livewire::test('pages::settings.security');
|
||||
|
||||
$component->assertSet('twoFactorEnabled', false);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'two_factor_secret' => null,
|
||||
'two_factor_recovery_codes' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
test('password can be updated', function () {
|
||||
$user = User::factory()->create([
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('pages::settings.security')
|
||||
->set('current_password', 'password')
|
||||
->set('password', 'new-password')
|
||||
->set('password_confirmation', 'new-password')
|
||||
->call('updatePassword');
|
||||
|
||||
$response->assertHasNoErrors();
|
||||
|
||||
expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue();
|
||||
});
|
||||
|
||||
test('correct password must be provided to update password', function () {
|
||||
$user = User::factory()->create([
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('pages::settings.security')
|
||||
->set('current_password', 'wrong-password')
|
||||
->set('password', 'new-password')
|
||||
->set('password_confirmation', 'new-password')
|
||||
->call('updatePassword');
|
||||
|
||||
$response->assertHasErrors(['current_password']);
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||
| need to change it using the "pest()" function to bind different classes or traits.
|
||||
|
|
||||
*/
|
||||
|
||||
pest()->extend(TestCase::class)
|
||||
->use(RefreshDatabase::class)
|
||||
->in('Feature');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expectations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When you're writing tests, you often need to check that values meet certain conditions. The
|
||||
| "expect()" function gives you access to a set of "expectations" methods that you can use
|
||||
| to assert different things. Of course, you may extend the Expectation API at any time.
|
||||
|
|
||||
*/
|
||||
|
||||
expect()->extend('toBeOne', function () {
|
||||
return $this->toBe(1);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||
| global functions to help you to reduce the number of lines of code in your test files.
|
||||
|
|
||||
*/
|
||||
|
||||
function something()
|
||||
{
|
||||
// ..
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
protected function skipUnlessFortifyHas(string $feature, ?string $message = null): void
|
||||
{
|
||||
if (! Features::enabled($feature)) {
|
||||
$this->markTestSkipped($message ?? "Fortify feature [{$feature}] is not enabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
test('that true is true', function () {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
Reference in New Issue
Block a user