310 lines
10 KiB
PHP
310 lines
10 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
use App\Models\Folder;
|
||
|
|
use App\Models\Organization;
|
||
|
|
use App\Models\Todo;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\OrganizationRole;
|
||
|
|
use App\TodoStatus;
|
||
|
|
use Livewire\Livewire;
|
||
|
|
|
||
|
|
test('guests are redirected to the login page', function () {
|
||
|
|
$response = $this->get(route('kanban'));
|
||
|
|
|
||
|
|
$response->assertRedirect(route('login'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('authenticated users can visit the kanban page', function () {
|
||
|
|
$user = User::factory()->create();
|
||
|
|
$this->actingAs($user);
|
||
|
|
|
||
|
|
$response = $this->get(route('kanban'));
|
||
|
|
|
||
|
|
$response->assertOk();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('the board groups todos into status columns', function () {
|
||
|
|
$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',
|
||
|
|
'status' => TodoStatus::Open,
|
||
|
|
'position' => 0,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Todo::factory()->recycle($user)->for($folder)->create([
|
||
|
|
'description' => 'Progress task',
|
||
|
|
'status' => TodoStatus::InProgress,
|
||
|
|
'position' => 1,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Todo::factory()->recycle($user)->for($folder)->completed()->create([
|
||
|
|
'description' => 'Completed on hold',
|
||
|
|
'status' => TodoStatus::OnHold,
|
||
|
|
'position' => 2,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Todo::factory()->recycle($user)->for($folder)->create([
|
||
|
|
'description' => 'Completed status',
|
||
|
|
'status' => TodoStatus::Completed,
|
||
|
|
'position' => 3,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->assertSeeHtml('wire:sort="moveTodo"')
|
||
|
|
->assertSeeHtml('wire:sort:group="kanban"')
|
||
|
|
->assertSeeHtml('wire:sort:group-id="open"')
|
||
|
|
->assertSeeHtml('wire:sort:group-id="completed"')
|
||
|
|
->assertSeeHtmlInOrder([
|
||
|
|
'data-test="kanban-column-open"',
|
||
|
|
'Open task',
|
||
|
|
'data-test="kanban-column-in-progress"',
|
||
|
|
'Progress task',
|
||
|
|
'data-test="kanban-column-on-hold"',
|
||
|
|
'data-test="kanban-column-blocked"',
|
||
|
|
'data-test="kanban-column-cancelled"',
|
||
|
|
'data-test="kanban-column-deferred"',
|
||
|
|
'data-test="kanban-column-completed"',
|
||
|
|
'Completed status',
|
||
|
|
'Completed on hold',
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('moving a todo to another status column updates 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)->create([
|
||
|
|
'description' => 'Move me',
|
||
|
|
'status' => TodoStatus::Open,
|
||
|
|
'position' => 0,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Todo::factory()->recycle($user)->for($folder)->create([
|
||
|
|
'description' => 'Existing progress',
|
||
|
|
'status' => TodoStatus::InProgress,
|
||
|
|
'position' => 1,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->call('moveTodo', $todo->id, 1, 'in-progress')
|
||
|
|
->assertSeeHtmlInOrder([
|
||
|
|
'data-test="kanban-column-in-progress"',
|
||
|
|
'Existing progress',
|
||
|
|
'Move me',
|
||
|
|
]);
|
||
|
|
|
||
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::InProgress);
|
||
|
|
expect($todo->fresh()->completed_at)->toBeNull();
|
||
|
|
expect(Todo::query()->where('status', TodoStatus::InProgress)->priority()->pluck('description')->all())
|
||
|
|
->toBe(['Existing progress', 'Move me']);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('toggling complete moves a todo into and out of the completed column', 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' => 'Toggle me',
|
||
|
|
'status' => TodoStatus::Open,
|
||
|
|
'position' => 0,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->call('toggleComplete', $todo->id)
|
||
|
|
->assertSeeHtmlInOrder([
|
||
|
|
'data-test="kanban-column-completed"',
|
||
|
|
'Toggle me',
|
||
|
|
]);
|
||
|
|
|
||
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
|
||
|
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->call('toggleComplete', $todo->id)
|
||
|
|
->assertSeeHtmlInOrder([
|
||
|
|
'data-test="kanban-column-open"',
|
||
|
|
'Toggle me',
|
||
|
|
]);
|
||
|
|
|
||
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::Open);
|
||
|
|
expect($todo->fresh()->completed_at)->toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('moving a todo to completed marks it complete without losing its workflow 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 = Todo::factory()->recycle($user)->for($folder)->create([
|
||
|
|
'description' => 'Finish me',
|
||
|
|
'status' => TodoStatus::Blocked,
|
||
|
|
'position' => 0,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->call('moveTodo', $todo->id, 0, 'completed')
|
||
|
|
->assertSeeHtmlInOrder([
|
||
|
|
'data-test="kanban-column-completed"',
|
||
|
|
'Finish me',
|
||
|
|
]);
|
||
|
|
|
||
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::Blocked);
|
||
|
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('moving an open todo to completed also completes 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)->create([
|
||
|
|
'description' => 'Open task',
|
||
|
|
'status' => TodoStatus::Open,
|
||
|
|
'position' => 0,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->call('moveTodo', $todo->id, 0, 'completed');
|
||
|
|
|
||
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::Completed);
|
||
|
|
expect($todo->fresh()->completed_at)->not->toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('moving a completed todo back to a status column reopens it', function () {
|
||
|
|
$user = User::factory()->create();
|
||
|
|
$this->actingAs($user);
|
||
|
|
|
||
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||
|
|
$todo = Todo::factory()->recycle($user)->for($folder)->completed()->create([
|
||
|
|
'description' => 'Reopen me',
|
||
|
|
'status' => TodoStatus::OnHold,
|
||
|
|
'position' => 0,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->call('moveTodo', $todo->id, 0, 'on-hold')
|
||
|
|
->assertSeeHtmlInOrder([
|
||
|
|
'data-test="kanban-column-on-hold"',
|
||
|
|
'Reopen me',
|
||
|
|
]);
|
||
|
|
|
||
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::OnHold);
|
||
|
|
expect($todo->fresh()->completed_at)->toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('reordering within a column keeps the order of other columns', 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 open',
|
||
|
|
'status' => TodoStatus::Open,
|
||
|
|
'position' => 0,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Todo::factory()->recycle($user)->for($folder)->create([
|
||
|
|
'description' => 'Second open',
|
||
|
|
'status' => TodoStatus::Open,
|
||
|
|
'position' => 1,
|
||
|
|
]);
|
||
|
|
|
||
|
|
$blocked = Todo::factory()->recycle($user)->for($folder)->create([
|
||
|
|
'description' => 'Blocked task',
|
||
|
|
'status' => TodoStatus::Blocked,
|
||
|
|
'position' => 2,
|
||
|
|
]);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->call('moveTodo', $first->id, 1, 'open');
|
||
|
|
|
||
|
|
expect(Todo::query()->where('status', TodoStatus::Open)->priority()->pluck('description')->all())
|
||
|
|
->toBe(['Second open', 'First open']);
|
||
|
|
expect($blocked->fresh()->position)->toBe(2);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('the board 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']);
|
||
|
|
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Review proposal']);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->set('search', 'proposal')
|
||
|
|
->assertDontSee('Review design')
|
||
|
|
->assertSee('Review proposal');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('adding a todo from a column preselects that status', function () {
|
||
|
|
$user = User::factory()->create();
|
||
|
|
$this->actingAs($user);
|
||
|
|
|
||
|
|
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->call('openCreateForm', 'blocked')
|
||
|
|
->assertSet('todoStatus', 'blocked')
|
||
|
|
->set('description', 'Blocked task')
|
||
|
|
->set('formFolderId', $folder->id)
|
||
|
|
->call('saveTodo')
|
||
|
|
->assertSet('showTodoForm', false)
|
||
|
|
->assertSeeHtmlInOrder([
|
||
|
|
'data-test="kanban-column-blocked"',
|
||
|
|
'Blocked task',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$todo = Todo::where('description', 'Blocked task')->firstOrFail();
|
||
|
|
|
||
|
|
expect($todo->status)->toBe(TodoStatus::Blocked);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('users do not see another user todos on the board', function () {
|
||
|
|
$owner = User::factory()->create();
|
||
|
|
$ownerFolder = Folder::factory()->for($owner)->create(['name' => 'Owner Folder']);
|
||
|
|
Todo::factory()->recycle($owner)->for($ownerFolder)->create(['description' => 'Owner secret']);
|
||
|
|
|
||
|
|
$intruder = User::factory()->create();
|
||
|
|
$this->actingAs($intruder);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->assertDontSee('Owner secret')
|
||
|
|
->assertDontSee('Owner Folder');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('viewers cannot move todos on the board', function () {
|
||
|
|
$owner = User::factory()->create();
|
||
|
|
$member = User::factory()->create();
|
||
|
|
|
||
|
|
$organization = Organization::factory()->family()->withMember($owner)->create();
|
||
|
|
$owner->forceFill(['current_organization_id' => $organization->id])->save();
|
||
|
|
$organization->users()->attach($member, ['role' => OrganizationRole::Member->value]);
|
||
|
|
$member->forceFill(['current_organization_id' => $organization->id])->save();
|
||
|
|
|
||
|
|
$folder = Folder::factory()->for($owner)->inOrganization($organization)->sharedWithWorkspace()->create(['name' => 'Shared List']);
|
||
|
|
$todo = Todo::factory()->recycle($owner)->for($folder)->create([
|
||
|
|
'description' => 'Shared task',
|
||
|
|
'status' => TodoStatus::Open,
|
||
|
|
]);
|
||
|
|
|
||
|
|
$this->actingAs($member);
|
||
|
|
|
||
|
|
Livewire::test('pages::kanban')
|
||
|
|
->assertSee('Shared task')
|
||
|
|
->call('moveTodo', $todo->id, 0, 'in-progress')
|
||
|
|
->assertStatus(403);
|
||
|
|
|
||
|
|
expect($todo->fresh()->status)->toBe(TodoStatus::Open);
|
||
|
|
});
|