Files
Toiminnanohjaus/tests/Browser/TimeTrackingAccessibilityTest.php
T
petriandClaude Opus 5.5 d5cbf9d6eb Add approval of hours and lock opening for management
- Time entries store who approved them and when. Approved hours are
  locked: cells, task page edits and removals are refused.
- "Hyväksy viikko" in the weekly view approves the user's own week;
  subcontractors' hours are approved by management.
- Management gets an approval page (unapproved weeks by person, recently
  approved weeks) and can open anyone's week read-only to approve it or
  cancel its approval, which only management may do.
- Only management may move a done job back to an earlier status, which
  opens the lock on its hours and expenses; the history marks it.
- The Clock contract gets now() for approval times.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 08:24:34 +02:00

114 lines
4.9 KiB
PHP

<?php
use App\Models\User;
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->user = User::factory()->create();
$this->actingAs($this->user);
$this->task = TaskModel::factory()->assignedTo([$this->user->id])->create(['title' => 'Mainoskuvat']);
$this->monday = now()->startOfWeek()->toDateString();
TimeEntryModel::factory()->create(['task_id' => $this->task->id, 'user_id' => $this->user->id, 'worked_on' => $this->monday, 'hours' => 1.5, 'note' => 'Luonnokset']);
});
it('has no accessibility issues on the time pages and no sideways scrolling', function (string $page, string $device, string $colorScheme) {
$url = $page === 'week' ? route('time.week') : route('time.task', $this->task->id);
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee('Mainoskuvat')
->assertScript('document.documentElement.scrollWidth <= window.innerWidth', true)
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['week', 'task page'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('records hours in the weekly view with the keyboard', function () {
$tuesday = now()->startOfWeek()->addDay()->toDateString();
$cell = '#cell-'.$this->task->id.'-'.$tuesday;
visit(route('time.week'))
->on()->desktop()
->type($cell, '2,5')
->keys($cell, 'Tab')
->assertSee('Tallennettu: Mainoskuvat')
->assertSee('Viikko yhteensä: 4 h')
->assertNoAccessibilityIssues(level: 2);
expect((float) TimeEntryModel::query()->whereDate('worked_on', $tuesday)->sole()->hours)->toBe(2.5);
});
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;
$visit = visit(route('time.week'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
if ($device === 'mobile') {
$visit->click('[aria-pressed][wire\\:click="selectDay(\''.$this->monday.'\')"]');
}
$visit->clear($selector)
->type($selector, '1,1')
->keys($selector, 'Tab')
->assertSee('Anna tunnit vartin tarkkuudella')
->assertAttribute($selector, 'aria-invalid', 'true')
->assertNoAccessibilityIssues(level: 2);
})->with(['desktop', 'mobile']);
it('records hours from the task page', function () {
visit(route('time.task', $this->task->id))
->fill('[wire\\:model="workedOn"]', $this->monday)
->fill('[wire\\:model="hours"]', '2')
->press('Kirjaa tunnit')
->assertSee('kirjaus on nyt 3,5 h.')
->assertNoAccessibilityIssues(level: 2);
});
it('has no accessibility issues on the approval pages', function (string $page, string $device, string $colorScheme) {
TimeEntryModel::query()->update(['approved_at' => now(), 'approved_by' => $this->user->id]);
$other = User::factory()->employee()->create(['name' => 'Kaisa Kollega']);
TimeEntryModel::factory()->create(['task_id' => TaskModel::factory()->assignedTo([$other->id])->create()->id, 'user_id' => $other->id, 'worked_on' => $this->monday]);
$this->actingAs(User::factory()->management()->create());
$url = $page === 'approvals' ? route('time.approvals') : route('time.week', ['kayttaja' => $this->user->id]);
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee($page === 'approvals' ? 'Kaisa Kollega' : 'hyväksytty')
->assertScript('document.documentElement.scrollWidth <= window.innerWidth', true)
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['approvals', 'week of another user'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
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äksytyt tunnit on lukittu.')
->assertSee('hyväksytty')
->assertNoAccessibilityIssues(level: 2);
expect(TimeEntryModel::query()->sole()->approved_at)->not->toBeNull();
});