Kanban / timesheet update
This commit is contained in:
@@ -35,14 +35,15 @@ it('has no accessibility issues on the time pages and no sideways scrolling', fu
|
||||
|
||||
it('records hours in the weekly view with the keyboard', function () {
|
||||
$tuesday = now()->startOfWeek()->addDay()->toDateString();
|
||||
$cell = '#cell-'.$this->task->id.'-'.$tuesday;
|
||||
$cell = '#cell-scheduled-'.$this->task->id.'-'.$tuesday;
|
||||
|
||||
visit(route('time.week'))
|
||||
->on()->desktop()
|
||||
->type($cell, '2,5')
|
||||
->clear($cell)
|
||||
->type($cell, '2:30')
|
||||
->keys($cell, 'Tab')
|
||||
->assertSee('Tallennettu: Mainoskuvat')
|
||||
->assertSee('Viikko yhteensä: 4 h')
|
||||
->assertSee('Viikko yhteensä: 4:00 h')
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
|
||||
expect((float) TimeEntryModel::query()->whereDate('worked_on', $tuesday)->sole()->hours)->toBe(2.5);
|
||||
@@ -50,8 +51,8 @@ it('records hours in the weekly view with the keyboard', function () {
|
||||
|
||||
it('shows an invalid value as an error at the field', function (string $device) {
|
||||
$selector = $device === 'mobile'
|
||||
? '#mcell-'.$this->task->id.'-'.$this->monday
|
||||
: '#cell-'.$this->task->id.'-'.$this->monday;
|
||||
? '#mcell-scheduled-'.$this->task->id.'-'.$this->monday
|
||||
: '#cell-scheduled-'.$this->task->id.'-'.$this->monday;
|
||||
|
||||
$visit = visit(route('time.week'));
|
||||
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
||||
@@ -90,7 +91,7 @@ it('has no accessibility issues on the approval pages', function (string $page,
|
||||
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
||||
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
||||
|
||||
$visit->assertSee($page === 'approvals' ? 'Kaisa Kollega' : 'hyväksytty')
|
||||
$visit->assertSee($page === 'approvals' ? 'Kaisa Kollega' : 'Hyväksytty:')
|
||||
->assertScript('document.documentElement.scrollWidth <= window.innerWidth', true)
|
||||
->assertNoJavaScriptErrors()
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
@@ -103,11 +104,51 @@ it('has no accessibility issues on the approval pages', function (string $page,
|
||||
|
||||
it('approves the own week with the keyboard and shows the cells as approved', function () {
|
||||
visit(route('time.week'))
|
||||
->assertSee('Hyväksymättä 1,5 h.')
|
||||
->keys('#approval-heading + p + div button', 'Enter')
|
||||
->assertSee('Hyväksymättä:')
|
||||
->assertSee('1:30')
|
||||
->click('Hyväksy viikko')
|
||||
->assertSee('Hyväksytyt tunnit on lukittu.')
|
||||
->assertSee('hyväksytty')
|
||||
->assertSee('Hyväksytty:')
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
|
||||
expect(TimeEntryModel::query()->sole()->approved_at)->not->toBeNull();
|
||||
});
|
||||
|
||||
it('asks for the missing billing notes before approving, and fills one in the entry dialog', function () {
|
||||
TimeEntryModel::query()->update(['note' => null]);
|
||||
|
||||
visit(route('time.week'))
|
||||
->on()->desktop()
|
||||
->assertSee('1 selite puuttuu')
|
||||
->click('Hyväksy viikko')
|
||||
->assertScript('document.getElementById("missing-notes-dialog").open', true)
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->click('#missing-notes-dialog button[wire\\:click^="openEntry"]')
|
||||
->assertScript('document.getElementById("entry-dialog").open', true)
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->type('#entry-note', 'Mainoskuvien luonnokset')
|
||||
->keys('#entry-note', 'Escape')
|
||||
->assertSee('Kirjaus tallennettu')
|
||||
->assertScript('document.getElementById("entry-dialog").open', false);
|
||||
|
||||
expect(TimeEntryModel::query()->sole()->note)->toBe('Mainoskuvien luonnokset');
|
||||
});
|
||||
|
||||
it('has no accessibility issues in the timer, work orders and add to list dialogs', function (string $colorScheme) {
|
||||
$visit = visit(route('time.week'))->on()->desktop();
|
||||
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
||||
|
||||
$visit->click('[aria-label^="Työajastin: Mainoskuvat"]')
|
||||
->assertScript('document.getElementById("timer-dialog").open', true)
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->keys('#timer-note', 'Escape')
|
||||
->click('#open-manage')
|
||||
->assertScript('document.getElementById("manage-dialog").open', true)
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->keys('#manage-dialog', 'Escape')
|
||||
->click('#open-add-to-list')
|
||||
->assertScript('document.getElementById("add-to-list-dialog").open', true)
|
||||
->type('#pin-search', 'Mainos')
|
||||
->assertSee('1 osuma')
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->with(['light', 'dark']);
|
||||
|
||||
@@ -21,6 +21,11 @@ class FakeTaskQueries implements TaskQueries
|
||||
$this->tasks[$taskId] = new BookableTask($taskId, $jobId, '2026-0001', 'Kampanja', 'Tehtävä '.$taskId, $workTypeId, 'graafinen työ', $jobStatus, TaskStatus::Waiting);
|
||||
}
|
||||
|
||||
public function scheduledTaskIdsFor(int $userId, string $from, string $to): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function pinnedTaskIds(int $jobId): array
|
||||
{
|
||||
return [];
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\TimeTracking\Domain\Contracts\PinnedTaskRepository;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class InMemoryPinnedTaskRepository implements PinnedTaskRepository
|
||||
{
|
||||
/** @var array<int, list<int>> task ids by user id */
|
||||
public array $pins = [];
|
||||
|
||||
public function pin(int $userId, int $taskId, DateTimeImmutable $at): void
|
||||
{
|
||||
if (! in_array($taskId, $this->pins[$userId] ?? [], true)) {
|
||||
$this->pins[$userId][] = $taskId;
|
||||
}
|
||||
}
|
||||
|
||||
public function unpin(int $userId, int $taskId): void
|
||||
{
|
||||
$this->pins[$userId] = array_values(array_diff($this->pins[$userId] ?? [], [$taskId]));
|
||||
}
|
||||
|
||||
public function unpinAll(int $userId): int
|
||||
{
|
||||
$count = count($this->pins[$userId] ?? []);
|
||||
$this->pins[$userId] = [];
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function pinnedTaskIds(int $userId): array
|
||||
{
|
||||
return $this->pins[$userId] ?? [];
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class InMemoryTimeEntryRepository implements TimeEntryRepository
|
||||
public function save(TimeEntry $entry): TimeEntry
|
||||
{
|
||||
$id = $entry->id() ?? $this->nextId++;
|
||||
$this->entries[$id] = TimeEntry::reconstitute($id, $entry->userId(), $entry->taskId(), $entry->jobId(), $entry->workTypeId(), $entry->workedOn(), $entry->hours(), $entry->note(), $entry->approvedBy(), $entry->approvedAt(), $entry->billingExportId());
|
||||
$this->entries[$id] = TimeEntry::reconstitute($id, $entry->userId(), $entry->taskId(), $entry->jobId(), $entry->workTypeId(), $entry->workedOn(), $entry->hours(), $entry->note(), $entry->approvedBy(), $entry->approvedAt(), $entry->billingExportId(), $entry->billingModel(), $entry->internalComment());
|
||||
|
||||
return clone $this->entries[$id];
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ it('approves the own week in the weekly view, which locks its cells', function (
|
||||
$this->actingAs($this->employee);
|
||||
|
||||
Livewire::test('time::week')
|
||||
->assertSee('Hyväksymättä 3 h.')
|
||||
->assertSee('Hyväksymättä:')->assertSee('3:00')
|
||||
->call('approveWeek')
|
||||
->assertSet('statusMessage', fn (string $message) => str_contains($message, 'hyväksytty. Hyväksytyt tunnit on lukittu.'))
|
||||
->assertDontSee('id="cell-'.$this->task->id.'-'.$this->monday.'"', false)
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Modules\Jobs\Domain\Exceptions\TaskHasTimeEntries;
|
||||
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\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
|
||||
@@ -23,7 +24,7 @@ it('saves and clears a cell of the weekly view', function () {
|
||||
|
||||
Livewire::test('time::week')
|
||||
->call('saveCell', $this->task->id, $this->monday, '2,5')
|
||||
->assertSee('2,5 h.')
|
||||
->assertSee('2:30.')
|
||||
->call('saveCell', $this->task->id, $this->monday, '1,1')
|
||||
->assertHasErrors(["cells.{$this->task->id}.{$this->monday}"]);
|
||||
|
||||
@@ -34,6 +35,100 @@ it('saves and clears a cell of the weekly view', function () {
|
||||
expect(TimeEntryModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('takes hours and minutes, minutes and 15 minute steps in a cell', function () {
|
||||
$week = Livewire::test('time::week')
|
||||
->call('saveCell', $this->task->id, $this->monday, '1:30')
|
||||
->call('adjustCell', $this->task->id, $this->monday, 1);
|
||||
|
||||
expect((float) TimeEntryModel::query()->sole()->hours)->toBe(1.75);
|
||||
|
||||
$week->call('saveCell', $this->task->id, $this->monday, '90');
|
||||
expect((float) TimeEntryModel::query()->sole()->hours)->toBe(1.5);
|
||||
|
||||
$week->call('saveCell', $this->task->id, $this->monday, '1:10')
|
||||
->assertHasErrors(["cells.{$this->task->id}.{$this->monday}"]);
|
||||
|
||||
foreach (range(1, 6) as $step) {
|
||||
$week->call('adjustCell', $this->task->id, $this->monday, -1);
|
||||
}
|
||||
|
||||
expect(TimeEntryModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('stores the billing basis, billing note and internal comment of an entry', function () {
|
||||
Livewire::test('time::week')
|
||||
->call('saveCell', $this->task->id, $this->monday, '2')
|
||||
->call('openEntry', $this->task->id, $this->monday)
|
||||
->assertSet('entryBillingModel', 'hourly')
|
||||
->set('entryBillingModel', 'non_billable')
|
||||
->set('entryNote', 'Kuvien rajaus')
|
||||
->set('entryComment', 'Asiakas toivoi kiirettä')
|
||||
->call('saveEntry')
|
||||
->assertSee('Kirjaus tallennettu');
|
||||
|
||||
$entry = TimeEntryModel::query()->sole();
|
||||
|
||||
expect($entry->note)->toBe('Kuvien rajaus')
|
||||
->and($entry->internal_comment)->toBe('Asiakas toivoi kiirettä')
|
||||
->and($entry->billing_model)->toBe('non_billable');
|
||||
});
|
||||
|
||||
it('blocks approving a week without billing notes and lists the entries', function () {
|
||||
Livewire::test('time::week')
|
||||
->call('saveCell', $this->task->id, $this->monday, '2')
|
||||
->assertSee('1 selite puuttuu')
|
||||
->call('approveWeek')
|
||||
->assertSee('Viikkoa ei voi vielä hyväksyä');
|
||||
|
||||
expect(TimeEntryModel::query()->sole()->approved_at)->toBeNull();
|
||||
});
|
||||
|
||||
it('pins tasks to the pinned part, keeps them on later weeks and unpins them', function () {
|
||||
$other = TaskModel::factory()->create(['title' => 'Kehitystyöt']);
|
||||
|
||||
$week = Livewire::test('time::week')
|
||||
->call('pinTasks', [$other->id])
|
||||
->assertSee('Tehtävä Kehitystyöt kiinnitetty');
|
||||
|
||||
expect($week->instance()->sheet->row($other->id)?->pinned)->toBeTrue()
|
||||
->and($week->instance()->sheet->pinnedTaskCount())->toBe(1);
|
||||
|
||||
$week->call('showWeek', 'next');
|
||||
expect($week->instance()->sheet->pinnedTaskCount())->toBe(1);
|
||||
|
||||
$week->call('unpinTask', $other->id);
|
||||
expect($week->instance()->sheet->pinnedTaskCount())->toBe(0);
|
||||
|
||||
$week->call('pinTasks', [$other->id])->call('clearPins')->assertSee('1 kiinnitys poistettu.');
|
||||
});
|
||||
|
||||
it('lets a pin lapse after the job is done, except on weeks with hours', function () {
|
||||
$week = Livewire::test('time::week')
|
||||
->call('pinTasks', [$this->task->id])
|
||||
->call('saveCell', $this->task->id, $this->monday, '1');
|
||||
|
||||
DB::table('customer_jobs')->where('id', $this->task->customer_job_id)->update(['status' => 'done']);
|
||||
|
||||
$week->call('showWeek', 'this');
|
||||
expect($week->instance()->sheet->pinnedTaskCount())->toBe(1);
|
||||
|
||||
$week->call('showWeek', 'next');
|
||||
expect($week->instance()->sheet->pinnedTaskCount())->toBe(0)
|
||||
->and($week->instance()->sheet->scheduledTaskCount())->toBe(0);
|
||||
});
|
||||
|
||||
it('saves the timer time rounded to quarter hours on today', function () {
|
||||
Livewire::test('time::week')
|
||||
->call('saveTimer', $this->task->id, 50 * 60, 'Ottelun striimaus')
|
||||
->assertSee('0:45 kirjattu tehtävälle Mainoskuvat');
|
||||
|
||||
$entry = TimeEntryModel::query()->sole();
|
||||
|
||||
expect((float) $entry->hours)->toBe(0.75)
|
||||
->and($entry->worked_on->toDateString())->toBe(now()->toDateString())
|
||||
->and($entry->note)->toBe('Ottelun striimaus');
|
||||
});
|
||||
|
||||
it('takes the week only from the URL and the week buttons', function () {
|
||||
$this->get(route('time.week', ['viikko' => "abc'); alert(1); ('"]))->assertOk()->assertSee('Mainoskuvat');
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Modules\TimeTracking\Application\UseCases\CancelWeekApproval;
|
||||
use App\Modules\TimeTracking\Application\UseCases\RemoveTimeEntry;
|
||||
use App\Modules\TimeTracking\Application\UseCases\SetDayHours;
|
||||
use App\Modules\TimeTracking\Application\UseCases\UpdateTimeEntry;
|
||||
use App\Modules\TimeTracking\Domain\Exceptions\BillingNotesMissing;
|
||||
use App\Modules\TimeTracking\Domain\Exceptions\TimeApproved;
|
||||
use Tests\Fakes\FakeClock;
|
||||
use Tests\Fakes\FakeTaskQueries;
|
||||
@@ -34,6 +35,12 @@ beforeEach(function () {
|
||||
$this->setDayHours->execute(10, 1, '2026-11-29', '2');
|
||||
$this->setDayHours->execute(10, 1, '2026-11-30', '3');
|
||||
$this->setDayHours->execute(11, 1, '2026-11-23', '5');
|
||||
|
||||
// Every entry has its billing note, which the approval requires.
|
||||
foreach ($this->entries->entries as $entry) {
|
||||
$entry->describe(null, 'Suunnittelu', null);
|
||||
$this->entries->save($entry);
|
||||
}
|
||||
});
|
||||
|
||||
it('approves the user\'s unapproved hours of the week only', function () {
|
||||
@@ -76,3 +83,10 @@ it('cancels the approval of a week so the hours can be changed again', function
|
||||
|
||||
expect($this->entries->findForDay(10, 1, new DateTimeImmutable('2026-11-23'))?->hours()->format())->toBe('5');
|
||||
});
|
||||
|
||||
it('refuses to approve a week while an entry has no billing note', function () {
|
||||
$this->setDayHours->execute(10, 2, '2026-11-24', '1');
|
||||
|
||||
expect(fn () => $this->approveWeek->execute(10, '2026-11-23', approverId: 99))->toThrow(BillingNotesMissing::class);
|
||||
expect(array_filter($this->entries->entries, fn ($entry) => $entry->isApproved()))->toBeEmpty();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Jobs\Application\DTOs\BookableTask;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\TimeTracking\Application\DTOs\TimesheetCell;
|
||||
use App\Modules\TimeTracking\Application\DTOs\TimesheetTaskRow;
|
||||
use App\Modules\TimeTracking\Application\Services\TimesheetLayout;
|
||||
use App\Modules\TimeTracking\Domain\Enums\EntryBillingModel;
|
||||
use App\Modules\TimeTracking\Domain\Exceptions\InvalidWorkedHours;
|
||||
use App\Modules\TimeTracking\Domain\ValueObjects\WorkedHours;
|
||||
|
||||
function sheetRow(int $taskId, string $customer, string $jobNumber, string $title, bool $pinned = false, int $quarters = 0, JobStatus $jobStatus = JobStatus::InProduction, TaskStatus $taskStatus = TaskStatus::InProgress, int $customerId = 0): TimesheetTaskRow
|
||||
{
|
||||
$task = new BookableTask($taskId, (int) $jobNumber, $jobNumber, 'Työ '.$jobNumber, $title, 1, 'suunnittelu', $jobStatus, $taskStatus, $customerId ?: crc32($customer), $customer, null, 'hourly');
|
||||
$cells = $quarters > 0 ? ['2026-11-30' => new TimesheetCell($quarters, null, null, null, false)] : [];
|
||||
|
||||
return new TimesheetTaskRow($task, $cells, $quarters, $pinned);
|
||||
}
|
||||
|
||||
it('reads hours and minutes, decimal hours and minutes from a cell', function (string $value, ?int $quarters) {
|
||||
expect(WorkedHours::parseFlexible($value)?->quarters)->toBe($quarters);
|
||||
})->with([
|
||||
'h:mm' => ['1:30', 6],
|
||||
'decimal comma' => ['1,5', 6],
|
||||
'decimal point' => ['2.25', 9],
|
||||
'whole hours' => ['2', 8],
|
||||
'minutes over 24' => ['90', 6],
|
||||
'zero' => ['0:00', null],
|
||||
'empty' => ['', null],
|
||||
]);
|
||||
|
||||
it('refuses times that are not whole quarter hours', function (string $value) {
|
||||
WorkedHours::parseFlexible($value);
|
||||
})->throws(InvalidWorkedHours::class)->with(['1:10', '50', '1,1', 'abc', '25:00']);
|
||||
|
||||
it('formats quarters as hours and minutes', function () {
|
||||
expect(WorkedHours::formatClock(0))->toBe('0:00')
|
||||
->and(WorkedHours::formatClock(6))->toBe('1:30')
|
||||
->and(WorkedHours::formatClock(41))->toBe('10:15');
|
||||
});
|
||||
|
||||
it('takes the default billing basis from the job\'s payment basis', function (?string $basis, EntryBillingModel $model) {
|
||||
expect(EntryBillingModel::forPaymentBasis($basis))->toBe($model);
|
||||
})->with([
|
||||
['fixed_quote', EntryBillingModel::Fixed],
|
||||
['price_list', EntryBillingModel::Fixed],
|
||||
['monthly_fee', EntryBillingModel::Fixed],
|
||||
['hourly', EntryBillingModel::Hourly],
|
||||
[null, EntryBillingModel::Hourly],
|
||||
['not_billable', EntryBillingModel::NonBillable],
|
||||
]);
|
||||
|
||||
it('groups rows customer A–Ö, then job, then task, in Finnish order', function () {
|
||||
$rows = [
|
||||
sheetRow(1, 'Ässä KP Oy', '798', 'Markkinointi'),
|
||||
sheetRow(2, 'Agrikumppanit Oy', '5', 'Myyntityö'),
|
||||
sheetRow(3, 'Loimaan kaupunki', '778', 'Videokuvaus'),
|
||||
sheetRow(4, 'Loimaan kaupunki', '778', 'Käsikirjoitus'),
|
||||
sheetRow(5, 'Ravintola ATA ky', '470', 'Lounaslista'),
|
||||
];
|
||||
|
||||
$sections = (new TimesheetLayout)->arrange($rows, [1, 2, 3, 4, 5], []);
|
||||
|
||||
expect(array_map(fn ($customer) => $customer->name, $sections['scheduled']))->toBe(['Agrikumppanit Oy', 'Loimaan kaupunki', 'Ravintola ATA ky', 'Ässä KP Oy'])
|
||||
->and(array_map(fn ($row) => $row->task->taskTitle, $sections['scheduled'][1]->jobs[0]->rows))->toBe(['Käsikirjoitus', 'Videokuvaus']);
|
||||
});
|
||||
|
||||
it('moves pinned rows out of the scheduled part and keeps lapsed pins only with hours', function () {
|
||||
$rows = [
|
||||
sheetRow(1, 'A Oy', '1', 'Pinned open', pinned: true),
|
||||
sheetRow(2, 'A Oy', '1', 'Pinned done with hours', pinned: true, quarters: 4, jobStatus: JobStatus::Done),
|
||||
sheetRow(3, 'A Oy', '1', 'Pinned done without hours', pinned: true, jobStatus: JobStatus::Done),
|
||||
sheetRow(4, 'B Oy', '2', 'Scheduled'),
|
||||
sheetRow(5, 'B Oy', '2', 'Not scheduled, no hours'),
|
||||
sheetRow(6, 'B Oy', '2', 'Hours only', quarters: 2),
|
||||
];
|
||||
|
||||
$sections = (new TimesheetLayout)->arrange($rows, [1, 4], []);
|
||||
$titles = fn (array $groups): array => array_merge(...array_map(fn ($customer) => array_merge(...array_map(fn ($job) => array_map(fn ($row) => $row->task->taskTitle, $job->rows), $customer->jobs)), $groups));
|
||||
|
||||
expect($titles($sections['pinned']))->toBe(['Pinned done with hours', 'Pinned open'])
|
||||
->and($titles($sections['scheduled']))->toBe(['Hours only', 'Scheduled']);
|
||||
});
|
||||
Reference in New Issue
Block a user