user = User::factory()->create(['name' => 'Eetu Esimerkki']); $this->actingAs($this->user); $this->job = CustomerJobModel::factory()->create(['status' => 'order', 'number' => '2026-0042', 'name' => 'Messuvideo']); $this->task = TaskModel::factory()->assignedTo([$this->user->id])->create(['customer_job_id' => $this->job->id, 'title' => 'Kuvauspäivä']); foreach ([1, 2] as $number) { NotificationModel::query()->create([ 'user_id' => $this->user->id, 'type' => 'task_starts_soon', 'params' => ['task_id' => $this->task->id, 'task_title' => 'Kuvauspäivä', 'job_id' => $this->job->id, 'job_number' => '2026-0042', 'job_name' => 'Messuvideo', 'starts_on' => '2026-11-30'], 'dedupe_key' => 'browser:'.$number, 'created_at' => now()->subHours($number), ]); } }); it('has no accessibility issues with the notifications closed and open', function (string $device, string $colorScheme) { $visit = visit(route('jobs.index')); $visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop(); $visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode(); $visit->assertNoJavaScriptErrors() ->assertSeeIn('[data-notifications-bell]', '2') ->assertNoAccessibilityIssues(level: 2) ->click('[data-notifications-bell]') ->assertVisible('#notifications-panel') ->assertSee('Uusi') ->assertNoAccessibilityIssues(level: 2); })->with([ 'desktop, light' => ['desktop', 'light'], 'desktop, dark' => ['desktop', 'dark'], 'mobile, light' => ['mobile', 'light'], 'mobile, dark' => ['mobile', 'dark'], ]); it('opens with the keyboard, marks the notifications seen and closes with Escape', function () { visit(route('jobs.index')) ->assertScript("document.querySelector('[data-notifications-bell]').getAttribute('aria-describedby')", 'notifications-count') ->assertSeeIn('#notifications-count', '2 lukematonta ilmoitusta') ->keys('[data-notifications-bell]', 'Enter') ->assertVisible('#notifications-panel') ->assertSeeIn('#notifications-count', 'Ei lukemattomia ilmoituksia') ->assertScript("document.querySelector('[data-notifications-bell]').getAttribute('aria-expanded')", 'true') ->keys('[data-notifications-bell]', 'Escape') ->assertMissing('#notifications-panel') ->assertScript("document.activeElement.hasAttribute('data-notifications-bell')", true) ->resize(320, 900) ->click('[data-notifications-bell]') ->assertScript('document.documentElement.scrollWidth <= window.innerWidth', true); expect(NotificationModel::query()->whereNull('seen_at')->count())->toBe(0); }); it('opens the task from a notification', function () { visit(route('jobs.index')) ->click('[data-notifications-bell]') ->click('#notifications-panel li:first-child a') ->assertPathIs('/jobs/'.$this->job->id) ->assertVisible('#task-'.$this->task->id.'-details'); });