added status for todos; updated add todo dialog title
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-09-18 15:34:35 -07:00
parent 1e8ae3d1e5
commit 4391d342ff
6 changed files with 269 additions and 5 deletions
+23 -5
View File
@@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use App\TodoStatus;
use Database\Factories\TodoFactory; use Database\Factories\TodoFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
@@ -16,13 +17,14 @@ use Illuminate\Support\Carbon;
* @property int $folder_id * @property int $folder_id
* @property string $description * @property string $description
* @property string|null $notes * @property string|null $notes
* @property TodoStatus $status
* @property Carbon|null $due_date * @property Carbon|null $due_date
* @property Carbon|null $completed_at * @property Carbon|null $completed_at
* @property Folder $folder * @property Folder $folder
* @property Carbon|null $created_at * @property Carbon|null $created_at
* @property Carbon|null $updated_at * @property Carbon|null $updated_at
*/ */
#[Fillable(['user_id', 'folder_id', 'description', 'notes', 'due_date', 'completed_at'])] #[Fillable(['user_id', 'folder_id', 'description', 'notes', 'status', 'due_date', 'completed_at'])]
class Todo extends Model class Todo extends Model
{ {
/** @use HasFactory<TodoFactory> */ /** @use HasFactory<TodoFactory> */
@@ -50,6 +52,7 @@ class Todo extends Model
return [ return [
'due_date' => 'date', 'due_date' => 'date',
'completed_at' => 'datetime', 'completed_at' => 'datetime',
'status' => TodoStatus::class,
]; ];
} }
@@ -87,24 +90,39 @@ class Todo extends Model
} }
/** /**
* Scope the query to open todos whose due date has already passed. * Scope the query to todos that still need attention: not completed
* and not cancelled or deferred.
*
* @param Builder<Todo> $query
* @return Builder<Todo>
*/
public function scopeActive(Builder $query): Builder
{
return $query->incomplete()->whereNotIn('status', [
TodoStatus::Cancelled->value,
TodoStatus::Deferred->value,
]);
}
/**
* Scope the query to active todos whose due date has already passed.
* *
* @param Builder<Todo> $query * @param Builder<Todo> $query
* @return Builder<Todo> * @return Builder<Todo>
*/ */
public function scopeOverdue(Builder $query): Builder public function scopeOverdue(Builder $query): Builder
{ {
return $query->incomplete()->whereDate('due_date', '<', now()); return $query->active()->whereDate('due_date', '<', now());
} }
/** /**
* Scope the query to open todos due today. * Scope the query to active todos due today.
* *
* @param Builder<Todo> $query * @param Builder<Todo> $query
* @return Builder<Todo> * @return Builder<Todo>
*/ */
public function scopeDueToday(Builder $query): Builder public function scopeDueToday(Builder $query): Builder
{ {
return $query->incomplete()->whereDate('due_date', today()); return $query->active()->whereDate('due_date', today());
} }
} }
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App;
enum TodoStatus: string
{
case Open = 'open';
case InProgress = 'in-progress';
case OnHold = 'on-hold';
case Blocked = 'blocked';
case Cancelled = 'cancelled';
case Deferred = 'deferred';
/**
* Get the human-friendly label for the status.
*/
public function label(): string
{
return match ($this) {
self::Open => 'Open',
self::InProgress => 'In Progress',
self::OnHold => 'On Hold',
self::Blocked => 'Blocked',
self::Cancelled => 'Cancelled',
self::Deferred => 'Deferred',
};
}
/**
* Get the Flux badge color used to render the status.
*/
public function badgeColor(): string
{
return match ($this) {
self::Open => 'blue',
self::InProgress => 'green',
self::OnHold => 'amber',
self::Blocked => 'red',
self::Cancelled => 'zinc',
self::Deferred => 'purple',
};
}
/**
* Determine whether the status means the todo is no longer actionable.
*/
public function isTerminal(): bool
{
return in_array($this, [self::Cancelled, self::Deferred], true);
}
}
+12
View File
@@ -5,6 +5,7 @@ namespace Database\Factories;
use App\Models\Folder; use App\Models\Folder;
use App\Models\Todo; use App\Models\Todo;
use App\Models\User; use App\Models\User;
use App\TodoStatus;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/** /**
@@ -23,6 +24,7 @@ class TodoFactory extends Factory
'user_id' => User::factory(), 'user_id' => User::factory(),
'folder_id' => Folder::factory(), 'folder_id' => Folder::factory(),
'description' => fake()->sentence(6), 'description' => fake()->sentence(6),
'status' => TodoStatus::Open,
'due_date' => today()->addDays(5), 'due_date' => today()->addDays(5),
'completed_at' => null, 'completed_at' => null,
]; ];
@@ -58,6 +60,16 @@ class TodoFactory extends Factory
]); ]);
} }
/**
* Apply the given status to the todo.
*/
public function withStatus(TodoStatus $status): static
{
return $this->state(fn (array $attributes) => [
'status' => $status,
]);
}
/** /**
* Indicate that the todo is overdue. * Indicate that the todo is overdue.
*/ */
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('todos', function (Blueprint $table) {
$table->string('status')->default('open')->after('description');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('todos', function (Blueprint $table) {
$table->dropColumn('status');
});
}
};
+108
View File
@@ -3,6 +3,7 @@
use App\Models\Folder; use App\Models\Folder;
use App\Models\Todo; use App\Models\Todo;
use App\Models\User; use App\Models\User;
use App\TodoStatus;
use Livewire\Livewire; use Livewire\Livewire;
test('guests are redirected to the login page', function () { test('guests are redirected to the login page', function () {
@@ -142,6 +143,97 @@ test('todos can be created without a due date', function () {
expect($todo->due_date)->toBeNull(); expect($todo->due_date)->toBeNull();
}); });
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);
});
test('users can save and update notes on a todo', function () { test('users can save and update notes on a todo', function () {
$user = User::factory()->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
@@ -247,6 +339,22 @@ test('users can mark a todo done and reopen it', function () {
expect($todo->fresh()->completed_at)->toBeNull(); expect($todo->fresh()->completed_at)->toBeNull();
}); });
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');
});
test('users can delete a todo', function () { test('users can delete a todo', function () {
$user = User::factory()->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
+47
View File
@@ -3,6 +3,7 @@
use App\Models\Folder; use App\Models\Folder;
use App\Models\Todo; use App\Models\Todo;
use App\Models\User; use App\Models\User;
use App\TodoStatus;
use Livewire\Livewire; use Livewire\Livewire;
test('guests are redirected to the login page', function () { test('guests are redirected to the login page', function () {
@@ -181,6 +182,52 @@ test('the view-todos button links to the filtered dashboard', function () {
->assertSee((string) route('dashboard', ['folder' => $work->id])); ->assertSee((string) route('dashboard', ['folder' => $work->id]));
}); });
test('the add todo dialog on the folders page shows the target folder', 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']);
Livewire::test('pages::folders')
->call('startTodoCreate', $acme->id)
->assertSeeHtml('data-test="add-todo-folder-name"')
->assertSeeHtml('data-test="add-todo-title-folder"')
->assertSeeText('Add todo - Work / Acme Corp');
});
test('users can set a status when adding a todo 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', 'Review contract')
->set('todoStatus', 'deferred')
->call('saveFolderTodo');
$todo = Todo::where('description', 'Review contract')->firstOrFail();
expect($todo->status)->toBe(TodoStatus::Deferred);
});
test('an invalid status is rejected 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)
->set('todoDescription', 'Nope')
->set('todoStatus', 'bogus')
->call('saveFolderTodo')
->assertHasErrors('todoStatus');
$this->assertDatabaseCount('todos', 0);
});
test('a todo description is required when adding from the folders page', function () { test('a todo description is required when adding from the folders page', function () {
$user = User::factory()->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);