Files
Toiminnanohjaus/tests/Browser/QuickSaleOrdersAccessibilityTest.php
T
petriandClaude Sonnet 5.5 32c33e2a64 Give the machine console its own session with PIN sign-in, make counters cumulative
The console under console/ has its own session cookie and console guard
(UseConsoleSession), so signing out or changing user there leaves the
normal interface alone. Links open it in a new window through a one-time
handoff key; a signed-out console asks for a PIN code or password on its
own login page. Users set their 4-6 digit PIN on the profile's PIN page,
and the console's change user dialog takes it on a keypad; five wrong
PINs lock PIN sign-in for 15 minutes.

Machine counters are cumulative: users record how much a job used and it
is added to the latest reading. A maintenance record restarts the whole
counter interval from the reading at the record.

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

119 lines
6.1 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ProductModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockItemModel;
use App\Modules\Machines\Application\DTOs\ProductionStepData;
use App\Modules\Machines\Application\UseCases\SaveProductionProcess;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineModel;
use App\Modules\Sales\Application\DTOs\OrderData;
use App\Modules\Sales\Application\UseCases\QuickSaleOrders;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->user = User::factory()->management()->create(['name' => 'Johtaja']);
$this->actingAs($this->user);
// The machine console has its own session and guard.
$this->actingAs($this->user, 'console');
$print = ServiceUnitModel::query()->where('name', 'Painotuotanto')->sole();
$print->update(['uses_stock' => true]);
$printing = WorkTypeModel::query()->where('name', 'painotyö')->sole();
$this->printer = MachineModel::factory()->inUnits([$print->id])->create(['name' => 'Tarratulostin']);
$this->sticker = ProductModel::factory()->consumer()->create(['name' => 'Tarra', 'price_cents' => 1000, 'work_type_id' => $printing->id]);
$vinyl = StockItemModel::factory()->create(['name' => 'Tarramateriaali', 'unit' => 'square_metre']);
app(SaveProductionProcess::class)->execute($this->sticker->id, [
new ProductionStepData($this->printer->id, '0,25', $printing->id, [['stockItemId' => $vinyl->id, 'quantity' => '0,5']]),
new ProductionStepData(null, '0', $printing->id),
]);
app(QuickSaleOrders::class)->send($this->user->id, new OrderData([$this->sticker->id => 2], customerName: 'Matti'));
});
it('has no accessibility issues on the pages of quick sale orders', function (string $page, string $device, string $colorScheme) {
$url = match ($page) {
'sell' => route('sales.sell'),
'product' => route('catalog.products.edit', $this->sticker->id),
'console' => route('machines.console', $this->printer->id),
};
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee($page === 'product' ? __('machines.process.title') : 'Nro 1')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['sell', 'product', 'console'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('completes an order on the console and pays it on the quick sale page with the keyboard', function () {
visit(route('machines.console', $this->printer->id))
->click('[aria-label="'.__('machines.console.order_finish_named', ['number' => 1]).'"]')
->assertSee(__('machines.console.order_materials'))
->assertNoAccessibilityIssues(level: 2)
->click(__('machines.console.confirm_order'))
->assertSee('Tilauksen 1 tuote Tarra kuitattu.');
visit(route('sales.sell'))
->assertSee('vaihe 2/2')
->click('[aria-label="'.__('sales.orders.complete_step_named', ['number' => 1, 'product' => 'Tarra']).'"]')
->click(__('sales.orders.complete'))
->assertSee('Tilauksen 1 tuote Tarra on valmis.')
->click('[aria-label="'.__('sales.orders.pay_named', ['number' => 1]).'"]')
->assertNoAccessibilityIssues(level: 2)
->click(__('sales.orders.take_payment'))
->assertSee('Tilaus 1 maksettu')
->assertSee('Avaa kuitti');
});
it('changes an order with the keyboard, moving focus to the cart', function () {
visit(route('sales.sell'))
->keys('[aria-label="'.__('sales.orders.change_named', ['number' => 1]).'"]', 'Enter')
->assertSee(__('sales.orders.editing_notice', ['number' => 1]))
->assertScript('document.activeElement.id', 'cart-heading')
->assertSee(__('sales.orders.save_change'))
->assertNoAccessibilityIssues(level: 2)
->keys('#stop-editing', 'Enter')
->assertScript('document.activeElement.id', 'cart-heading')
->assertDontSee(__('sales.orders.editing_notice', ['number' => 1]))
->keys('[aria-label="'.__('sales.orders.change_named', ['number' => 1]).'"]', 'Enter')
->keys('#order-customer-name', 'Control+a')
->type('#order-customer-name', 'Liisa')
->keys('#order-customer-name', 'Enter')
->assertSee('Tilaus 1 muutettu')
->assertSee('Liisa');
});
it('cancels an order in a dialog that takes and returns focus', function () {
$cancel = '[aria-label="'.__('sales.orders.cancel_named', ['number' => 1]).'"]';
visit(route('sales.sell'))
->keys($cancel, 'Enter')
->assertScript('document.getElementById("cancel-order-dialog").open', true)
->assertScript('document.getElementById("cancel-order-dialog").contains(document.activeElement)', true)
->assertNoAccessibilityIssues(level: 2)
->keys('#cancel-order-dialog', 'Escape')
->assertScript('document.getElementById("cancel-order-dialog").open', false)
->assertScript('document.activeElement.getAttribute("aria-label")', __('sales.orders.cancel_named', ['number' => 1]))
->keys($cancel, 'Enter')
->click('#cancel-order-dialog button[wire\:click="cancel"]')
->assertSee('Tilaus 1 peruttu.')
->assertScript('document.activeElement.id', 'orders-status');
});
it('moves a production step with the keyboard, keeping focus', function () {
visit(route('catalog.products.edit', $this->sticker->id))
->keys('[aria-label="'.__('catalog.workflows.move_up_named', ['number' => 2]).'"]', 'Enter')
->assertScript('document.activeElement.getAttribute("aria-label")', __('catalog.workflows.move_up_named', ['number' => 1]))
->assertNoAccessibilityIssues(level: 2);
});