Files
Toiminnanohjaus/tests/Browser/QuickSaleOrdersAccessibilityTest.php
T
petriandClaude Sonnet 5.5 701f05780f Change a quick sale order before making starts
An unpaid order whose lines have no completed step can be reopened in the
cart from the open orders list; saving replaces its lines with current
prices and processes, moves the machine work list rows and keeps the
pickup number. Keyboard browser tests cover changing and cancelling an
order and moving production steps.

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

117 lines
6.0 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);
$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);
});