Add comments to tasks

Everyone who may change a task's status (attached subcontractors too)
comments on it on the job page. Authors edit and remove their own
comments; admin and management may remove anyone's
(jobs.remove-any-task-comment). Edited comments show when they were
edited, and task cards show the number of comments.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 07:31:53 +02:00
co-authored by Claude Sonnet 5.5
parent 60cab4b871
commit 4fb8ea1c5f
29 changed files with 1354 additions and 4 deletions
+36
View File
@@ -9,6 +9,7 @@ use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskCommentModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
@@ -161,6 +162,8 @@ it('has no accessibility issues on a job with tasks and on the task form', funct
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä', 'due_on' => now()->subDay()->toDateString(), 'estimated_hours' => 6]);
ChecklistItemModel::query()->create(['task_id' => $task->id, 'text' => 'Valot', 'sort_order' => 1, 'done_at' => now(), 'done_by' => $this->user->id]);
ChecklistItemModel::query()->create(['task_id' => $task->id, 'text' => 'Mikit', 'sort_order' => 2]);
TaskCommentModel::query()->create(['task_id' => $task->id, 'user_id' => $this->user->id, 'body' => 'Valot ok.
Mikit puuttuu.', 'edited_at' => now()]);
$url = match ($page) {
'job page' => route('jobs.show', $this->job->id),
@@ -279,6 +282,39 @@ it('adds, checks, renames, moves and removes checklist items with the keyboard',
->assertNoAccessibilityIssues(level: 2);
});
it('adds, edits and removes a task comment with the keyboard', function () {
$this->job->update(['status' => 'order']);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
$task = TaskModel::factory()
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä']);
$page = visit(route('jobs.show', $this->job->id))
->click('#task-toggle-'.$task->id)
->type('#comment-new-'.$task->id, 'Valot ok.')
->keys('[aria-label="Lisää kommentti tehtävälle Kuvauspäivä"]', 'Enter')
->assertSee('Kommentti lisätty.')
->assertSeeIn('#task-'.$task->id.'-title + dl', 'Kommentit:');
$commentId = TaskCommentModel::query()->sole()->id;
$page->keys('#comment-edit-button-'.$commentId, 'Enter')
->assertScript('document.activeElement.id', 'comment-edit-'.$commentId)
->type('#comment-edit-'.$commentId, 'Valot ja mikit ok.')
->click('Tallenna')
->assertSee('Kommentti tallennettu.')
->assertSee('Valot ja mikit ok.')
->assertScript('document.activeElement.id', 'comment-edit-button-'.$commentId)
->keys('[aria-label^="Poista kommentti (Johanna Johto"]', 'Enter')
->assertScript("document.getElementById('remove-comment-dialog-{$task->id}').open", true)
->assertNoAccessibilityIssues(level: 2)
->click('#remove-comment-confirm-'.$task->id)
->assertSee('Kommentti poistettu.')
->assertScript('document.activeElement.id', 'comment-new-'.$task->id)
->assertNoAccessibilityIssues(level: 2);
expect(TaskCommentModel::query()->count())->toBe(0);
});
it('adds tasks from a workflow template with the keyboard, without accessibility issues', function (string $device, string $colorScheme) {
$this->job->update(['status' => 'order']);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();