Files
Toiminnanohjaus/tests/Browser/CustomersAccessibilityTest.php
petriandClaude Opus 5.5 b4f2f1cfaa Add the task calendar, holidays, workflow templates and customer removal
Task calendar (/jobs/calendar) replaces per-unit task Kanban columns
(K34): a two-week Gantt of tasks per person. Bars move, resize and
change person by dragging or through a keyboard dialog. Each task's
estimate is booked evenly over working days into task_bookings, and
what exceeds the daily maximum (jobs.daily_capacity_hours, 8 h) moves
to the next working day. Tasks get planned_from/planned_to on the form.

Holidays (/settings/holidays): Finnish public holidays calculated per
year, which the admin can take out of use, plus company days off.

Also includes the earlier uncommitted work: workflow templates with
adding tasks from a template, and removing customers no module refers to.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 18:13:11 +02:00

202 lines
9.3 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\BillingUnitModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerContactModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->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' => '[email protected]',
'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('removes a customer with nothing linked to it with the keyboard, and offers no removal for one with a contact', function (string $colorScheme) {
$empty = CustomerModel::factory()->create(['name' => 'Turha Oy']);
$linked = CustomerModel::factory()->create(['name' => 'Mainos Oy']);
CustomerContactModel::factory()->create(['customer_id' => $linked->id, 'name' => 'Maija']);
$removeCustomer = '[wire\:click^="confirmRemoval(\'customer\'"]';
visit(route('customers.show', $linked->id))
->assertSee('Maija')
->assertDontSee('Poista asiakas');
$page = visit(route('customers.show', $empty->id));
$page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
// Removed: the dialog takes focus, then the list shows a status message.
$page->keys($removeCustomer, 'Enter')
->assertSee('Poistetaanko asiakas Turha Oy?')
->assertScript('document.getElementById("remove-dialog").contains(document.activeElement)', true)
->assertNoAccessibilityIssues(level: 2)
->click('#remove-dialog [wire\:click="remove"]')
->assertSee('Asiakas Turha Oy poistettu.')
->assertNoAccessibilityIssues(level: 2);
})->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']);