Replace the demo home page with a dashboard

Everyone sees their open tasks on an agenda, their open jobs, this
week's hours and quick links. Admin and management also get a lazily
loaded management panel: things to do, the month so far against the
previous month, jobs and late work, and everyone's workload.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 09:20:02 +02:00
co-authored by Claude Sonnet 5.5
parent d4251d00d7
commit 487a7d34ba
46 changed files with 2032 additions and 62 deletions
+1 -9
View File
@@ -2,7 +2,6 @@
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
@@ -14,17 +13,10 @@ it('renders the home page with the main menu', function () {
$this->get(route('home'))
->assertOk()
->assertSee('Toiminnanohjaus')
->assertSee('Hei, Eero Esimerkki')
->assertSee('Siirry pääsisältöön')
->assertSee('id="main-content"', false)
->assertSee('aria-label="Päävalikko"', false)
->assertSee('aria-label="Profiili: Eero Esimerkki"', false)
->assertSee('Kirjaudu ulos');
});
it('increments the click count', function () {
Livewire::test('pages::home')
->assertSet('clickCount', 0)
->call('incrementClickCount')
->assertSet('clickCount', 1)
->assertSee('Klikattu 1 kertaa');
});
@@ -0,0 +1,112 @@
<?php
use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Jobs\Domain\Enums\JobStatus;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
use App\Modules\TimeTracking\Infrastructure\Persistence\Eloquent\TimeEntryModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
// Wednesday.
$this->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 * 8 * 60)
->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();
});