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 -3
View File
@@ -32,9 +32,7 @@ it('can be operated with the keyboard alone', function () {
->assertScript('document.activeElement.textContent.trim()', 'Siirry pääsisältöön')
->keys('a[href="#main-content"]', 'Enter')
->keys('#main-content', 'Tab')
->assertScript('document.activeElement.textContent.trim()', 'Lisää klikkaus')
->keys('#main-content button', 'Enter')
->assertSeeIn('[role="status"]', 'Klikattu 1 kertaa');
->assertScript('document.activeElement.textContent.trim()', 'Pikavastaanotto');
});
it('reaches the main menu with the keyboard', function () {
@@ -0,0 +1,45 @@
<?php
use App\Models\User;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Jobs\Domain\Enums\JobStatus;
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;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->worker = User::factory()->employee()->create(['name' => 'Aino Tekijä']);
$job = CustomerJobModel::factory()->create([
'name' => 'Mainosvideo',
'customer_id' => CustomerModel::factory()->company()->create()->id,
'status' => JobStatus::InProduction,
'responsible_user_id' => $this->worker->id,
'due_on' => now()->subDays(3)->toDateString(),
]);
$task = TaskModel::factory()->create(['customer_job_id' => $job->id, 'title' => 'Leikkaus', 'assignee_user_id' => $this->worker->id, 'due_on' => now()->subDay()->toDateString()]);
TaskModel::factory()->create(['customer_job_id' => $job->id, 'title' => 'Värimäärittely', 'assignee_user_id' => $this->worker->id, 'due_on' => now()->toDateString()]);
TimeEntryModel::factory()->create(['user_id' => $this->worker->id, 'task_id' => $task->id, 'worked_on' => now()->toDateString(), 'hours' => 2]);
});
it('has no accessibility issues on the home page', function (string $role, string $device, string $colorScheme) {
$this->actingAs($role === 'management' ? User::factory()->management()->create(['name' => 'Maija Johtaja']) : $this->worker);
$visit = visit(route('home'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$role === 'management'
? $visit->assertSee('Henkilöiden kuormitus')->assertSee('Leikkaus')
: $visit->assertSee('Leikkaus')->assertSee('Värimäärittely')->assertDontSee('Johtajapaneeli');
$visit->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['employee', 'management'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
+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();
});
@@ -0,0 +1,41 @@
<?php
use App\Modules\Dashboard\Domain\Enums\AgendaBucket;
use App\Modules\Dashboard\Domain\ValueObjects\Change;
use App\Modules\Dashboard\Domain\ValueObjects\Workload;
it('puts open tasks on the agenda by their nearest date', function (?string $due, ?string $start, AgendaBucket $bucket) {
// Wednesday 25.11.2026: tomorrow is Thursday, the week ends on Sunday.
expect(AgendaBucket::of($due, $start, '2026-11-25', '2026-11-26', '2026-11-29'))->toBe($bucket);
})->with([
'due yesterday' => ['2026-11-24', null, AgendaBucket::Overdue],
'due yesterday, started earlier' => ['2026-11-24', '2026-11-01', AgendaBucket::Overdue],
'due today' => ['2026-11-25', null, AgendaBucket::Soon],
'under way since Monday' => ['2026-12-10', '2026-11-23', AgendaBucket::Soon],
'starts tomorrow' => [null, '2026-11-26', AgendaBucket::Soon],
'due on Sunday' => ['2026-11-29', null, AgendaBucket::ThisWeek],
'starts next week' => [null, '2026-11-30', AgendaBucket::Later],
'no dates' => [null, null, AgendaBucket::Later],
]);
it('counts working days without weekends and holidays', function () {
expect(Workload::workingDays('2026-12-21', '2026-12-27', ['2026-12-24', '2026-12-25', '2026-12-26']))->toBe(3)
->and(Workload::workingDays('2026-11-23', '2026-11-29', []))->toBe(5);
});
it('compares the workload with the capacity', function () {
$load = Workload::of(2700, 480, 5);
expect($load->capacityMinutes)->toBe(2400)
->and($load->ratio())->toBe(1.125)
->and($load->isOverloaded())->toBeTrue()
->and(Workload::of(0, 480, 0)->ratio())->toBeNull()
->and(Workload::of(2400, 480, 5)->isOverloaded())->toBeFalse();
});
it('gives the change from the earlier value, none from zero', function () {
expect((new Change(150, 100))->ratio())->toBe(0.5)
->and((new Change(50, 100))->ratio())->toBe(-0.5)
->and((new Change(-50, -100))->ratio())->toBe(0.5)
->and((new Change(10, 0))->ratio())->toBeNull();
});