Add checklists to tasks on the job page

Tasks get an ordered checklist (spec 8.2, phase 3): items are checked
done with who and when recorded, also by subcontractors attached to the
job; others add, rename, reorder and remove items. Items go with their
task. The spec gets a phase 3 chapter (18.1), and open questions move
to chapter 19.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 16:38:08 +02:00
co-authored by Claude Opus 5.5
parent e521df647c
commit dfe4941f02
28 changed files with 1376 additions and 3 deletions
@@ -0,0 +1,127 @@
<?php
use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->employee = User::factory()->create();
$this->actingAs($this->employee);
$this->job = CustomerJobModel::factory()->create(['status' => 'order', 'responsible_user_id' => $this->employee->id]);
$workType = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
$this->task = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Mainoskuvat']);
$this->params = ['jobId' => $this->job->id, 'taskId' => $this->task->id, 'taskTitle' => 'Mainoskuvat'];
});
/**
* @return list<string>
*/
function checklistTexts(int $taskId): array
{
return ChecklistItemModel::query()->where('task_id', $taskId)->orderBy('sort_order')->orderBy('id')->pluck('text')->all();
}
it('shows the checklist with progress on the job page', function () {
ChecklistItemModel::query()->create(['task_id' => $this->task->id, 'text' => 'Valot', 'sort_order' => 1, 'done_at' => now(), 'done_by' => $this->employee->id]);
ChecklistItemModel::query()->create(['task_id' => $this->task->id, 'text' => 'Mikit', 'sort_order' => 2]);
$this->get(route('jobs.show', $this->job->id))
->assertOk()
->assertSee('Tarkistuslista')
->assertSee('(1/2 tehty)')
->assertSeeInOrder(['Valot', 'Mikit']);
});
it('adds, checks, renames, moves and removes checklist items', function () {
$component = Livewire::test('jobs::task-checklist', $this->params)
->set('newItem', ' Valot ')
->call('add')
->assertHasNoErrors()
->assertSet('newItem', '')
->assertSee('Kohta Valot lisätty.')
->set('newItem', 'Mikit')
->call('add');
[$lights, $mics] = ChecklistItemModel::query()->orderBy('id')->pluck('id')->all();
$component->call('check', $lights, true)
->assertSee('Kohta Valot merkitty tehdyksi.')
->assertSee('(1/2 tehty)');
expect(ChecklistItemModel::query()->find($lights)->done_by)->toBe($this->employee->id);
$component->call('startRename', $lights)
->assertSet('editingItemId', $lights)
->set('editingText', 'Valot ja jalustat')
->call('saveRename')
->assertSee('Kohta Valot ja jalustat tallennettu.')
->assertSet('editingItemId', null)
->call('move', $mics, 'up')
->assertSee('Kohta Mikit siirretty ylöspäin.')
->call('move', $mics, 'up')
->assertSee('Kohta Mikit on jo ensimmäisenä.');
expect(checklistTexts($this->task->id))->toBe(['Mikit', 'Valot ja jalustat']);
$component->call('remove', $mics)->assertSee('Kohta Mikit poistettu.');
expect(checklistTexts($this->task->id))->toBe(['Valot ja jalustat']);
});
it('shows Finnish errors for empty and too long items', function () {
Livewire::test('jobs::task-checklist', $this->params)
->call('add')
->assertHasErrors('newItem')
->assertSee('Anna kohdan teksti.')
->set('newItem', str_repeat('a', 256))
->call('add')
->assertSee('Kohdan teksti voi olla enintään 255 merkkiä.');
expect(ChecklistItemModel::query()->count())->toBe(0);
});
it('does not change items of another task through this one', function () {
$other = ChecklistItemModel::query()->create(['task_id' => TaskModel::factory()->create()->id, 'text' => 'Vieras', 'sort_order' => 1]);
Livewire::test('jobs::task-checklist', $this->params)
->call('remove', $other->id)
->assertSee('Kohtaa ei löytynyt. Päivitä sivu.');
expect($other->fresh())->not->toBeNull();
});
it('lets an attached subcontractor check items but not manage them', function () {
$item = ChecklistItemModel::query()->create(['task_id' => $this->task->id, 'text' => 'Valot', 'sort_order' => 1]);
$subcontractor = User::factory()->subcontractor()->create();
TaskModel::factory()->assignedTo([$subcontractor->id])->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->task->work_type_id]);
$this->actingAs($subcontractor);
Livewire::test('jobs::task-checklist', $this->params)
->assertDontSee('Lisää kohta')
->call('check', $item->id, true)
->assertSee('Kohta Valot merkitty tehdyksi.')
->call('remove', $item->id)
->assertForbidden();
expect($item->fresh()->done_by)->toBe($subcontractor->id);
});
it('forbids the checklist of a job the subcontractor is not attached to', function () {
$this->actingAs(User::factory()->subcontractor()->create());
Livewire::test('jobs::task-checklist', $this->params)->assertForbidden();
});
it('removes the checklist with its task', function () {
ChecklistItemModel::query()->create(['task_id' => $this->task->id, 'text' => 'Valot', 'sort_order' => 1]);
$this->task->delete();
expect(ChecklistItemModel::query()->count())->toBe(0);
});