items = new InMemoryChecklistItemRepository; $transactions = new FakeTransactionManager; $finder = new ChecklistItemFinder($tasks, $this->items); $this->jobId = 5; $this->taskId = (int) $tasks->save(Task::reconstitute(1, $this->jobId, 11, new TaskTitle('Kuvaus'), null, TaskStatus::Waiting, null, null, null, [], 10))->id(); $this->add = new AddChecklistItem($finder, $this->items, $transactions); $this->rename = new RenameChecklistItem($finder, $this->items, $transactions); $this->check = new CheckChecklistItem($finder, $this->items, $transactions, new FakeClock(new DateTimeImmutable('2026-11-24'))); $this->move = new MoveChecklistItem($finder, $this->items, $transactions); $this->remove = new RemoveChecklistItem($finder, $this->items, $transactions); }); it('normalises checklist item text and rejects empty and too long text', function () { expect((new ChecklistItemText(" Tarkista valot \n"))->value)->toBe('Tarkista valot') ->and(fn () => new ChecklistItemText(' '))->toThrow(InvalidChecklistItemText::class) ->and(fn () => new ChecklistItemText(str_repeat('a', 256)))->toThrow(InvalidChecklistItemText::class); }); it('adds items to the end of the task checklist', function () { $this->add->execute($this->jobId, $this->taskId, 'Valot'); $this->add->execute($this->jobId, $this->taskId, 'Mikit'); expect($this->items->textsOf($this->taskId))->toBe(['Valot', 'Mikit']); }); it('does not touch the checklist of a task through another job', function () { $itemId = $this->add->execute($this->jobId, $this->taskId, 'Valot'); expect(fn () => $this->add->execute(99, $this->taskId, 'Mikit'))->toThrow(TaskNotFound::class) ->and(fn () => $this->remove->execute(99, $this->taskId, $itemId))->toThrow(TaskNotFound::class) ->and(fn () => $this->remove->execute($this->jobId, $this->taskId, 404))->toThrow(ChecklistItemNotFound::class); }); it('checks an item with who and when, keeps them on a second check and clears them on uncheck', function () { $itemId = $this->add->execute($this->jobId, $this->taskId, 'Valot'); $this->check->execute($this->jobId, $this->taskId, $itemId, true, 10); $this->check->execute($this->jobId, $this->taskId, $itemId, true, 12); $item = $this->items->items[$itemId]; expect($item->isDone())->toBeTrue() ->and($item->doneBy())->toBe(10) ->and($item->doneAt()?->format('Y-m-d H:i'))->toBe('2026-11-24 12:00'); $this->check->execute($this->jobId, $this->taskId, $itemId, false, 10); expect($this->items->items[$itemId]->isDone())->toBeFalse() ->and($this->items->items[$itemId]->doneBy())->toBeNull(); }); it('renames, moves and removes items', function () { $first = $this->add->execute($this->jobId, $this->taskId, 'Valot'); $second = $this->add->execute($this->jobId, $this->taskId, 'Mikit'); $this->rename->execute($this->jobId, $this->taskId, $first, 'Valot ja jalustat'); expect($this->move->execute($this->jobId, $this->taskId, $first, MoveDirection::Up))->toBeFalse() ->and($this->move->execute($this->jobId, $this->taskId, $second, MoveDirection::Down))->toBeFalse() ->and($this->move->execute($this->jobId, $this->taskId, $first, MoveDirection::Down))->toBeTrue() ->and($this->items->textsOf($this->taskId))->toBe(['Mikit', 'Valot ja jalustat']); $this->remove->execute($this->jobId, $this->taskId, $second); expect($this->items->textsOf($this->taskId))->toBe(['Valot ja jalustat']); });