2026-09-17 23:01:26 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Models\Folder;
|
|
|
|
|
use App\Models\Todo;
|
|
|
|
|
use App\Models\User;
|
2026-09-18 15:34:35 -07:00
|
|
|
use App\TodoStatus;
|
2026-09-17 23:01:26 -07:00
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-18 15:34:35 -07:00
|
|
|
test('users can set a status when creating 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', 'Fix login bug')
|
|
|
|
|
->set('todoStatus', 'blocked')
|
|
|
|
|
->set('formFolderId', $folder->id)
|
|
|
|
|
->call('saveTodo')
|
|
|
|
|
->assertSet('showTodoForm', false);
|
|
|
|
|
|
|
|
|
|
$todo = Todo::where('description', 'Fix login bug')->firstOrFail();
|
|
|
|
|
expect($todo->status)->toBe(TodoStatus::Blocked);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('an invalid todo status is rejected', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('openCreateForm')
|
|
|
|
|
->set('description', 'Nope')
|
|
|
|
|
->set('todoStatus', 'bogus')
|
|
|
|
|
->set('formFolderId', $folder->id)
|
|
|
|
|
->call('saveTodo')
|
|
|
|
|
->assertHasErrors('todoStatus');
|
|
|
|
|
|
|
|
|
|
$this->assertDatabaseCount('todos', 0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('users can change the status of 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' => 'Write report']);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('openEditForm', $todo->id)
|
|
|
|
|
->set('todoStatus', 'on-hold')
|
|
|
|
|
->call('saveTodo');
|
|
|
|
|
|
|
|
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::OnHold);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('todos show their status badge in the list', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
$todo = Todo::factory()->recycle($user)->for($folder)->withStatus(TodoStatus::InProgress)->create(['description' => 'Draft plan']);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->assertSeeHtml('data-test="todo-status-'.$todo->id.'"')
|
|
|
|
|
->assertSee('In Progress');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('todo list filters by workflow status', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->withStatus(TodoStatus::Blocked)->create(['description' => 'Blocked task']);
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Open task']);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->set('status', 'blocked')
|
|
|
|
|
->assertSee('Blocked task')
|
|
|
|
|
->assertDontSee('Open task');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cancelled and deferred todos are excluded from the open count', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Active task', 'due_date' => today()->addDays(3)]);
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->withStatus(TodoStatus::Cancelled)->create(['description' => 'Cancelled task']);
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->withStatus(TodoStatus::Deferred)->create(['description' => 'Deferred task']);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->assertSet('todoCounts.open', 1);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-17 23:01:26 -07:00
|
|
|
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();
|
2026-09-21 00:33:10 -07:00
|
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
|
2026-09-17 23:01:26 -07:00
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('toggleComplete', $todo->id)
|
|
|
|
|
->assertSet('todoCounts.completed', 0);
|
|
|
|
|
|
|
|
|
|
expect($todo->fresh()->completed_at)->toBeNull();
|
2026-09-21 00:33:10 -07:00
|
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::Open);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('an in-progress todo is marked completed when checked', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
$todo = Todo::factory()->recycle($user)->for($folder)->withStatus(TodoStatus::InProgress)->create(['description' => 'Draft plan']);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('toggleComplete', $todo->id);
|
|
|
|
|
|
|
|
|
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
|
|
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('checking an on-hold todo does not overwrite its status', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
$todo = Todo::factory()->recycle($user)->for($folder)->withStatus(TodoStatus::OnHold)->create(['description' => 'Waiting for signoff']);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('toggleComplete', $todo->id);
|
|
|
|
|
|
|
|
|
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
|
|
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::OnHold);
|
2026-09-17 23:01:26 -07:00
|
|
|
});
|
|
|
|
|
|
2026-09-18 15:34:35 -07:00
|
|
|
test('completed todos render with strikethrough styling', 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)->completed()->create(['description' => 'Finished task']);
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Pending task', 'due_date' => today()->addDays(3)]);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->assertSeeHtml('<span class="line-through text-zinc-400">Finished task</span>')
|
|
|
|
|
->assertDontSeeHtml('line-through text-zinc-400">Pending task');
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-21 00:33:10 -07:00
|
|
|
test('completed todos show their completion date and days to completion', function () {
|
|
|
|
|
$this->travelTo('2026-09-10 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' => 'Shipped feature']);
|
|
|
|
|
|
|
|
|
|
$this->travelTo('2026-09-18 09:00:00');
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('toggleComplete', $todo->id);
|
|
|
|
|
|
|
|
|
|
$todo->refresh();
|
|
|
|
|
|
|
|
|
|
expect($todo->daysToComplete())->toBe(8);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->assertSee('Sep 18, 2026')
|
|
|
|
|
->assertSee('Completed in 8 days');
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-17 23:01:26 -07:00
|
|
|
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);
|
|
|
|
|
});
|
2026-09-21 00:33:10 -07:00
|
|
|
|
|
|
|
|
test('new todos are added to the top of the priority order', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Older todo', 'position' => 2]);
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Middle todo', 'position' => 1]);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('openCreateForm')
|
|
|
|
|
->set('description', 'Newest todo')
|
|
|
|
|
->set('formFolderId', $folder->id)
|
|
|
|
|
->call('saveTodo');
|
|
|
|
|
|
|
|
|
|
$newest = Todo::where('description', 'Newest todo')->firstOrFail();
|
|
|
|
|
|
|
|
|
|
expect($newest->position)->toBe(0);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->assertSeeInOrder(['Newest todo', 'Middle todo', 'Older todo']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('users can move a todo up in the priority order', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
|
|
|
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
|
|
|
|
$third = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Third todo', 'position' => 2]);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('moveTodo', $third->id, 'up');
|
|
|
|
|
|
|
|
|
|
expect($first->fresh()->position)->toBe(0);
|
|
|
|
|
expect($second->fresh()->position)->toBe(2);
|
|
|
|
|
expect($third->fresh()->position)->toBe(1);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->assertSeeInOrder(['First todo', 'Third todo', 'Second todo']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('users can move a todo down in the priority order', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
|
|
|
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('moveTodo', $first->id, 'down');
|
|
|
|
|
|
|
|
|
|
expect($first->fresh()->position)->toBe(1);
|
|
|
|
|
expect($second->fresh()->position)->toBe(0);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->assertSeeInOrder(['Second todo', 'First todo']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('moving the first todo up does nothing', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
|
|
|
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('moveTodo', $first->id, 'up');
|
|
|
|
|
|
|
|
|
|
expect($first->fresh()->position)->toBe(0);
|
|
|
|
|
expect($second->fresh()->position)->toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('users can drag a todo to a new position', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
|
|
|
|
|
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
|
|
|
|
|
$third = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Third todo', 'position' => 2]);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->call('handleSort', $first->id, 2);
|
|
|
|
|
|
|
|
|
|
expect($first->fresh()->position)->toBe(2);
|
|
|
|
|
expect($second->fresh()->position)->toBe(0);
|
|
|
|
|
expect($third->fresh()->position)->toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('dragging accounts for the pagination offset', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
$todos = collect(range(1, 12))
|
|
|
|
|
->map(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create([
|
|
|
|
|
'description' => 'Todo '.$n,
|
|
|
|
|
'position' => $n - 1,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
$todoEleven = $todos->get(10);
|
|
|
|
|
$todoTwelve = $todos->get(11);
|
|
|
|
|
|
|
|
|
|
Livewire::withQueryParams(['page' => 2])
|
|
|
|
|
->test('pages::dashboard')
|
|
|
|
|
->assertSee('Todo 12')
|
|
|
|
|
->call('handleSort', $todoTwelve->id, 0);
|
|
|
|
|
|
|
|
|
|
expect($todoEleven->fresh()->position)->toBe(11);
|
|
|
|
|
expect($todoTwelve->fresh()->position)->toBe(10);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('completed todos sort last regardless of their position', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$this->actingAs($user);
|
|
|
|
|
|
|
|
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
|
|
|
|
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->completed()->create(['description' => 'Finished task', 'position' => 0]);
|
|
|
|
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Pending task', 'position' => 1]);
|
|
|
|
|
|
|
|
|
|
Livewire::test('pages::dashboard')
|
|
|
|
|
->assertSeeInOrder(['Pending task', 'Finished task']);
|
|
|
|
|
});
|