Files
Toiminnanohjaus/tests/Browser/SalesAccessibilityTest.php
T
petriandClaude Opus 5.5 6de5d9bef1 Add quick sales with cash days, credits and PDF receipts
Quick sales (pikamyynti) of active consumer products at the counter, in a
new Sales module:

- Product buttons add one to the sale's list per press; quantities can be
  lowered, raised or removed. Payment by cash or card, optional customer.
- Product durations are booked as the seller's hours on the yearly
  "Pikamyynnit" job (internal customer, not billed) through Jobs'
  ProvideQuickSaleTask and TimeTracking's AddTaskHours. The sale stands
  even when the hours cannot be booked, and the seller is told.
- Sales are never deleted: a credit records the lines negated on today's
  cash day, once per sale, by the seller or management.
- Closing a cash day stores its balance by payment method and VAT rate and
  stops sales on it; only management reopens a day.
- A printable A5 PDF receipt (barryvdh/laravel-dompdf) with the company's
  details, business ID, VAT number, lines and VAT breakdown.

Company details are kept in the settings and edited by the admin only on
the new Yritystiedot page. BusinessId moves from Customers to Shared so
both use the same check.

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

80 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ProductModel;
use App\Modules\Sales\Infrastructure\Persistence\Eloquent\QuickSaleModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->user = User::factory()->management()->create(['name' => 'Johtaja']);
$this->actingAs($this->user);
$this->photos = ProductModel::factory()->consumer()->withAutoHours(0.25)->create(['name' => 'Passikuvat', 'price_cents' => 1500]);
QuickSaleModel::factory()->withLine($this->photos, 2)->create(['user_id' => $this->user->id]);
});
it('has no accessibility issues on the quick sale pages and no sideways scrolling', function (string $page, string $device, string $colorScheme) {
$url = match ($page) {
'sell' => route('sales.sell'),
'sales' => route('sales.index'),
};
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee('Passikuvat')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['sell', 'sales'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('adds products with their buttons and announces the sale', function () {
$button = '[wire\\:click="addProduct('.$this->photos->id.')"]';
$page = visit(route('sales.sell'));
$page->click('#products-heading ~ ul '.$button)
->click('#products-heading ~ ul '.$button)
->click('#products-heading ~ ul '.$button)
->assertSee('Yhteensä 45,00')
->assertSee('3 × 15,00')
->assertNoAccessibilityIssues(level: 2)
->click('Kirjaa myynti')
->assertSee('kirjattu: 45,00')
->assertSee('Tunneillesi kirjattiin 0,75 h.')
->assertSee('Avaa kuitti')
->assertNoAccessibilityIssues(level: 2);
});
it('has no accessibility issues on the company details page', function (string $device, string $colorScheme) {
$this->actingAs(User::factory()->admin()->create());
$visit = visit(route('settings.company'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee('Yritystiedot')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('closes the cash day from its dialog', function () {
visit(route('sales.index'))
->click('Päätä kassapäivä')
->assertSee('Päätetäänkö kassapäivä?')
->assertNoAccessibilityIssues(level: 2)
->click('#close-dialog button:last-child')
->assertSee('Kassapäivä päätetty')
->assertSee('Avaa kassapäivä');
});