actingAs(User::factory()->create()); }); it('has no accessibility issues on the customer pages', function (string $routeName, string $device, string $colorScheme) { $customer = CustomerModel::factory()->company('0737546-2')->create(['name' => 'Mainos Oy']); $page = visit($routeName === 'customers.edit' ? route($routeName, $customer->id) : route($routeName)); $page = $device === 'mobile' ? $page->on()->mobile() : $page->on()->desktop(); $page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode(); $page->assertNoJavaScriptErrors() ->assertNoAccessibilityIssues(level: 2); })->with([ 'list' => 'customers.index', 'create' => 'customers.create', 'edit' => 'customers.edit', ])->with([ 'desktop, light' => ['desktop', 'light'], 'desktop, dark' => ['desktop', 'dark'], 'mobile, light' => ['mobile', 'light'], 'mobile, dark' => ['mobile', 'dark'], ]); it('shows form errors without accessibility issues', function (string $colorScheme) { $page = visit(route('customers.create')); $page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode(); $page->fill('[wire\\:model="form.name"]', 'Mainos Oy') ->fill('[wire\\:model="form.business_id"]', '0737546-3') ->press('Tallenna') ->assertSee('Y-tunnus ei ole kelvollinen.') ->assertNoAccessibilityIssues(level: 2); })->with(['light', 'dark']); it('creates a customer with the keyboard alone', function () { visit(route('customers.create')) ->keys('html > body', 'Tab') ->assertScript('document.activeElement.textContent.trim()', 'Siirry pääsisältöön') ->keys('a[href="#main-content"]', 'Enter') ->keys('#main-content', 'Tab') ->assertScript('document.activeElement.getAttribute("wire:model")', 'form.name') ->type('[wire\\:model="form.name"]', 'Mainos Oy') ->keys('[wire\\:model="form.name"]', 'Enter') ->assertPathBeginsWith('/customers/') ->assertSee('Asiakas Mainos Oy lisätty.'); }); it('has no accessibility issues on the customer page and the contact and billing unit forms', function (string $page, string $device, string $colorScheme) { $customer = CustomerModel::factory()->company('0737546-2')->create(['name' => 'Mainos Oy']); $contact = CustomerContactModel::factory()->create([ 'customer_id' => $customer->id, 'name' => 'Maija Meikäläinen', 'title' => 'Markkinointipäällikkö', 'phone' => '040 123 4567', 'email' => 'maija@example.test', 'note' => 'Soita aamupäivisin.', ]); $billingUnit = BillingUnitModel::factory()->eInvoice()->create(['customer_id' => $customer->id, 'name' => 'Mainos Oy, markkinointi', 'reference' => 'PO-42']); $url = match ($page) { 'customer page' => route('customers.show', $customer->id), 'new contact' => route('customers.contacts.create', $customer->id), 'edit contact' => route('customers.contacts.edit', [$customer->id, $contact->id]), 'new billing unit' => route('customers.billing-units.create', $customer->id), 'edit billing unit' => route('customers.billing-units.edit', [$customer->id, $billingUnit->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([ 'customer page', 'new contact', 'edit contact', 'new billing unit', 'edit billing unit', ])->with([ 'desktop, light' => ['desktop', 'light'], 'desktop, dark' => ['desktop', 'dark'], 'mobile, light' => ['mobile', 'light'], 'mobile, dark' => ['mobile', 'dark'], ]); it('shows billing unit errors without accessibility issues', function (string $colorScheme) { $customer = CustomerModel::factory()->create(['name' => 'Mainos Oy']); $page = visit(route('customers.billing-units.create', $customer->id)); $page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode(); $page->fill('[wire\:model="form.e_invoice_address"]', '003712345678') ->press('Tallenna') ->assertSee('Anna välittäjätunnus, koska verkkolaskuosoite on annettu.') ->assertNoAccessibilityIssues(level: 2); })->with(['light', 'dark']); it('removes a contact with the keyboard, in a dialog that keeps and returns focus', function (string $colorScheme) { $customer = CustomerModel::factory()->create(['name' => 'Mainos Oy']); CustomerContactModel::factory()->create(['customer_id' => $customer->id, 'name' => 'Maija']); CustomerContactModel::factory()->create(['customer_id' => $customer->id, 'name' => 'Pekka']); $page = visit(route('customers.show', $customer->id)); $page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode(); $removeMaija = '[aria-label="Poista yhteyshenkilö Maija"]'; // Cancel: the dialog opens with focus inside it, and Escape returns focus to the button. $page->keys($removeMaija, 'Enter') ->assertSee('Poistetaanko yhteyshenkilö Maija?') ->assertScript('document.getElementById("remove-dialog").open', true) ->assertScript('document.getElementById("remove-dialog").contains(document.activeElement)', true) ->assertNoAccessibilityIssues(level: 2) ->keys('#remove-dialog', 'Escape') ->assertScript('document.getElementById("remove-dialog").open', false) ->assertScript('document.activeElement.getAttribute("aria-label")', 'Poista yhteyshenkilö Maija'); // Confirm: the row goes away and focus moves to the section heading. $page->keys($removeMaija, 'Enter') ->click('#remove-dialog button.bg-red-600, #remove-dialog [wire\:click="remove"]') ->assertSee('Yhteyshenkilö Maija poistettu.') ->assertDontSee('Poista yhteyshenkilö Maija') ->assertScript('document.activeElement.id', 'contacts-heading') ->assertSee('Pekka'); })->with(['light', 'dark']); it('has no accessibility issues with a consumer\'s personal identity code', function (string $page, string $device, string $colorScheme) { $this->actingAs(User::factory()->management()->create()); $consumer = CustomerModel::factory()->consumer()->create([ 'name' => 'Maija Meikäläinen', 'personal_identity_code' => '131052-308T', 'personal_identity_code_hash' => str_repeat('a', 64), ]); $url = match ($page) { 'customer page' => route('customers.show', $consumer->id), 'edit form' => route('customers.edit', $consumer->id), }; $visit = visit($url); $visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop(); $visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode(); $visit->assertSee($page === 'customer page' ? '131052-308T' : 'Poista tallennettu henkilötunnus') ->assertNoJavaScriptErrors() ->assertNoAccessibilityIssues(level: 2); })->with(['customer page', 'edit form'])->with([ 'desktop, light' => ['desktop', 'light'], 'desktop, dark' => ['desktop', 'dark'], 'mobile, light' => ['mobile', 'light'], 'mobile, dark' => ['mobile', 'dark'], ]); it('shows an invalid personal identity code error without accessibility issues', function (string $colorScheme) { $page = visit(route('customers.create')); $page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode(); $page->fill('[wire\:model="form.name"]', 'Maija Meikäläinen') ->click('Kuluttaja') ->fill('[wire\:model="form.personal_identity_code"]', '131052-308U') ->press('Tallenna') ->assertSee('Henkilötunnus ei ole kelvollinen.') ->assertNoAccessibilityIssues(level: 2); })->with(['light', 'dark']);