travelTo('2026-11-25 12:00'); $this->worker = User::factory()->employee()->create(['name' => 'Aino Tekijä']); $this->customer = CustomerModel::factory()->company()->create(['name' => 'Asiakas Oy']); $this->job = CustomerJobModel::factory()->create([ 'name' => 'Mainosvideo', 'customer_id' => $this->customer->id, 'status' => JobStatus::InProduction, 'responsible_user_id' => $this->worker->id, 'due_on' => '2026-11-20', ]); }); function homeTask(array $attributes, array $memberIds = []): TaskModel { $task = TaskModel::factory()->create(array_merge(['customer_job_id' => test()->job->id], $attributes)); foreach ($memberIds as $userId) { DB::table('task_members')->insert(['task_id' => $task->id, 'user_id' => $userId]); } return $task; } it('shows the user their tasks on an agenda, their open jobs and the week', function () { homeTask(['title' => 'Myöhästynyt', 'assignee_user_id' => $this->worker->id, 'due_on' => '2026-11-24']); homeTask(['title' => 'Huomenna', 'due_on' => '2026-11-26'], [$this->worker->id]); homeTask(['title' => 'Perjantaina', 'assignee_user_id' => $this->worker->id, 'planned_from' => '2026-11-27', 'planned_to' => '2026-11-27']); homeTask(['title' => 'Ensi kuussa', 'assignee_user_id' => $this->worker->id, 'due_on' => '2026-12-15']); homeTask(['title' => 'Valmis', 'assignee_user_id' => $this->worker->id, 'status' => TaskStatus::Done, 'due_on' => '2026-11-24']); homeTask(['title' => 'Jonkun muun', 'due_on' => '2026-11-24']); CustomerJobModel::factory()->create(['name' => 'Valmistunut', 'customer_id' => $this->customer->id, 'status' => JobStatus::Done, 'responsible_user_id' => $this->worker->id]); TimeEntryModel::factory()->create(['user_id' => $this->worker->id, 'task_id' => TaskModel::factory()->create(['customer_job_id' => $this->job->id])->id, 'worked_on' => '2026-11-23', 'hours' => 2.5]); $this->actingAs($this->worker); $page = Livewire::test('dashboard::home') ->assertOk() ->assertSee('Hei, Aino Tekijä') ->assertSee('Myöhässä (1)') ->assertSee('Mainosvideo') ->assertDontSee('Valmistunut') ->assertDontSee('Jonkun muun') ->assertDontSee('Johtajapaneeli') ->assertSee('Lisäksi yksi tehtävä myöhemmin.'); $overview = $page->instance()->overview(); expect(array_map(fn ($task) => $task->title, $overview->overdue))->toBe(['Myöhästynyt']) ->and($overview->overdue[0]->isLate)->toBeTrue() ->and(array_map(fn ($task) => $task->title, $overview->soon))->toBe(['Huomenna']) ->and(array_map(fn ($task) => $task->title, $overview->thisWeek))->toBe(['Perjantaina']) ->and($overview->laterCount)->toBe(1) ->and(array_map(fn ($job) => $job->name, $overview->jobs))->toBe(['Mainosvideo']) ->and($overview->jobs[0]->isLate)->toBeTrue() ->and($overview->week->monday)->toBe('2026-11-23') ->and($overview->week->totalQuarters)->toBe(10) ->and($overview->week->unapprovedQuarters)->toBe(10); }); it('gives admin and management the management panel', function () { $manager = User::factory()->management()->create(['name' => 'Maija Johtaja']); WorkTypeModel::factory()->create(['hourly_rate_cents' => 8000]); homeTask(['title' => 'Myöhässä oleva', 'assignee_user_id' => $this->worker->id, 'due_on' => '2026-11-20', 'estimated_hours' => 30, 'planned_from' => '2026-11-23', 'planned_to' => '2026-11-27']); DB::table('task_bookings')->insert(['task_id' => TaskModel::query()->where('title', 'Myöhässä oleva')->value('id'), 'user_id' => $this->worker->id, 'day' => '2026-11-26', 'minutes' => 45 * 60]); TimeEntryModel::factory()->create(['user_id' => $this->worker->id, 'task_id' => TaskModel::factory()->create(['customer_job_id' => $this->job->id])->id, 'worked_on' => '2026-11-03', 'hours' => 4]); TimeEntryModel::factory()->approved()->create(['user_id' => $this->worker->id, 'task_id' => TaskModel::factory()->create(['customer_job_id' => $this->job->id])->id, 'worked_on' => '2026-10-03', 'hours' => 2]); $this->actingAs($manager); $this->get(route('home'))->assertOk()->assertSee('Hei, Maija Johtaja'); $panel = Livewire::test('dashboard::management') ->assertOk() ->assertSee('Johtajapaneeli') ->assertSee('Yhdellä henkilöllä hyväksymättömiä tunteja') ->assertSee('Aino Tekijä: 4 h, 1 viikolta') ->assertSee('Yksi työ on myöhässä.') ->assertSee('Myöhässä oleva') ->assertSee('Ylikuormitettu') ->assertSee("+100,0\u{00A0}% edelliseen kuukauteen"); $overview = $panel->instance()->overview(); expect($overview->previousFrom)->toBe('2026-10-01') ->and($overview->previousTo)->toBe('2026-10-25') ->and($overview->month->customerQuarters)->toBe(16) ->and($overview->jobCounts['in_production'])->toBe(1) ->and($overview->overdueTaskCount)->toBe(1); $load = collect($overview->workloads)->firstWhere('userId', $this->worker->id); expect($load->thisWeek->bookedMinutes)->toBe(2700) ->and($load->thisWeek->capacityMinutes)->toBe(5 * 450) ->and(collect($overview->workloads)->pluck('userId'))->toContain($manager->id); }); it('keeps the management panel from employees', function () { $this->actingAs($this->worker); Livewire::test('dashboard::management')->assertForbidden(); });