Files
Toiminnanohjaus/tests/Feature/Modules/Jobs/JobBoardTest.php
petriandClaude Opus 5.5 7f3b6dff78 Add customer job Kanban board
Phase 1, item 6:
- New page /jobs/board: one column per Kanban status (archived left
  out), one card per job with number, name, customer, priority and due
  date. Filters for my jobs (default), priority and service unit;
  subcontractors see only their own cards and cannot move them.
- Cards move by dragging (Livewire wire:sort across column groups) or
  with each card's status select, which works with the keyboard. Moves
  go through ChangeJobStatus, so they are recorded in the job history;
  the result is announced and focus returns to the moved card.
- Billing statuses only for management and the job's biller: the
  jobs.set-billing-status gate now takes the biller's user id.
- Column links with counts at the top; columns wrap with the screen
  width, so there is no sideways scrolling.
- CustomerJobQueries::board() and the biller on job summaries.
- Menu link and a link from the job list; spec and CLAUDE.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 19:15:54 +02:00

93 lines
4.1 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->employee = User::factory()->create();
$this->actingAs($this->employee);
});
it('shows the Kanban columns in order with my jobs, without archived ones', function () {
CustomerJobModel::factory()->create(['name' => 'Tilattu työ', 'status' => 'order', 'responsible_user_id' => $this->employee->id]);
CustomerJobModel::factory()->create(['name' => 'Arkistoitu työ', 'status' => 'archived', 'responsible_user_id' => $this->employee->id]);
CustomerJobModel::factory()->create(['name' => 'Muiden työ', 'status' => 'order']);
$board = Livewire::test('jobs::board')
->assertSee('Tilattu työ')
->assertDontSee('Arkistoitu työ')
->assertDontSee('Muiden työ')
->assertSeeInOrder(['Prospekti', 'Alustava', 'Tarjouspyyntö', 'Tilaus', 'Tuotannossa', 'Keskeytetty', 'Valmis', 'Lasku luotu', 'Laskutettu'])
->set('mine', false)
->assertSee('Muiden työ');
expect(array_keys($board->instance()->board))->not->toContain('archived')
->and(array_map(fn ($job) => $job->name, $board->instance()->board['order']))->toContain('Tilattu työ', 'Muiden työ');
$this->get(route('jobs.board'))->assertOk()->assertSee('Kanban');
});
it('moves a job with the select or by dropping it, and records the change', function () {
$job = CustomerJobModel::factory()->create(['name' => 'Messuvideo', 'status' => 'tentative', 'responsible_user_id' => $this->employee->id]);
Livewire::test('jobs::board')
->call('moveJob', $job->id, 'order')
->assertSee('Työ '.$job->number.' Messuvideo siirretty tilaan Tilaus.')
->call('moveDropped', (string) $job->id, 0, 'in_production')
->assertSee('siirretty tilaan Tuotannossa.');
expect($job->fresh()->status->value)->toBe('in_production')
->and(DB::table('customer_job_changes')->where('customer_job_id', $job->id)->where('field', 'status')->count())->toBe(2);
});
it('lets only management and the biller move a job to a billing status', function () {
$job = CustomerJobModel::factory()->create(['status' => 'done', 'responsible_user_id' => $this->employee->id]);
Livewire::test('jobs::board')
->call('moveJob', $job->id, 'invoiced')
->assertSee('voi asettaa vain johto tai työn laskuttaja');
expect($job->fresh()->status->value)->toBe('done');
$job->update(['biller_user_id' => $this->employee->id]);
Livewire::test('jobs::board')->call('moveJob', $job->id, 'invoiced');
expect($job->fresh()->status->value)->toBe('invoiced');
});
it('ignores unknown statuses, archiving and jobs not on the board', function () {
$job = CustomerJobModel::factory()->create(['status' => 'order', 'responsible_user_id' => $this->employee->id]);
$other = CustomerJobModel::factory()->create(['status' => 'order']);
Livewire::test('jobs::board')
->call('moveJob', $job->id, 'nonsense')
->assertSee('Työtä ei siirretty.')
->call('moveJob', $job->id, 'archived')
->call('moveJob', $other->id, 'done')
->call('moveJob', 999, 'done');
expect($job->fresh()->status->value)->toBe('order')
->and($other->fresh()->status->value)->toBe('order');
});
it('shows a subcontractor only their cards, without moving', function () {
$subcontractor = User::factory()->subcontractor()->create();
$theirs = CustomerJobModel::factory()->withMembers([$subcontractor->id])->create(['name' => 'Alihankintatyö', 'status' => 'order']);
CustomerJobModel::factory()->create(['name' => 'Muu työ', 'status' => 'order']);
$this->actingAs($subcontractor);
Livewire::test('jobs::board')
->assertSee('Alihankintatyö')
->assertDontSee('Muu työ')
->assertDontSeeHtml('wire:sort=')
->call('moveJob', $theirs->id, 'done')
->assertForbidden();
expect($theirs->fresh()->status->value)->toBe('order');
});