updated folder colors, reordering, new todo page, updated sidebar
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-09-21 00:33:10 -07:00
parent df016dad14
commit f8fc561602
25 changed files with 1980 additions and 264 deletions
+187
View File
@@ -331,12 +331,42 @@ test('users can mark a todo done and reopen it', function () {
->assertSet('todoCounts.completed', 1);
expect($todo->fresh()->completed_at)->not->toBeNull();
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
Livewire::test('pages::dashboard')
->call('toggleComplete', $todo->id)
->assertSet('todoCounts.completed', 0);
expect($todo->fresh()->completed_at)->toBeNull();
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);
});
test('completed todos render with strikethrough styling', function () {
@@ -355,6 +385,29 @@ test('completed todos render with strikethrough styling', function () {
->assertDontSeeHtml('line-through text-zinc-400">Pending task');
});
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');
});
test('users can delete a todo', function () {
$user = User::factory()->create();
$this->actingAs($user);
@@ -432,3 +485,137 @@ test('users cannot create todos in another user folders', function () {
$this->assertDatabaseCount('todos', 0);
});
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']);
});
+25
View File
@@ -0,0 +1,25 @@
<?php
use App\Models\Folder;
use App\Models\Todo;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use function Pest\Laravel\seed;
test('full seeding creates the test user, folders and todos', function () {
seed(DatabaseSeeder::class);
expect(User::where('email', 'test@example.com')->count())->toBe(1)
->and(Folder::count())->toBe(9)
->and(Todo::count())->toBe(8);
});
test('full seeding is idempotent', function () {
seed(DatabaseSeeder::class);
seed(DatabaseSeeder::class);
expect(User::where('email', 'test@example.com')->count())->toBe(1)
->and(Folder::count())->toBe(9)
->and(Todo::count())->toBe(8);
});
+212
View File
@@ -4,6 +4,7 @@ use App\Models\Folder;
use App\Models\Todo;
use App\Models\User;
use App\TodoStatus;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Livewire\Livewire;
test('guests are redirected to the login page', function () {
@@ -241,3 +242,214 @@ test('a todo description is required when adding from the folders page', functio
$this->assertDatabaseCount('todos', 0);
});
test('clicking the open badge expands the open todos in the folder', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Open task', 'due_date' => today()->addDays(2)]);
Todo::factory()->recycle($user)->for($work)->completed()->create(['description' => 'Done task']);
Livewire::test('pages::folders')
->call('toggleExpandFolder', $work->id)
->assertSet('expandedFolderId', $work->id)
->assertSee('Open task')
->assertDontSee('Done task');
});
test('clicking the open badge again collapses the folder todos', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Open task', 'due_date' => today()->addDays(2)]);
Livewire::test('pages::folders')
->call('toggleExpandFolder', $work->id)
->call('toggleExpandFolder', $work->id)
->assertSet('expandedFolderId', null)
->assertDontSee('Open task');
});
test('only the clicked folder is expanded at a time', 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' => 'Work task', 'due_date' => today()->addDays(2)]);
Todo::factory()->recycle($user)->for($personal)->create(['description' => 'Personal task', 'due_date' => today()->addDays(2)]);
Livewire::test('pages::folders')
->call('toggleExpandFolder', $work->id)
->call('toggleExpandFolder', $personal->id)
->assertSet('expandedFolderId', $personal->id)
->assertDontSee('Work task')
->assertSee('Personal task');
});
test('users can move a todo to another folder from the folders page', 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 = Todo::factory()->recycle($user)->for($work)->create(['description' => 'Move me', 'due_date' => today()->addDay()]);
Livewire::test('pages::folders')
->call('toggleExpandFolder', $work->id)
->call('moveTodoToFolder', $todo->id, $personal->id);
expect($todo->fresh()->folder_id)->toBe($personal->id);
});
test('users cannot move a todo to another user folder', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
$todo = Todo::factory()->recycle($user)->for($work)->create(['description' => 'Mine', 'due_date' => today()->addDay()]);
$owner = User::factory()->create();
$foreign = Folder::factory()->for($owner)->create(['name' => 'Foreign']);
$this->expectException(ModelNotFoundException::class);
Livewire::test('pages::folders')
->call('moveTodoToFolder', $todo->id, $foreign->id);
});
test('users cannot move another user todo', function () {
$owner = User::factory()->create();
$ownerFolder = Folder::factory()->for($owner)->create(['name' => 'Owner Folder']);
$ownerTodo = Todo::factory()->recycle($owner)->for($ownerFolder)->create(['description' => 'Owner secret', 'due_date' => today()->addDay()]);
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
$this->expectException(ModelNotFoundException::class);
Livewire::test('pages::folders')
->call('moveTodoToFolder', $ownerTodo->id, $work->id);
});
test('users can create a top-level folder with a color', function () {
$user = User::factory()->create();
$this->actingAs($user);
Livewire::test('pages::folders')
->set('newFolderName', 'Work')
->set('newFolderColor', 'blue')
->call('createTopLevelFolder')
->assertSet('newFolderColor', '');
$this->assertDatabaseHas('folders', [
'user_id' => $user->id,
'name' => 'Work',
'color' => 'blue',
'parent_id' => null,
]);
});
test('users can create a sub-folder with a color', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => null]);
Livewire::test('pages::folders')
->call('startChildCreate', $work->id)
->set('newChildName', 'Acme Corp')
->set('newChildColor', 'emerald')
->call('createChildFolder')
->assertSet('newChildColor', '');
$this->assertDatabaseHas('folders', [
'user_id' => $user->id,
'name' => 'Acme Corp',
'color' => 'emerald',
'parent_id' => $work->id,
]);
});
test('an invalid folder color is rejected', function () {
$user = User::factory()->create();
$this->actingAs($user);
Livewire::test('pages::folders')
->set('newFolderName', 'Work')
->set('newFolderColor', 'neon')
->call('createTopLevelFolder')
->assertHasErrors('newFolderColor');
$this->assertDatabaseCount('folders', 0);
});
test('the folder color dot is shown on the folders page', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => 'indigo']);
Livewire::test('pages::folders')
->assertSee("data-test=\"folder-dot-{$work->id}\"", false);
});
test('the color picker offers the palette options', function () {
$user = User::factory()->create();
$this->actingAs($user);
Livewire::test('pages::folders')
->assertSee('color-option-none', false)
->assertSee('color-option-blue', false)
->assertSee('color-option-pink', false);
});
test('users can choose a color for an existing folder', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => null]);
Livewire::test('pages::folders')
->call('startColorEdit', $work->id)
->assertSet('colorDraft', '')
->set('colorDraft', 'violet')
->call('saveFolderColor')
->assertSet('colorEditingFolderId', null);
expect($work->fresh()->color)->toBe('violet');
});
test('users can clear the color of an existing folder', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => 'amber']);
Livewire::test('pages::folders')
->call('startColorEdit', $work->id)
->assertSet('colorDraft', 'amber')
->set('colorDraft', '')
->call('saveFolderColor');
expect($work->fresh()->color)->toBeNull();
});
test('an invalid color is rejected when editing a folder', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work', 'color' => null]);
Livewire::test('pages::folders')
->call('startColorEdit', $work->id)
->set('colorDraft', 'neon')
->call('saveFolderColor')
->assertHasErrors('colorDraft');
expect($work->fresh()->color)->toBeNull();
});
+251
View File
@@ -0,0 +1,251 @@
<?php
use App\Models\Folder;
use App\Models\Todo;
use App\Models\User;
use App\TodoStatus;
use Livewire\Livewire;
test('guests are redirected to the login page', function () {
$response = $this->get(route('todos'));
$response->assertRedirect(route('login'));
});
test('authenticated users can visit the todos page', function () {
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->get(route('todos'));
$response->assertOk();
});
test('users only see their own todos', 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::todos')
->assertDontSee('Owner secret')
->assertDontSee('Owner Folder');
});
test('the todos page loads a limited batch and has more to load', function () {
$user = User::factory()->create();
$this->actingAs($user);
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
collect(range(1, 60))
->each(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create([
'description' => 'Todo '.$n,
'position' => $n - 1,
]));
Livewire::test('pages::todos')
->assertSet('limit', 50)
->assertSet('hasMore', true)
->assertSee('Todo 1')
->assertDontSee('Todo 51');
});
test('loadMore appends the next batch until nothing remains', function () {
$user = User::factory()->create();
$this->actingAs($user);
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
collect(range(1, 120))
->each(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create([
'description' => 'Todo '.$n,
'position' => $n - 1,
]));
Livewire::test('pages::todos')
->call('loadMore')
->assertSet('limit', 100)
->assertSee('Todo 51')
->assertDontSee('Todo 101')
->call('loadMore')
->assertSet('limit', 120)
->assertSee('Todo 120')
->assertSet('hasMore', false);
});
test('loadMore does not exceed the total number of todos', function () {
$user = User::factory()->create();
$this->actingAs($user);
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
collect(range(1, 20))
->each(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Todo '.$n]));
Livewire::test('pages::todos')
->call('loadMore')
->assertSet('limit', 20)
->assertSet('hasMore', false);
});
test('changing a filter resets the loaded batch', function () {
$user = User::factory()->create();
$this->actingAs($user);
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Todo', 'due_date' => today()->addDay()]);
Livewire::test('pages::todos')
->call('loadMore')
->set('status', 'open')
->assertSet('limit', 50);
});
test('the todos page filters by status', 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 task', 'due_date' => today()->addDays(5)]);
Todo::factory()->recycle($user)->for($folder)->overdue()->create(['description' => 'Overdue task']);
Todo::factory()->recycle($user)->for($folder)->completed()->create(['description' => 'Done task']);
Livewire::test('pages::todos')
->set('status', 'overdue')
->assertDontSee('Open task')
->assertSee('Overdue task')
->assertDontSee('Done task');
});
test('users can create a todo from the todos page', 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::todos')
->call('openCreateForm')
->set('description', 'Write proposal')
->set('formFolderId', $folder->id)
->call('saveTodo')
->assertSet('showTodoForm', false);
$todo = Todo::where('description', 'Write proposal')->firstOrFail();
expect($todo->position)->toBe(0);
});
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::todos')
->call('toggleComplete', $todo->id);
expect($todo->fresh()->completed_at)->not->toBeNull();
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
Livewire::test('pages::todos')
->call('toggleComplete', $todo->id);
expect($todo->fresh()->completed_at)->toBeNull();
expect($todo->fresh()->status)->toBe(TodoStatus::Open);
});
test('users can drag a todo to a new position without a pagination offset', function () {
$user = User::factory()->create();
$this->actingAs($user);
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
$todos = collect(range(1, 60))
->map(fn (int $n) => Todo::factory()->recycle($user)->for($folder)->create([
'description' => 'Todo '.$n,
'position' => $n - 1,
]));
Livewire::test('pages::todos')
->call('loadMore')
->call('handleSort', $todos->get(30)->id, 0);
expect($todos->get(30)->fresh()->position)->toBe(0);
expect($todos->get(0)->fresh()->position)->toBe(1);
expect($todos->get(29)->fresh()->position)->toBe(30);
});
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::todos')
->call('moveTodo', $third->id, 'up');
expect($first->fresh()->position)->toBe(0);
expect($second->fresh()->position)->toBe(2);
expect($third->fresh()->position)->toBe(1);
});
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::todos')
->call('confirmTodoDelete', $todo->id)
->call('deleteTodo');
expect(Todo::find($todo->id))->toBeNull();
$this->assertDatabaseCount('todos', 0);
});
test('users do not see another user todos', 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::todos')
->assertDontSee('Owner secret');
});
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::todos')
->call('toggleComplete', $todo->id);
$todo->refresh();
Livewire::test('pages::todos')
->assertSee('Sep 18, 2026')
->assertSee('Completed in 8 days');
});