Files
Toiminnanohjaus/tests/Browser/InventoryAccessibilityTest.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

124 lines
5.8 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\Inventory\Infrastructure\Persistence\Eloquent\InventoryCountModel;
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockItemGroupModel;
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockItemModel;
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockMovementModel;
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' => 'Johtaja']);
$this->actingAs($this->user);
ServiceUnitModel::query()->where('name', 'Painotuotanto')->update(['uses_stock' => true]);
$group = StockItemGroupModel::factory()->create(['name' => 'Paperit']);
$this->item = StockItemModel::factory()->create([
'stock_item_group_id' => $group->id,
'name' => 'Valokuvapaperi',
'unit' => 'sheet',
'reorder_level_milli' => 50_000,
'average_cost_hundredths' => 5_000,
]);
StockMovementModel::query()->create([
'stock_item_id' => $this->item->id, 'kind' => 'purchase', 'quantity_milli' => 40_000, 'unit_cost_hundredths' => 5_000,
'value_cents' => 2_000, 'occurred_on' => now()->toDateString(), 'recorded_at' => now(), 'user_id' => $this->user->id,
]);
});
it('has no accessibility issues on the stock pages and no sideways scrolling', function (string $page, string $device, string $colorScheme) {
$url = match ($page) {
'index' => route('inventory.index'),
'item' => route('inventory.items.show', $this->item->id),
'form' => route('inventory.items.edit', $this->item->id),
'groups' => route('inventory.groups'),
};
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee(match ($page) {
'groups' => 'Paperit', 'form' => __('inventory.form.edit_title'), default => 'Valokuvapaperi'
})
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['index', 'item', 'form', 'groups'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('reverses a movement in a dialog that returns focus', function () {
visit(route('inventory.items.show', $this->item->id))
->assertSee(__('inventory.status.reorder'))
->click(__('inventory.item.reverse'))
->assertSee(__('inventory.item.reverse_title'))
->assertNoAccessibilityIssues(level: 2)
->click(__('inventory.item.reverse_confirm'))
->assertSee('Vastakirjaus kirjattu')
->assertScript('document.activeElement.id', 'item-status');
});
it('records material on a task card with the keyboard and without accessibility issues', function (string $device, string $colorScheme) {
$print = ServiceUnitModel::query()->where('name', 'Painotuotanto')->sole();
$print->update(['uses_stock' => true]);
$job = CustomerJobModel::factory()->create(['name' => 'Ikkunateippaus', 'status' => 'order']);
DB::table('customer_job_service_unit')->where('customer_job_id', $job->id)->update(['service_unit_id' => $print->id]);
$task = TaskModel::factory()->create([
'customer_job_id' => $job->id,
'work_type_id' => WorkTypeModel::query()->where('name', 'asennus')->value('id'),
'title' => 'Asennus',
]);
$visit = visit(route('jobs.show', $job->id).'#task-'.$task->id);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->click('#task-'.$task->id.'-tabs-tab-materials')
->assertSee(__('inventory.task.title'))
->fill('#task-'.$task->id.'-material-search', 'valoku')
->assertSee('1 osuma')
->click('[wire\:click="selectItem('.$this->item->id.')"]')
->fill('#task-'.$task->id.'-material-quantity', '2')
->keys('#task-'.$task->id.'-material-quantity', 'Enter')
->assertSee('Kirjattu Valokuvapaperi 2')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('has no accessibility issues on the stock count pages and saves a counted quantity', function (string $device, string $colorScheme) {
$count = InventoryCountModel::query()->create([
'counted_on' => now()->toDateString(), 'status' => 'open', 'started_by' => $this->user->id,
]);
foreach ([route('inventory.counts'), route('inventory.counts.show', $count->id)] as $url) {
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee(__('inventory.counts.title'))->assertNoJavaScriptErrors()->assertNoAccessibilityIssues(level: 2);
}
visit(route('inventory.counts.show', $count->id))
->fill('#counted-'.$this->item->id, '38')
->keys('#counted-'.$this->item->id, 'Tab')
->assertSee('Valokuvapaperi: laskettu 38')
->click(__('inventory.counts.confirm'))
->assertSee(__('inventory.counts.confirm_title'))
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);