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'); });