> $columns * @return array> */ function boardKeys(array $columns): array { return array_map(fn (array $cards): array => array_map(fn (BoardCard $card): string => $card->key(), $cards), $columns); } describe('board layout', function () { it('gathers the quote statuses in the daily view and keeps them apart in the sales view', function () { $cards = [boardCard(1, JobStatus::Prospect), boardCard(2, JobStatus::Tentative), boardCard(3, JobStatus::QuoteRequest), boardCard(4, JobStatus::Order)]; $layout = new BoardLayout; expect(boardKeys($layout->arrange($cards, BoardView::Production, BoardPreferences::defaults()))) ->toMatchArray(['quotes' => ['job-1', 'job-2', 'job-3'], 'order' => ['job-4']]) ->and(array_keys($layout->arrange($cards, BoardView::Sales, BoardPreferences::defaults())))->toBe(['prospect', 'tentative', 'quote_request']) ->and(boardKeys($layout->arrange($cards, BoardView::Sales, BoardPreferences::defaults())))->toBe(['prospect' => ['job-1'], 'tentative' => ['job-2'], 'quote_request' => ['job-3']]); }); it('splits jobs in production by the user\'s urgent threshold', function (UrgentThreshold $threshold, array $urgent) { $cards = [ boardCard(1, JobStatus::InProduction, Priority::Normal), boardCard(2, JobStatus::InProduction, Priority::First), boardCard(3, JobStatus::InProduction, Priority::Urgent), boardCard(4, JobStatus::InProduction, Priority::Immediate), ]; $columns = boardKeys((new BoardLayout)->arrange($cards, BoardView::Production, BoardPreferences::defaults()->withUrgentThreshold($threshold))); expect($columns['in_production_urgent'])->toBe($urgent) ->and([...$columns['in_production'], ...$columns['in_production_urgent']])->toHaveCount(4); })->with([ 'only immediate' => [UrgentThreshold::Immediate, ['job-4']], 'urgent and immediate' => [UrgentThreshold::Urgent, ['job-3', 'job-4']], 'first, urgent and immediate' => [UrgentThreshold::First, ['job-2', 'job-3', 'job-4']], ]); it('keeps continuing jobs in their own column and places pinned tasks by their status', function () { $cards = [ boardCard(1, JobStatus::Ongoing, Priority::Urgent), boardCard(1, JobStatus::Ongoing, taskId: 10, taskStatus: TaskStatus::Waiting), boardCard(1, JobStatus::Ongoing, taskId: 11, taskStatus: TaskStatus::InReview), boardCard(1, JobStatus::Ongoing, taskId: 12, taskStatus: TaskStatus::Done), ]; expect(boardKeys((new BoardLayout)->arrange($cards, BoardView::Production, BoardPreferences::defaults())))->toMatchArray([ 'ongoing' => ['job-1'], 'order' => ['task-10'], 'in_production' => ['task-11'], 'in_production_urgent' => [], 'done' => ['task-12'], ]); }); it('orders a column by drag order or by due date with undated cards last', function () { $cards = [ boardCard(1, JobStatus::Order, dueOn: '2026-12-10', position: 10), boardCard(2, JobStatus::Order, dueOn: null, position: 20), boardCard(3, JobStatus::Order, dueOn: '2026-12-01', position: 30), ]; $layout = new BoardLayout; $byDate = BoardPreferences::defaults()->withColumnSort(BoardColumn::Order, ColumnSort::DueDate); expect(boardKeys($layout->arrange($cards, BoardView::Production, BoardPreferences::defaults()))['order'])->toBe(['job-1', 'job-2', 'job-3']) ->and(boardKeys($layout->arrange($cards, BoardView::Production, $byDate))['order'])->toBe(['job-3', 'job-1', 'job-2']); }); it('gives each column the design colour until the user picks one', function () { $preferences = BoardPreferences::defaults()->withColumnColor(BoardColumn::Order, new HexColor('#B91C1C')); expect($preferences->colorOf(BoardColumn::Order)->value)->toBe('#b91c1c') ->and($preferences->colorOf(BoardColumn::Ongoing)->value)->toBe('#3b2d5e') ->and($preferences->withColumnColor(BoardColumn::Order, null)->colorOf(BoardColumn::Order)->value)->toBe('#23476a'); }); it('drops unknown columns and invalid values from stored settings', function () { $preferences = BoardPreferences::fromStored('huge', 'sometimes', ['order' => '#14532d', 'nope' => '#ffffff', 'done' => 'red'], ['order' => 'due_date', 'done' => 'random']); expect($preferences->colorValues())->toBe(['order' => '#14532d']) ->and($preferences->sortValues())->toBe(['order' => 'due_date']) ->and($preferences->density->value)->toBe('normal') ->and($preferences->urgentThreshold)->toBe(UrgentThreshold::Urgent); }); }); describe('moving cards', function () { beforeEach(function () { $this->jobs = new InMemoryCustomerJobRepository; $this->tasks = new InMemoryTaskRepository; $this->board = new InMemoryBoardRepository; $this->events = new FakeEventDispatcher; $customers = new FakeCustomerQueries; $catalog = new FakeCatalogQueries; $users = new FakeUserAccountQueries; $transactions = new FakeTransactionManager; $clock = new FakeClock(new DateTimeImmutable('2026-11-30')); $customers->customers = [1 => 'Mainos Oy']; $catalog->addServiceUnit(1, 'Markkinointi'); $catalog->addWorkType(11, 1, 'graafinen työ'); $users->addUser(10, 'Eero'); $createJob = new CreateCustomerJob($this->jobs, $this->jobs, new JobDetailsFactory($customers, $catalog, $users), $transactions, $clock, $this->events); $this->create = fn (string $status, string $priority = 'normal'): int => $createJob->execute(new CustomerJobData('Kampanja', 1, [1], 10, 'one_off', $status, $priority), 10); $planner = new TaskPlanner(new InMemoryTaskBookingRepository($this->tasks), new HolidayCalendar(new InMemoryHolidayOverrides), new DailyCapacity(new FakeSettings)); $this->addTask = new AddTask($this->jobs, $this->tasks, new TaskReferenceChecker($catalog, $users), $planner, $transactions, $this->events); $this->move = new MoveBoardCard($this->jobs, $this->tasks, $this->board, $transactions, $this->events, $clock); $this->pin = new PinTaskToBoard($this->jobs, $this->tasks, $this->board, $transactions); }); it('changes the status, records it and stores the dropped order', function () { $jobId = ($this->create)('order'); $otherId = ($this->create)('in_production'); $this->move->execute($jobId, null, BoardColumn::InProduction, ["job-{$otherId}", "job-{$jobId}"], UrgentThreshold::Urgent, 10); expect($this->jobs->findById($jobId)?->details()->status)->toBe(JobStatus::InProduction) ->and($this->jobs->changes)->not->toBeEmpty() ->and($this->board->jobPositions)->toBe([$otherId => 10, $jobId => 20]); }); it('raises the priority to the threshold in the urgent column and lowers it in the normal one', function () { $jobId = ($this->create)('in_production'); $this->move->execute($jobId, null, BoardColumn::InProductionUrgent, ["job-{$jobId}"], UrgentThreshold::First, 10); expect($this->jobs->findById($jobId)?->details()->priority)->toBe(Priority::First); $this->move->execute($jobId, null, BoardColumn::InProduction, ["job-{$jobId}"], UrgentThreshold::First, 10); expect($this->jobs->findById($jobId)?->details()->priority)->toBe(Priority::Normal); }); it('keeps a higher priority when the card is already urgent enough', function () { $jobId = ($this->create)('in_production', 'immediate'); $changesBefore = count($this->jobs->changes); $this->move->execute($jobId, null, BoardColumn::InProductionUrgent, ["job-{$jobId}"], UrgentThreshold::Urgent, 10); expect($this->jobs->findById($jobId)?->details()->priority)->toBe(Priority::Immediate) ->and($this->jobs->changes)->toHaveCount($changesBefore); }); it('keeps a quote status when moved inside the quotes column', function () { $jobId = ($this->create)('tentative'); $this->move->execute($jobId, null, BoardColumn::Quotes, ["job-{$jobId}"], UrgentThreshold::Urgent, 10); expect($this->jobs->findById($jobId)?->details()->status)->toBe(JobStatus::Tentative); $orderId = ($this->create)('order'); $this->move->execute($orderId, null, BoardColumn::Quotes, ["job-{$orderId}"], UrgentThreshold::Urgent, 10); expect($this->jobs->findById($orderId)?->details()->status)->toBe(JobStatus::QuoteRequest); }); it('never moves continuing jobs out of their column or other jobs into it', function (string $status, BoardColumn $target) { $jobId = ($this->create)($status); $this->move->execute($jobId, null, $target, [], UrgentThreshold::Urgent, 10); })->throws(CardCannotMoveThere::class)->with([ 'continuing out' => ['ongoing', BoardColumn::InProduction], 'other in' => ['order', BoardColumn::Ongoing], ]); it('sets a pinned task\'s status by its new column and publishes its completion', function () { $jobId = ($this->create)('ongoing'); $taskId = $this->addTask->execute($jobId, new TaskData('Ottelu 1', 11, 'waiting'), 10); $this->pin->execute($jobId, $taskId, true); $this->move->execute($jobId, $taskId, BoardColumn::Done, ["task-{$taskId}"], UrgentThreshold::Urgent, 10); expect($this->tasks->findForJob($jobId, $taskId)?->status())->toBe(TaskStatus::Done) ->and($this->board->pinnedTasks)->toBe([$taskId => true]) ->and($this->board->taskPositions)->toBe([$taskId => 10]) ->and(array_filter($this->events->dispatched, fn (object $event): bool => $event instanceof TaskCompleted))->toHaveCount(1); }); it('keeps pinned tasks out of columns that are not task columns', function () { $jobId = ($this->create)('ongoing'); $taskId = $this->addTask->execute($jobId, new TaskData('Ottelu 1', 11, 'waiting'), 10); $this->move->execute($jobId, $taskId, BoardColumn::OnHold, [], UrgentThreshold::Urgent, 10); })->throws(CardCannotMoveThere::class); it('pins only tasks of continuing jobs', function () { $jobId = ($this->create)('in_production'); $taskId = $this->addTask->execute($jobId, new TaskData('Taitto', 11, 'waiting'), 10); $this->pin->execute($jobId, $taskId, true); })->throws(TaskCannotBePinned::class); });