Files
Toiminnanohjaus/tests/Browser/BillingAccessibilityTest.php
T
petriandClaude Opus 5.5 ae7b611126 Add a CSV download of created billing materials
Management downloads a created billing material as a semicolon CSV with
decimal commas and a UTF-8 BOM for Excel: one row per invoice line with
the invoice's customer, billing unit, e-invoice details and reference,
the job, the line and its net, VAT and gross amounts. Consumers' full
personal identity codes are included only for those who may see them,
the response is not cached, and cells Excel would read as formulas are
escaped. The columns follow Fennoa's import format once a sample exists.

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

91 lines
4.1 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Billing\Application\UseCases\OpenBillingDraft;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Expenses\Infrastructure\Persistence\Eloquent\ExpenseModel;
use App\Modules\Jobs\Domain\Enums\JobStatus;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use App\Modules\TimeTracking\Infrastructure\Persistence\Eloquent\TimeEntryModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->manager = User::factory()->management()->create(['name' => 'Maija Johtaja']);
$this->actingAs($this->manager);
$layout = WorkTypeModel::factory()->create(['name' => 'Taitto', 'hourly_rate_cents' => 8000]);
$customer = CustomerModel::factory()->company()->create(['name' => 'Asiakas Oy']);
$this->jobs = [];
foreach (['Esite', 'Juliste'] as $name) {
$job = CustomerJobModel::factory()->create(['name' => $name, 'customer_id' => $customer->id, 'status' => JobStatus::Done, 'payment_basis' => 'hourly']);
$task = TaskModel::factory()->create(['customer_job_id' => $job->id, 'work_type_id' => $layout->id]);
TimeEntryModel::factory()->approved()->create(['task_id' => $task->id, 'hours' => 2.5]);
TimeEntryModel::factory()->create(['task_id' => TaskModel::factory()->create(['customer_job_id' => $job->id, 'work_type_id' => $layout->id])->id, 'hours' => 1]);
$this->jobs[] = $job;
}
ExpenseModel::factory()->create(['customer_job_id' => $this->jobs[0]->id, 'description' => 'Paperi']);
CustomerJobModel::factory()->create([
'name' => 'Ylläpito',
'customer_id' => $customer->id,
'status' => JobStatus::InProduction,
'payment_basis' => 'monthly_fee',
'monthly_fee_cents' => 9900,
'starts_on' => now()->subMonths(2)->toDateString(),
]);
// Opening the draft adds the monthly fee job.
$this->exportId = app(OpenBillingDraft::class)->execute($this->manager->id);
});
it('has no accessibility issues on the billing pages', function (string $page, string $device, string $colorScheme) {
$url = $page === 'index' ? route('billing.index') : route('billing.export', $this->exportId);
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee($page === 'index' ? 'Jatka luonnosta' : 'Esite')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['index', 'export'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('adds and combines jobs and creates the material', function () {
[$first, $second] = $this->jobs;
$page = visit(route('billing.export', $this->exportId));
$page->click('[wire\\:click="add('.$first->id.')"]')
->assertSee('lisätty aineistoon')
->click('[wire\\:click="add('.$second->id.')"]')
->assertSee('Lasku 3: Asiakas Oy')
->assertSee('Laskutettavat kuukaudet')
->assertSee('Hyväksymättömiä tunteja 1 h')
->assertNoAccessibilityIssues(level: 2)
->select('[wire\\:model="moveTargets.'.$second->id.'"]', (string) $first->id)
->click('[wire\\:click="move('.$second->id.')"]')
->assertSee('siirretty laskulle')
->assertDontSee('Lasku 3: Asiakas Oy')
->click('Muodosta aineisto')
->assertSee('Muodostetaanko laskuaineisto?')
->assertNoAccessibilityIssues(level: 2)
->click('#finalize-dialog button:last-child')
->assertSee('Laskuaineisto muodostettu: 2 laskua.')
->assertSee('Laskutetut h')
->assertSee('Lataa CSV')
->assertNoAccessibilityIssues(level: 2);
expect($first->refresh()->status)->toBe(JobStatus::Invoiced);
});