Files
Toiminnanohjaus/tests/Browser/BillingAccessibilityTest.php
petriandClaude Sonnet 5.5 bc3dbf16a4 Show a monthly fee job's billed periods on a page of its own
The new billing::job-months page lists the months that created billing
materials have billed for a monthly fee job, with links to the materials
and the total, and the months still to bill up to the current month,
counted the same way as a new material counts them. The job page links
to it next to the payment basis for those who manage billing.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-25 15:56:15 +02:00

111 lines
5.0 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Billing\Application\UseCases\FinalizeBillingExport;
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']);
$this->monthly = 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('has no accessibility issues on the billed periods page', function (string $device, string $colorScheme) {
// The draft holds only the monthly fee job, so creating it bills the job's months up to now.
app(FinalizeBillingExport::class)->execute($this->exportId, $this->manager->id);
$visit = visit(route('billing.job-months', $this->monthly->id));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee('Laskutetut kuukaudet (3)')
->assertSee('Aineisto 1')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->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);
});