97 lines
4.5 KiB
PHP
97 lines
4.5 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
|
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockItemGroupModel;
|
|
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockItemModel;
|
|
use App\Modules\Inventory\Infrastructure\Persistence\Eloquent\StockMovementModel;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->user = User::factory()->management()->create(['name' => 'Johtaja']);
|
|
$this->actingAs($this->user);
|
|
ServiceUnitModel::query()->where('name', 'Painotuotanto')->update(['uses_stock' => true]);
|
|
$group = StockItemGroupModel::factory()->create(['name' => 'Paperit']);
|
|
$this->item = StockItemModel::factory()->create([
|
|
'stock_item_group_id' => $group->id,
|
|
'name' => 'Valokuvapaperi',
|
|
'unit' => 'sheet',
|
|
'reorder_level_milli' => 50_000,
|
|
'average_cost_hundredths' => 5_000,
|
|
]);
|
|
StockMovementModel::query()->create([
|
|
'stock_item_id' => $this->item->id, 'kind' => 'purchase', 'quantity_milli' => 40_000, 'unit_cost_hundredths' => 5_000,
|
|
'value_cents' => 2_000, 'occurred_on' => now()->toDateString(), 'recorded_at' => now(), 'user_id' => $this->user->id,
|
|
]);
|
|
});
|
|
|
|
it('has no accessibility issues on the stock pages and no sideways scrolling', function (string $page, string $device, string $colorScheme) {
|
|
$url = match ($page) {
|
|
'index' => route('inventory.index'),
|
|
'item' => route('inventory.items.show', $this->item->id),
|
|
'form' => route('inventory.items.edit', $this->item->id),
|
|
'groups' => route('inventory.groups'),
|
|
};
|
|
|
|
$visit = visit($url);
|
|
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
|
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
|
|
|
$visit->assertSee(match ($page) {
|
|
'groups' => 'Paperit', 'form' => __('inventory.form.edit_title'), default => 'Valokuvapaperi'
|
|
})
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
})->with(['index', 'item', 'form', 'groups'])->with([
|
|
'desktop, light' => ['desktop', 'light'],
|
|
'desktop, dark' => ['desktop', 'dark'],
|
|
'mobile, light' => ['mobile', 'light'],
|
|
'mobile, dark' => ['mobile', 'dark'],
|
|
]);
|
|
|
|
it('reverses a movement in a dialog that returns focus', function () {
|
|
visit(route('inventory.items.show', $this->item->id))
|
|
->assertSee(__('inventory.status.reorder'))
|
|
->click(__('inventory.item.reverse'))
|
|
->assertSee(__('inventory.item.reverse_title'))
|
|
->assertNoAccessibilityIssues(level: 2)
|
|
->click(__('inventory.item.reverse_confirm'))
|
|
->assertSee('Vastakirjaus kirjattu')
|
|
->assertScript('document.activeElement.id', 'item-status');
|
|
});
|
|
|
|
it('records material on a task card with the keyboard and without accessibility issues', function (string $device, string $colorScheme) {
|
|
$print = ServiceUnitModel::query()->where('name', 'Painotuotanto')->sole();
|
|
$print->update(['uses_stock' => true]);
|
|
$job = CustomerJobModel::factory()->create(['name' => 'Ikkunateippaus', 'status' => 'order']);
|
|
DB::table('customer_job_service_unit')->where('customer_job_id', $job->id)->update(['service_unit_id' => $print->id]);
|
|
$task = TaskModel::factory()->create([
|
|
'customer_job_id' => $job->id,
|
|
'work_type_id' => WorkTypeModel::query()->where('name', 'asennus')->value('id'),
|
|
'title' => 'Asennus',
|
|
]);
|
|
|
|
$visit = visit(route('jobs.show', $job->id).'#task-'.$task->id);
|
|
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
|
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
|
|
|
$visit->assertSee(__('inventory.task.title'))
|
|
->fill('#task-'.$task->id.'-material-search', 'valoku')
|
|
->assertSee('1 osuma')
|
|
->click('[wire\:click="selectItem('.$this->item->id.')"]')
|
|
->fill('#task-'.$task->id.'-material-quantity', '2')
|
|
->keys('#task-'.$task->id.'-material-quantity', 'Enter')
|
|
->assertSee('Kirjattu Valokuvapaperi 2')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
})->with([
|
|
'desktop, light' => ['desktop', 'light'],
|
|
'mobile, dark' => ['mobile', 'dark'],
|
|
]);
|