Files
Toiminnanohjaus/tests/Browser/TaskCalendarAccessibilityTest.php
T
petriandClaude Opus 5.5 18598cc08e Give tasks one assignee and members, and schedule template tasks to due dates
- A task now has one optional assignee (tasks.assignee_user_id), whose
  calendar row it is on and whose days its estimate books, and members
  (task_members) who see it among their own jobs and in the weekly sheet
  but get no bookings. A migration moves existing assignees over: the one
  with most booked time becomes the assignee, the others members.
- Adding tasks from a workflow template asks for each step's assignee and,
  by default, schedules tasks with a due date to end on it, booking the
  estimate backwards from the due date (not before today); what does not
  fit runs past the due date and is reported as late.
- The task calendar leaves quick sale tasks out of the unscheduled list,
  shows a bar's job details in a popover on hover and focus, and shows the
  day load on its own grid line.
- The template table stacks its cells on narrow screens to reflow at 320 px.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 19:01:11 +02:00

109 lines
4.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->user = User::factory()->management()->create(['name' => 'Johanna Johto']);
$this->other = User::factory()->create(['name' => 'Aino Ahkera']);
$this->actingAs($this->user);
$job = CustomerJobModel::factory()->create(['name' => 'Messuvideo', 'status' => 'order', 'responsible_user_id' => $this->user->id]);
$workType = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
$this->task = TaskModel::factory()->assignedTo([$this->user->id])->create([
'customer_job_id' => $job->id,
'work_type_id' => $workType->id,
'title' => 'Leikkaus',
'estimated_hours' => 4,
'due_on' => now()->addDay()->toDateString(),
'planned_from' => now()->toDateString(),
'planned_to' => now()->addDays(2)->toDateString(),
]);
TaskModel::factory()->assignedTo([$this->other->id])->create(['customer_job_id' => $job->id, 'work_type_id' => $workType->id, 'title' => 'Värimäärittely']);
});
it('has no accessibility issues on the task calendar', function (string $device, string $colorScheme) {
$visit = visit(route('jobs.calendar'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertNoJavaScriptErrors()
->assertSee('Leikkaus')
->assertSee('Värimäärittely')
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('reschedules a task with the keyboard and returns focus to its bar', function () {
$key = $this->task->id.'-'.$this->user->id;
visit(route('jobs.calendar'))
->on()->desktop()
->keys('#bar-'.$key, 'Enter')
->assertSee('Tehtävän aikataulu')
->assertNoAccessibilityIssues(level: 2)
->type('#task-schedule-dialog [wire\:model="plannedFrom"]', now()->addDay()->format('Y-m-d'))
->type('#task-schedule-dialog [wire\:model="plannedTo"]', now()->addDays(3)->format('Y-m-d'))
->press('#task-schedule-dialog [wire\:click="saveDialog"]')
->assertSee('Tehtävä Leikkaus: Johanna Johto '.now()->addDay()->format('j.n.Y').'–'.now()->addDays(3)->format('j.n.Y').'.')
->assertScript('document.activeElement.id', 'bar-'.$key);
expect($this->task->refresh()->planned_from?->format('Y-m-d'))->toBe(now()->addDay()->toDateString());
});
it('shows the job details of a bar on hover and focus, and closes them with Escape', function (string $colorScheme) {
$key = $this->task->id.'-'.$this->user->id;
$open = "document.getElementById('bar-info-{$key}').matches(':popover-open')";
$visit = visit(route('jobs.calendar'))->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->hover('#bar-'.$key)
->assertScript($open, true)
->assertSee('Messuvideo')
->assertSee('Johanna Johto')
->assertNoAccessibilityIssues(level: 2)
->hover('#bar-info-'.$key)
->assertScript($open, true)
->keys('#bar-'.$key, 'Escape')
->assertScript($open, false)
->keys('#bar-'.$key, 'Tab')
->keys('#bar-'.$key, 'Shift')
->assertScript($open, true)
->assertNoJavaScriptErrors();
})->with(['light', 'dark']);
it('moves a task to another person by dragging its bar', function () {
// The bar (today – today + 2) is grabbed at its middle day, so dropping it
// on today + 4 moves it three days later.
$day = now()->addDays(4)->toDateString();
visit(route('jobs.calendar'))
->on()->desktop()
->drag('#bar-'.$this->task->id.'-'.$this->user->id, '[data-calendar-day="'.$day.'"][data-calendar-user="'.$this->other->id.'"]')
->assertSee('Tehtävä Leikkaus: Aino Ahkera');
expect($this->task->refresh()->planned_from?->format('Y-m-d'))->toBe(now()->addDays(3)->toDateString())
->and($this->task->assignee_user_id)->toBe($this->other->id);
});
it('has no accessibility issues on the holidays page', function (string $colorScheme) {
$this->actingAs(User::factory()->admin()->create());
$visit = visit(route('settings.holidays'));
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertNoJavaScriptErrors()
->assertSee('Itsenäisyyspäivä')
->assertNoAccessibilityIssues(level: 2);
})->with(['light', 'dark']);