employee = User::factory()->create(); $this->actingAs($this->employee); $this->task = TaskModel::factory()->assignedTo([$this->employee->id])->create(['title' => 'Mainoskuvat']); $this->monday = now()->startOfWeek()->toDateString(); }); it('saves and clears a cell of the weekly view', function () { $this->get(route('time.week'))->assertOk()->assertSee('Mainoskuvat'); Livewire::test('time::week') ->call('saveCell', $this->task->id, $this->monday, '2,5') ->assertSee('2,5 h.') ->call('saveCell', $this->task->id, $this->monday, '1,1') ->assertHasErrors(["cells.{$this->task->id}.{$this->monday}"]); expect((float) TimeEntryModel::query()->sole()->hours)->toBe(2.5); Livewire::test('time::week')->call('saveCell', $this->task->id, $this->monday, ''); expect(TimeEntryModel::query()->count())->toBe(0); }); 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'); $week = Livewire::test('time::week'); expect(fn () => $week->set('week', '2026-05-20'))->toThrow(CannotUpdateLockedPropertyException::class) ->and(fn () => $week->set('selectedDay', "x'); alert(1); ('"))->toThrow(CannotUpdateLockedPropertyException::class); $week->call('selectDay', "x'); alert(1); ('")->assertSet('selectedDay', now()->toDateString()); }); it('adds hours from the task page to the day entry and locks done jobs', function () { Livewire::test('time::task', ['task' => $this->task->id]) ->set('workedOn', $this->monday) ->set('hours', '2') ->call('save') ->set('hours', '1,5') ->set('note', 'Lisää kuvia') ->call('save') ->assertSee('kirjaus on nyt 3,5 h.'); expect(TimeEntryModel::query()->count())->toBe(1); $this->task->customer_job_id && DB::table('customer_jobs')->where('id', $this->task->customer_job_id)->update(['status' => 'done']); Livewire::test('time::task', ['task' => $this->task->id])->assertSee('tunnit on lukittu'); }); it('keeps subcontractors to their own jobs and blocks removing tasks with hours', function () { TimeEntryModel::factory()->create(['task_id' => $this->task->id, 'user_id' => $this->employee->id]); expect(fn () => app(RemoveTask::class)->execute($this->task->customer_job_id, $this->task->id)) ->toThrow(TaskHasTimeEntries::class); $this->actingAs(User::factory()->subcontractor()->create()); $this->get(route('time.task', $this->task->id))->assertForbidden(); });