155 lines
6.8 KiB
PHP
155 lines
6.8 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-scheduled-'.$this->task->id.'-'.$tuesday;
|
|
|
|
visit(route('time.week'))
|
|
->on()->desktop()
|
|
->clear($cell)
|
|
->type($cell, '2:30')
|
|
->keys($cell, 'Tab')
|
|
->assertSee('Tallennettu: Mainoskuvat')
|
|
->assertSee('Viikko yhteensä: 4:00 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-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();
|
|
|
|
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ä:')
|
|
->assertSee('1:30')
|
|
->click('Hyväksy viikko')
|
|
->assertSee('Hyväksytyt tunnit on lukittu.')
|
|
->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']);
|