Files
Toiminnanohjaus/tests/Browser/MachinesAccessibilityTest.php
T
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

118 lines
5.7 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
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 App\Modules\Machines\Application\UseCases\MachineWorkList;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineCounterModel;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineModel;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MaintenanceItemModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->user = User::factory()->management()->create(['name' => 'Johtaja']);
$this->actingAs($this->user);
$print = ServiceUnitModel::query()->where('name', 'Painotuotanto')->sole();
$print->update(['uses_stock' => true]);
$this->machine = MachineModel::factory()->inUnits([$print->id])->create(['name' => 'Suurkuvatulostin']);
MachineModel::factory()->inUnits([$print->id])->create(['name' => 'Tarraleikkuri', 'type' => 'cutter']);
$this->job = CustomerJobModel::factory()->create(['name' => 'Messut', 'status' => 'order', 'instructions' => 'Kiiltävä laminointi']);
DB::table('customer_job_service_unit')->where('customer_job_id', $this->job->id)->update(['service_unit_id' => $print->id]);
$this->task = TaskModel::factory()->create([
'customer_job_id' => $this->job->id,
'work_type_id' => WorkTypeModel::query()->where('name', 'painotyö')->value('id'),
'title' => 'Banderolli',
'description' => 'Kaksi kappaletta',
]);
app(MachineWorkList::class)->planTask($this->task->id, $this->machine->id, null);
$counter = MachineCounterModel::query()->create(['machine_id' => $this->machine->id, 'name' => 'Tulosteet', 'unit' => 'piece', 'sort_order' => 1]);
MaintenanceItemModel::query()->create([
'machine_id' => $this->machine->id, 'name' => 'Pään puhdistus', 'machine_counter_id' => $counter->id, 'interval_milli' => 1_000_000,
'period' => 'day', 'period_count' => 1, 'starts_on' => now()->subDays(2)->toDateString(), 'warning_percent' => 90,
]);
});
it('has no accessibility issues on the machine pages', function (string $page, string $device, string $colorScheme) {
$url = match ($page) {
'index' => route('machines.index'),
'show' => route('machines.show', $this->machine->id),
'form' => route('machines.edit', $this->machine->id),
'job' => route('jobs.show', $this->job->id).'#task-'.$this->task->id,
'maintenance' => route('machines.maintenance.create', $this->machine->id),
};
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
if ($page === 'job') {
$visit->click('#task-'.$this->task->id.'-tabs-tab-materials');
}
$visit->assertSee($page === 'form' ? __('machines.form.edit_title') : 'Suurkuvatulostin')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['index', 'show', 'form', 'job', 'maintenance'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('moves a task to another machine with the keyboard from the work list', function () {
visit(route('machines.show', $this->machine->id))
->assertSee('Banderolli')
->click(__('machines.show.reschedule'))
->assertNoAccessibilityIssues(level: 2)
->select('#edit-machine', 'Tarraleikkuri')
->click(__('machines.task.save'))
->assertSee('Tehtävä siirretty koneen Tarraleikkuri työlistalle')
->assertDontSee('Kiiltävä laminointi');
});
it('records maintenance done with the keyboard', function () {
visit(route('machines.show', $this->machine->id))
->assertSee('Huolto myöhässä')
->click(__('machines.maintenance.done'))
->fill('#record-note', 'Puhdistettu')
->click(__('machines.maintenance.confirm_done'))
->assertSee('Huolto Pään puhdistus kirjattu.')
->assertSee('Kunnossa')
->assertNoAccessibilityIssues(level: 2);
});
it('has no accessibility issues on the machine console', function (string $device, string $colorScheme) {
$visit = visit(route('machines.console', $this->machine->id));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee('Banderolli')
->assertSee(__('machines.console.maintenance_late', ['name' => 'Pään puhdistus']))
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('refreshes the console on a tablet and keeps focus on the button', function () {
visit(route('machines.console', $this->machine->id))
->resize(1024, 768)
->click('#console-refresh')
->assertSee('Päivitetty klo')
->assertScript('document.activeElement.id', 'console-refresh')
->click('[aria-label="'.__('machines.console.select_named', ['title' => 'Banderolli']).'"]')
->assertSee(__('machines.console.selected', ['title' => 'Banderolli']))
->assertNoAccessibilityIssues(level: 2);
});