Files
Toiminnanohjaus/tests/Feature/Modules/Jobs/JobBoardTest.php
T
petriandClaude Opus 5.5 f4b58f6b1d Darken the dark canvas, add customer colours, the ongoing status and the board model
- Dark theme page background is #5a5e60; text on it is lifted to zinc-200 /
  primary-100 and TallStackUI's dark labels, hints and checkbox labels are
  lightened so everything stays at 4.5:1.
- Shared HexColor picks white or black text by the higher WCAG contrast; a
  native-dialog colour picker and a large work dialog component.
- Customers get a header colour (customers.header_color), set on the
  customer page.
- New job status Jatkuvat / Kausi (ongoing): open, never late, billed
  monthly like running jobs.
- Kanban model: board columns and views, urgent threshold, per-user board
  preferences (density, column colours and sort), card positions, tasks of
  continuing jobs pinned to the board, MoveBoardCard and board queries with
  logged hours from TimeTracking.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 06:11:49 +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', 'Jatkuvat / Kausi'])
->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');
});