- Toolbar: whose board (own, a person, a service line, all), pipeline views (daily, sales, full), urgent and late filters with a live count, normal and compact density, and the quick intake button. - Columns side by side with horizontal scrolling on desktop, stacked on phones; each user's own column colours and order, the urgent column's threshold menu, and the continuing jobs column. - Cards in customer colours: job cards with their tasks checked off inside the card (the status select is gone), continuing job cards with the next period, PIN and quick add, and pinned task cards. Dragging moves and orders cards; the keyboard opens the job editor from the card title. - Job editor dialog: every job detail, tasks with checklists and templates, quick hours (TimeTracking) and expenses (Expenses), history. - The quick intake form also adds a contact person, initial status and priority, and opens as a dialog on the board. Co-Authored-By: Claude Opus 5.5 <[email protected]>
269 lines
13 KiB
PHP
269 lines
13 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
|
use App\Modules\Jobs\Domain\Enums\BoardColumn;
|
|
use App\Modules\Jobs\Domain\Enums\BoardDensity;
|
|
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;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->employee = User::factory()->create();
|
|
$this->actingAs($this->employee);
|
|
});
|
|
|
|
/**
|
|
* @return array<string, list<string>> card keys by column
|
|
*/
|
|
function boardColumnKeys(mixed $board): array
|
|
{
|
|
return array_map(fn (array $cards): array => array_map(fn ($card): string => $card->key(), $cards), $board->instance()->columns);
|
|
}
|
|
|
|
it('shows the daily pipeline columns in order with my jobs, without archived ones and the quick-sale job', function () {
|
|
$mine = 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' => 'Pikamyynnit', 'status' => 'in_production', 'responsible_user_id' => $this->employee->id, 'quick_sale_year' => 2026]);
|
|
CustomerJobModel::factory()->create(['name' => 'Muiden työ', 'status' => 'order']);
|
|
|
|
$board = Livewire::test('jobs::board')
|
|
->assertSee('Tilattu työ')
|
|
->assertDontSee('Arkistoitu työ')
|
|
->assertDontSee('Pikamyynnit')
|
|
->assertDontSee('Muiden työ')
|
|
->assertSeeInOrder(['Tarjoukset', 'Jonossa', 'Työn alla', 'Työn alla • Kiire', 'Odottaa asiakasta', 'Valmis • Laskuta', 'Jatkuvat & Kausi'], false)
|
|
->assertDontSeeHtml('id="job-status-');
|
|
|
|
expect(array_keys($board->instance()->columns))->toBe(['quotes', 'order', 'in_production', 'in_production_urgent', 'on_hold', 'done', 'ongoing'])
|
|
->and(boardColumnKeys($board)['order'])->toBe(['job-'.$mine->id]);
|
|
|
|
$board->set('board', 'all')->assertSee('Muiden työ');
|
|
|
|
$this->get(route('jobs.board'))->assertOk()->assertSee('Kanban');
|
|
});
|
|
|
|
it('shows the sales and full pipelines with their own columns', function () {
|
|
$board = Livewire::test('jobs::board')->call('setView', 'sales');
|
|
expect(array_keys($board->instance()->columns))->toBe(['prospect', 'tentative', 'quote_request']);
|
|
|
|
$board->call('setView', 'full');
|
|
expect(array_keys($board->instance()->columns))->toContain('invoiced', 'billed', 'ongoing')->not->toContain('quotes');
|
|
});
|
|
|
|
it('filters by person, service line, urgency and lateness', function () {
|
|
$colleague = User::factory()->create(['name' => 'Anna Korhonen']);
|
|
$urgent = CustomerJobModel::factory()->create(['name' => 'Kiiretyö', 'status' => 'in_production', 'priority' => 'urgent', 'responsible_user_id' => $colleague->id]);
|
|
$late = CustomerJobModel::factory()->create(['name' => 'Myöhässä oleva', 'status' => 'order', 'due_on' => now()->subDays(3), 'responsible_user_id' => $colleague->id]);
|
|
|
|
$board = Livewire::test('jobs::board')
|
|
->assertSee('Henkilö: Anna Korhonen')
|
|
->set('board', 'person-'.$colleague->id)
|
|
->assertSee('Kiiretyö')
|
|
->assertSee('Myöhässä oleva')
|
|
->toggle('onlyUrgent')
|
|
->assertSee('Kiiretyö')
|
|
->assertDontSee('Myöhässä oleva')
|
|
->assertSee('Näytetään 1 kortti');
|
|
|
|
$board->toggle('onlyUrgent')->toggle('onlyLate')
|
|
->assertSee('Myöhässä oleva')
|
|
->assertDontSee('Kiiretyö');
|
|
|
|
expect($urgent->id)->not->toBe($late->id);
|
|
});
|
|
|
|
it('moves a job to another column 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('moveDropped', 'job-'.$job->id, 0, 'order')
|
|
->assertSee('Työ '.$job->number.' Messuvideo siirretty tilaan Tilaus.')
|
|
->call('moveDropped', 'job-'.$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('raises the priority when a job is dropped into the urgent column, by the user\'s threshold', function () {
|
|
$job = CustomerJobModel::factory()->create(['name' => 'Juliste', 'status' => 'in_production', 'priority' => 'normal', 'responsible_user_id' => $this->employee->id]);
|
|
|
|
$board = Livewire::test('jobs::board')
|
|
->call('setUrgentThreshold', 'first')
|
|
->call('moveDropped', 'job-'.$job->id, 0, 'in_production_urgent')
|
|
->assertSee('siirretty Kiire-listaan (prioriteetti nostettu: Ensin)');
|
|
|
|
expect($job->fresh()->priority->value)->toBe('first')
|
|
->and(boardColumnKeys($board)['in_production_urgent'])->toBe(['job-'.$job->id]);
|
|
|
|
$board->call('moveDropped', 'job-'.$job->id, 0, 'in_production');
|
|
expect($job->fresh()->priority->value)->toBe('normal');
|
|
});
|
|
|
|
it('stores the drop order inside a column and switches a due-date column to own order', function () {
|
|
$first = CustomerJobModel::factory()->create(['status' => 'order', 'due_on' => now()->addDays(2), 'responsible_user_id' => $this->employee->id]);
|
|
$second = CustomerJobModel::factory()->create(['status' => 'order', 'due_on' => now()->addDay(), 'responsible_user_id' => $this->employee->id]);
|
|
|
|
$board = Livewire::test('jobs::board')->call('setColumnSort', 'order', 'due_date');
|
|
expect(boardColumnKeys($board)['order'])->toBe(['job-'.$second->id, 'job-'.$first->id]);
|
|
|
|
$board->call('moveDropped', 'job-'.$second->id, 1, 'order')
|
|
->assertSee('järjestys: oma järjestys');
|
|
|
|
expect(boardColumnKeys($board)['order'])->toBe(['job-'.$first->id, 'job-'.$second->id])
|
|
->and(DB::table('job_board_preferences')->where('user_id', $this->employee->id)->value('column_sorts'))->toBe('{"order":"manual"}');
|
|
});
|
|
|
|
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('setView', 'full')
|
|
->call('moveDropped', 'job-'.$job->id, 0, '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('setView', 'full')->call('moveDropped', 'job-'.$job->id, 0, 'invoiced');
|
|
expect($job->fresh()->status->value)->toBe('invoiced');
|
|
});
|
|
|
|
it('keeps continuing jobs in their own column', function () {
|
|
$ongoing = CustomerJobModel::factory()->create(['name' => 'Futsal LIVE', 'status' => 'ongoing', 'responsible_user_id' => $this->employee->id]);
|
|
$order = CustomerJobModel::factory()->create(['status' => 'order', 'responsible_user_id' => $this->employee->id]);
|
|
|
|
$board = Livewire::test('jobs::board')
|
|
->call('moveDropped', 'job-'.$ongoing->id, 0, 'in_production')
|
|
->assertSee('Korttia ei voi siirtää listaan Työn alla.')
|
|
->call('moveDropped', 'job-'.$order->id, 0, 'ongoing')
|
|
->assertSee('Korttia ei voi siirtää listaan Jatkuvat & Kausi.', false);
|
|
|
|
expect($ongoing->fresh()->status->value)->toBe('ongoing')
|
|
->and($order->fresh()->status->value)->toBe('order')
|
|
->and(boardColumnKeys($board)['ongoing'])->toBe(['job-'.$ongoing->id]);
|
|
});
|
|
|
|
it('ignores unknown columns and cards 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('moveDropped', 'job-'.$job->id, 0, 'nonsense')
|
|
->assertSee('Työtä ei siirretty.')
|
|
->call('moveDropped', 'job-'.$job->id, 0, 'archived')
|
|
->call('moveDropped', 'job-'.$job->id, 0, 'invoiced')
|
|
->call('moveDropped', 'job-'.$other->id, 0, 'done')
|
|
->call('moveDropped', 'job-999', 0, 'done');
|
|
|
|
expect($job->fresh()->status->value)->toBe('order')
|
|
->and($other->fresh()->status->value)->toBe('order');
|
|
});
|
|
|
|
it('marks a task done from the card and opens it again', function () {
|
|
$job = CustomerJobModel::factory()->create(['status' => 'in_production', 'responsible_user_id' => $this->employee->id]);
|
|
$task = TaskModel::factory()->create(['customer_job_id' => $job->id, 'title' => 'Vedos asiakkaalle', 'status' => 'in_progress']);
|
|
|
|
$board = Livewire::test('jobs::board')
|
|
->assertSee('Tehtävät (0/1)')
|
|
->call('setTaskDone', $job->id, $task->id, true)
|
|
->assertSee('Tehtävä Vedos asiakkaalle kuitattu valmiiksi.')
|
|
->assertSee('Tehtävät (1/1)');
|
|
|
|
expect($task->fresh()->status->value)->toBe('done');
|
|
|
|
$board->call('setTaskDone', $job->id, $task->id, false);
|
|
expect($task->fresh()->status->value)->toBe('in_progress');
|
|
});
|
|
|
|
it('lifts a continuing job\'s task into the pipeline and releases it', function () {
|
|
$job = CustomerJobModel::factory()->create(['name' => 'Somemarkkinointi', 'status' => 'ongoing', 'responsible_user_id' => $this->employee->id]);
|
|
$task = TaskModel::factory()->create(['customer_job_id' => $job->id, 'title' => 'Joulukampanja', 'status' => 'waiting']);
|
|
|
|
$board = Livewire::test('jobs::board')
|
|
->assertSee('Seuraava vuorossa:')
|
|
->call('pinTask', $job->id, $task->id, true)
|
|
->assertSee('Tehtävä Joulukampanja nostettu työputkeen.')
|
|
->assertSee('Tehtävä • PIN');
|
|
|
|
expect(boardColumnKeys($board)['order'])->toBe(['task-'.$task->id]);
|
|
|
|
$board->call('moveDropped', 'task-'.$task->id, 0, 'in_production');
|
|
expect($task->fresh()->status->value)->toBe('in_progress');
|
|
|
|
$board->call('pinTask', $job->id, $task->id, false);
|
|
expect((bool) $task->fresh()->is_pinned_to_board)->toBeFalse();
|
|
});
|
|
|
|
it('adds a task to a continuing job straight from its card', function () {
|
|
$job = CustomerJobModel::factory()->create(['status' => 'ongoing', 'responsible_user_id' => $this->employee->id]);
|
|
$unitId = DB::table('customer_job_service_unit')->where('customer_job_id', $job->id)->value('service_unit_id');
|
|
|
|
Livewire::test('jobs::board')
|
|
->call('addTask', $job->id)
|
|
->assertSee('Anna tehtävän nimi.')
|
|
->set('newTaskTitles.'.$job->id, 'Ottelu 12.12.')
|
|
->set('newTaskPins.'.$job->id, true)
|
|
->call('addTask', $job->id)
|
|
->assertSee('Tehtävä Ottelu 12.12. lisätty');
|
|
|
|
$task = TaskModel::query()->where('customer_job_id', $job->id)->sole();
|
|
expect($task->title)->toBe('Ottelu 12.12.')
|
|
->and((bool) $task->is_pinned_to_board)->toBeTrue()
|
|
->and($task->assignee_user_id)->toBe($this->employee->id)
|
|
->and($unitId)->not->toBeNull();
|
|
});
|
|
|
|
it('keeps each user\'s column colours and density their own and saves the customer colour for everyone', function () {
|
|
$customer = CustomerModel::factory()->create(['name' => 'Ässä KP Oy']);
|
|
CustomerJobModel::factory()->create(['customer_id' => $customer->id, 'status' => 'order', 'responsible_user_id' => $this->employee->id]);
|
|
|
|
$board = Livewire::test('jobs::board')
|
|
->call('setColumnColor', 'order', '#B91C1C')
|
|
->assertSee('Listan Jonossa otsikkoväri tallennettu.')
|
|
->call('setDensity', 'compact')
|
|
->call('setCustomerColor', $customer->id, '#991b1b')
|
|
->assertSee('Asiakkaan Ässä KP Oy väri tallennettu.')
|
|
->assertSeeHtml('background-color: #991b1b; color: #ffffff')
|
|
->call('setColumnColor', 'order', 'javascript:alert(1)')
|
|
->assertSee('Väri ei kelpaa.');
|
|
|
|
expect($board->instance()->columnStyle(BoardColumn::Order)['header'])->toBe('#b91c1c')
|
|
->and($board->instance()->preferences->density)->toBe(BoardDensity::Compact);
|
|
|
|
expect($customer->fresh()->header_color)->toBe('#991b1b');
|
|
|
|
$this->actingAs(User::factory()->create());
|
|
$otherBoard = Livewire::test('jobs::board');
|
|
expect($otherBoard->instance()->columnStyle(BoardColumn::Order)['header'])->toBe('#23476a')
|
|
->and($otherBoard->instance()->preferences->density)->toBe(BoardDensity::Normal);
|
|
|
|
$this->actingAs($this->employee);
|
|
Livewire::test('jobs::board')->call('setColumnColor', 'order', null)->assertSee('palautettu oletukseksi');
|
|
});
|
|
|
|
it('shows a subcontractor only their cards, without moving or changing colours', 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=')
|
|
->assertDontSeeHtml('id="board-select"')
|
|
->call('moveDropped', 'job-'.$theirs->id, 0, 'done')
|
|
->assertForbidden();
|
|
|
|
Livewire::test('jobs::board')->call('setCustomerColor', $theirs->customer_id, '#000000')->assertForbidden();
|
|
|
|
expect($theirs->fresh()->status->value)->toBe('order');
|
|
});
|