Files
Toiminnanohjaus/tests/Browser/JobsAccessibilityTest.php
petriandClaude Sonnet 5.5 87e38260dc Show a task card's actions above tabs for notes, images and materials
The opened task card keeps its details and description at the top, then
the status, book hours, edit and remove actions, and below them tabs:
checklist and comments, images, and materials and machines. The tabs are
a project component (x-tabs) after the WAI-ARIA pattern, because
TallStackUI's tab ties its panels to missing ids and has no arrow keys.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-29 09:58:04 +02:00

445 lines
22 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Jobs\Application\Contracts\TaskImageFiles;
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\TaskImageModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->user = User::factory()->management()->create(['name' => 'Johanna Johto']);
$this->actingAs($this->user);
$this->customer = CustomerModel::factory()->create(['name' => 'Mainos Oy']);
$this->job = CustomerJobModel::factory()->create([
'name' => 'Messuvideo',
'customer_id' => $this->customer->id,
'responsible_user_id' => $this->user->id,
'priority' => 'immediate',
'due_on' => now()->subDay()->toDateString(),
'instructions' => 'Kuvaus klo 9.',
'quoted_amount_cents' => 450000,
]);
DB::table('customer_job_links')->insert(['customer_job_id' => $this->job->id, 'title' => 'Briiffi', 'url' => 'https://drive.example.test/b', 'sort_order' => 1]);
});
it('has no accessibility issues on the job pages', function (string $page, string $device, string $colorScheme) {
$url = match ($page) {
'list' => route('jobs.index'),
'new job' => route('jobs.create'),
'edit job' => route('jobs.edit', $this->job->id),
'job page' => route('jobs.show', $this->job->id),
};
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['list', 'new job', 'edit job', 'job page'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('shows the form errors without accessibility issues', function (string $colorScheme) {
$page = visit(route('jobs.create'));
$page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
$page->press('Tallenna')
->assertSee('Anna asiakastyön nimi.')
->assertSee('Valitse vähintään yksi palveluyksikkö.')
->assertNoAccessibilityIssues(level: 2);
})->with(['light', 'dark']);
it('finds and picks a customer, and adds and removes a tag, with the keyboard', function () {
visit(route('jobs.create'))
->type('#customer-search', 'Mainos')
->assertSee('1 osuma.')
->keys('[aria-label="Valitse Mainos Oy"]', 'Enter')
->assertSee('Vaihda asiakas')
->assertScript('document.activeElement.id', 'change-customer')
->type('#new-tag', 'messut')
->keys('#new-tag', 'Enter')
->assertSee('Tagi messut lisätty.')
->keys('[aria-label="Poista tagi messut"]', 'Enter')
->assertSee('Tagi messut poistettu.')
->assertScript('document.activeElement.id', 'new-tag')
->assertNoAccessibilityIssues(level: 2);
});
it('has no accessibility issues on the quick intake, also with errors', function (string $device, string $colorScheme) {
$visit = visit(route('jobs.quick'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2)
->press('Tallenna työ')
->assertSee('Valitse palveluyksikkö.')
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('takes in a job on a phone with the keyboard alone', function () {
$unit = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole();
visit(route('jobs.quick'))
->on()->mobile()
->type('#customer-search', 'Mainos')
->assertSee('1 osuma.')
->keys('[aria-label="Valitse Mainos Oy"]', 'Enter')
->assertScript('document.activeElement.id', 'change-customer')
->type('[wire\:model="form.name"]', 'Kevätkampanja')
->select('[wire\:model="form.service_unit_id"]', (string) $unit->id)
->keys('[wire\:model="form.name"]', 'Enter')
->assertSee('Kevätkampanja luotu.')
->assertScript('document.activeElement.id', 'quick-created')
->assertNoAccessibilityIssues(level: 2);
});
it('has no accessibility issues on the Kanban board and no sideways scrolling on a phone', function (string $device, string $colorScheme) {
CustomerJobModel::factory()->create(['name' => 'Tilattu työ', 'status' => 'order', 'responsible_user_id' => $this->user->id, 'customer_id' => $this->customer->id]);
$visit = visit(route('jobs.board'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee('Tilattu työ')
->assertScript('document.documentElement.scrollWidth <= window.innerWidth', true)
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('moves a card to another column with the keyboard', function () {
$select = '#job-status-'.$this->job->id;
visit(route('jobs.board'))
->assertScript('document.querySelector("#column-tentative").textContent.includes("Messuvideo")', true)
->select($select, 'order')
->assertSee('Työ '.$this->job->number.' Messuvideo siirretty tilaan Tilaus.')
->assertScript('document.querySelector("#column-order").textContent.includes("Messuvideo")', true)
->assertScript('document.activeElement.id', 'job-status-'.$this->job->id)
->assertNoAccessibilityIssues(level: 2);
expect($this->job->fresh()->status->value)->toBe('order');
});
it('moves a card by dragging it to another column', function () {
visit(route('jobs.board'))
->on()->desktop()
->drag('[wire\:sort\:item="'.$this->job->id.'"]', '#column-order ul')
->assertSee('siirretty tilaan Tilaus.');
expect($this->job->fresh()->status->value)->toBe('order');
});
it('has no accessibility issues on a job with tasks and on the task form', function (string $page, string $device, string $colorScheme) {
$this->job->update(['status' => 'order']);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
$task = TaskModel::factory()
->assignedTo([$this->user->id])
->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()]);
Storage::fake('local');
$stored = app(TaskImageFiles::class)->store(browserTestImage(), $task->id);
TaskImageModel::query()->create(['task_id' => $task->id, 'user_id' => $this->user->id, 'path' => $stored->path, 'thumbnail_path' => $stored->thumbnailPath, 'original_name' => 'valot.png', 'caption' => 'Valot paikallaan', 'width' => $stored->width, 'height' => $stored->height]);
$url = match ($page) {
'job page' => route('jobs.show', $this->job->id),
'new task' => route('jobs.tasks.create', $this->job->id),
'edit task' => route('jobs.tasks.edit', [$this->job->id, $task->id]),
};
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
if ($page === 'job page') {
$visit->click('[data-tasks-expand-all]')
->click('#history-toggle')
->assertVisible('#task-status-'.$task->id);
}
$visit->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['job page', 'new task', 'edit task'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('changes a task status and removes a task 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ä']);
visit(route('jobs.show', $this->job->id))
->keys('#task-toggle-'.$task->id, 'Enter')
->select('#task-status-'.$task->id, 'in_progress')
->assertSee('Tehtävän Kuvauspäivä tila on nyt Työn alla.')
->assertScript('document.activeElement.id', 'task-status-'.$task->id)
->assertAttribute('#task-toggle-'.$task->id, 'aria-expanded', 'true')
->keys('[aria-label="Poista tehtävä Kuvauspäivä"]', 'Enter')
->assertScript('document.getElementById("remove-task-dialog").open', true)
->assertScript('document.getElementById("remove-task-dialog").contains(document.activeElement)', true)
->click('#remove-task-dialog [wire\\:click="removeTask"]')
->assertSee('Tehtävä Kuvauspäivä poistettu.')
->assertScript('document.activeElement.id', 'tasks-heading');
});
it('puts the task actions above the tabs and moves between the tabs with the arrow keys', function (string $device, string $colorScheme) {
$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ä']);
$tabs = 'task-'.$task->id.'-tabs';
$visit = visit(route('jobs.show', $this->job->id));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->click('#task-toggle-'.$task->id)
->assertScript("!! (document.getElementById('task-status-{$task->id}').compareDocumentPosition(document.getElementById('{$tabs}-tab-notes')) & Node.DOCUMENT_POSITION_FOLLOWING)", true)
->assertAttribute('#'.$tabs.'-tab-notes', 'aria-selected', 'true')
->assertVisible('#checklist-new-'.$task->id)
->assertMissing('#'.$tabs.'-panel-images')
->keys('#'.$tabs.'-tab-notes', 'ArrowRight')
->assertScript('document.activeElement.id', $tabs.'-tab-images')
->assertAttribute('#'.$tabs.'-tab-images', 'aria-selected', 'true')
->assertAttribute('#'.$tabs.'-tab-notes', 'tabindex', '-1')
->assertVisible('#'.$tabs.'-panel-images')
->assertMissing('#'.$tabs.'-panel-notes')
->keys('#'.$tabs.'-tab-images', 'End')
->assertScript('document.activeElement.id', $tabs.'-tab-materials')
->assertSee('Tällä tehtävällä ei ole materiaaleja eikä koneita.')
->keys('#'.$tabs.'-tab-materials', 'ArrowRight')
->assertScript('document.activeElement.id', $tabs.'-tab-notes')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('shows task cards collapsed, opens several at once and expands or collapses them all', function () {
$this->job->update(['status' => 'order']);
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
$shoot = TaskModel::factory()
->assignedTo([$this->user->id])
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä', 'due_on' => '2026-12-04']);
$edit = TaskModel::factory()
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Editointi']);
$page = visit(route('jobs.show', $this->job->id))
->assertSee('Johanna Johto')
->assertSee('4.12.2026')
->assertAttribute('#task-toggle-'.$shoot->id, 'aria-expanded', 'false')
->assertMissing('#task-status-'.$shoot->id)
->keys('#task-toggle-'.$shoot->id, 'Enter')
->assertAttribute('#task-toggle-'.$shoot->id, 'aria-expanded', 'true')
->assertVisible('#task-status-'.$shoot->id)
->keys('#task-toggle-'.$edit->id, 'Enter')
->assertVisible('#task-status-'.$shoot->id)
->assertVisible('#task-status-'.$edit->id)
->click('[data-tasks-collapse-all]')
->assertSee('Kaikki tehtävät supistettu.')
->assertMissing('#task-status-'.$shoot->id)
->assertMissing('#task-status-'.$edit->id)
->click('[data-tasks-expand-all]')
->assertSee('Kaikki tehtävät laajennettu.')
->assertAttribute('#task-toggle-'.$shoot->id, 'aria-expanded', 'true')
->assertAttribute('#task-toggle-'.$edit->id, 'aria-expanded', 'true');
$page->assertAttribute('#history-toggle', 'aria-expanded', 'false')
->assertMissing('#history-panel')
->keys('#history-toggle', 'Enter')
->assertAttribute('#history-toggle', 'aria-expanded', 'true')
->assertVisible('#history-panel')
->assertNoAccessibilityIssues(level: 2);
});
it('adds, checks, renames, moves and removes checklist items 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('#checklist-new-'.$task->id, 'Valot')
->keys('#checklist-new-'.$task->id, 'Enter')
->assertSee('Kohta Valot lisätty.')
->type('#checklist-new-'.$task->id, 'Mikit')
->keys('#checklist-new-'.$task->id, 'Enter')
->assertSee('Kohta Mikit lisätty.');
[$lights, $mics] = ChecklistItemModel::query()->orderBy('id')->pluck('id')->all();
$page->keys('#checklist-item-'.$lights, 'Space')
->assertSee('Kohta Valot merkitty tehdyksi.')
->assertSee('(1/2 tehty)')
->keys('#checklist-rename-'.$lights, 'Enter')
->assertScript('document.activeElement.id', 'checklist-edit-'.$lights)
->type('#checklist-edit-'.$lights, 'Valot ja jalustat')
->keys('#checklist-edit-'.$lights, 'Enter')
->assertSee('Kohta Valot ja jalustat tallennettu.')
->assertScript('document.activeElement.id', 'checklist-rename-'.$lights)
->keys('#checklist-move-up-'.$mics, 'Enter')
->assertSee('Kohta Mikit siirretty ylöspäin.')
->assertScript('document.activeElement.id', 'checklist-move-up-'.$mics)
->keys('[aria-label="Poista kohta Mikit"]', 'Enter')
->assertSee('Kohta Mikit poistettu.')
->assertScript('document.activeElement.id', 'checklist-new-'.$task->id)
->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);
});
/**
* A small PNG file for sending as a task image.
*/
function browserTestImage(): string
{
$image = imagecreatetruecolor(120, 80);
imagefill($image, 0, 0, (int) imagecolorallocate($image, 30, 120, 200));
$path = tempnam(sys_get_temp_dir(), 'img').'.png';
imagepng($image, $path);
return $path;
}
it('recaptions and removes a task image with the keyboard', function () {
Storage::fake('local');
$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ä']);
// Sending is covered by the feature tests: the browser plugin's test server keeps a
// multipart field named files[] under that literal key, so Livewire receives no upload.
$stored = app(TaskImageFiles::class)->store(browserTestImage(), $task->id);
TaskImageModel::query()->create(['task_id' => $task->id, 'user_id' => $this->user->id, 'path' => $stored->path, 'thumbnail_path' => $stored->thumbnailPath, 'original_name' => 'valot.png', 'caption' => 'Valot paikallaan', 'width' => $stored->width, 'height' => $stored->height]);
$page = visit(route('jobs.show', $this->job->id))
->click('#task-toggle-'.$task->id)
->click('#task-'.$task->id.'-tabs-tab-images')
->assertVisible('img[alt="Valot paikallaan"]')
->assertScript("document.querySelector('img[alt=\"Valot paikallaan\"]').naturalWidth > 0", true)
->assertSeeIn('#task-'.$task->id.'-title + dl', 'Kuvat:');
$imageId = TaskImageModel::query()->sole()->id;
$page->keys('#image-edit-button-'.$imageId, 'Enter')
->assertScript('document.activeElement.id', 'image-caption-edit-'.$imageId)
->type('#image-caption-edit-'.$imageId, 'Lavasteet')
->keys('#image-caption-edit-'.$imageId, 'Enter')
->assertSee('Kuvateksti tallennettu.')
->assertScript('document.activeElement.id', 'image-edit-button-'.$imageId)
->keys('[aria-label="Poista kuva: Lavasteet"]', 'Enter')
->assertScript("document.getElementById('remove-image-dialog-{$task->id}').open", true)
->assertNoAccessibilityIssues(level: 2)
->click('#remove-image-confirm-'.$task->id)
->assertSee('Kuva poistettu.')
->assertScript('document.activeElement.id', 'image-new-'.$task->id)
->assertNoAccessibilityIssues(level: 2);
expect(TaskImageModel::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();
$templateId = app(AddWorkflowTemplate::class)->execute(new WorkflowTemplateData('Lyhyt video', $workType->id, [
new WorkflowStepData('Suunnittelu', null, WorkTypeModel::query()->where('name', 'suunnittelu')->sole()->id),
new WorkflowStepData('Kuvaus'),
]));
$visit = visit(route('jobs.tasks.from-template', $this->job->id));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2)
->keys('[value="'.$templateId.'"]', 'Space')
->assertSee('Pohjan Lyhyt video tehtävät')
->assertNoAccessibilityIssues(level: 2)
->resize(320, 900)
->assertScript('document.documentElement.scrollWidth <= window.innerWidth', true)
->type('#row-1-hours', '2,5')
->keys('main form button[type="submit"]', 'Enter')
->assertSee('Lisättiin 2 tehtävää pohjasta Lyhyt video (videokuvaus).')
->assertSee('Suunnittelu')
// The page was reached with wire:navigate: wait until Livewire's progress bar (role="bar", not an ARIA role) is gone.
->assertMissing('#nprogress .bar')
->assertNoAccessibilityIssues(level: 2);
expect(TaskModel::query()->where('customer_job_id', $this->job->id)->orderBy('id')->pluck('estimated_hours')->map(fn ($hours) => $hours === null ? null : (float) $hours)->all())->toBe([null, 2.5]);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);