Files
Toiminnanohjaus/tests/Browser/TaskCalendarAccessibilityTest.php
T
petriandClaude Sonnet 5.5 912b4ae1b5 Colour overloaded days and late tasks in the task calendar
Days over the daily capacity are amber and late task bars red, next to
the existing icon and text.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-25 11:00:36 +02:00

123 lines
5.4 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;
use Illuminate\Support\Facades\DB;
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) {
// A day over the daily capacity and a late task (Leikkaus ends after its due date) get warning colours.
DB::table('task_bookings')->insert([
['task_id' => $this->task->id, 'user_id' => $this->user->id, 'day' => now()->toDateString(), 'minutes' => 600],
['task_id' => $this->task->id, 'user_id' => $this->user->id, 'day' => now()->addDays(2)->toDateString(), 'minutes' => 60],
]);
$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')
->assertSee('Myöhässä');
// Phones show an agenda list without the daily load.
if ($device === 'desktop') {
$visit->assertSee('10 / 7,5 h');
}
$visit->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']);