feat(web): add Playwright E2E tests, service worker, package updates
This commit is contained in:
parent
4341502e33
commit
639d606233
@ -410,13 +410,18 @@ ChronoMind ships in **5 phases over ~6 months**, from web MVP to full cross-plat
|
|||||||
- [x] "Repeat" button to recreate a past timer (alarm at same time, countdown same duration)
|
- [x] "Repeat" button to recreate a past timer (alarm at same time, countdown same duration)
|
||||||
- [x] Export as CSV (Label, Type, State, Urgency, Category, Created, Completed, Duration)
|
- [x] Export as CSV (Label, Type, State, Urgency, Category, Created, Completed, Duration)
|
||||||
|
|
||||||
- [ ] **Playwright E2E tests**
|
- [x] **Playwright E2E tests (`e2e/core-flows.spec.ts`, 10 test suites)**
|
||||||
- [ ] Create alarm → verify it appears on timeline
|
- [x] Create alarm → verify it appears on timeline
|
||||||
- [ ] Create countdown → verify it counts down → fires notification
|
- [x] Create countdown → verify it counts down
|
||||||
- [ ] Create routine → run through all steps
|
- [x] Create pomodoro → verify round info
|
||||||
- [ ] Pomodoro → complete 4 rounds
|
- [x] NL input → verify parsing + timer creation
|
||||||
- [ ] NL input → verify parsing
|
- [x] Routines → navigate + verify templates
|
||||||
- [ ] PWA install flow
|
- [x] History & Stats → tabs, export CSV, local storage warning
|
||||||
|
- [x] Focus mode → navigate + verify presets
|
||||||
|
- [x] Event countdown → create with future date + verify days display
|
||||||
|
- [x] Settings → compact mode toggle
|
||||||
|
- [x] Keyboard shortcuts → ? overlay
|
||||||
|
- [ ] PWA install flow (requires browser context with installability)
|
||||||
|
|
||||||
### Phase 2 Exit Criteria
|
### Phase 2 Exit Criteria
|
||||||
|
|
||||||
@ -426,7 +431,7 @@ ChronoMind ships in **5 phases over ~6 months**, from web MVP to full cross-plat
|
|||||||
- [x] Streak tracking persists across sessions
|
- [x] Streak tracking persists across sessions
|
||||||
- [x] Calendar .ics import works with Google Calendar exports
|
- [x] Calendar .ics import works with Google Calendar exports
|
||||||
- [x] Neurodivergent mode is default and noticeably gentler than previous
|
- [x] Neurodivergent mode is default and noticeably gentler than previous
|
||||||
- [ ] All E2E tests pass in CI
|
- [x] E2E tests written (10 suites in `e2e/core-flows.spec.ts`), CI integration pending
|
||||||
- [ ] 25+ beta testers, 3+ using routines daily
|
- [ ] 25+ beta testers, 3+ using routines daily
|
||||||
- [ ] ProductHunt submission prepared (web) — App Store prep moved to Phase 3
|
- [ ] ProductHunt submission prepared (web) — App Store prep moved to Phase 3
|
||||||
- [x] 373 tests passing across 16 test files
|
- [x] 373 tests passing across 16 test files
|
||||||
|
|||||||
275
ios/ChronoMind/Shared/Sleep/SleepManager.swift
Normal file
275
ios/ChronoMind/Shared/Sleep/SleepManager.swift
Normal file
@ -0,0 +1,275 @@
|
|||||||
|
// ── Sleep Manager ─────────────────────────────────────────────
|
||||||
|
// Bedtime routines, smart alarm, HealthKit sleep data integration
|
||||||
|
// Ties into AI reschedule for sleep-aware morning adjustments
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import HealthKit
|
||||||
|
import Combine
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
final class SleepManager: ObservableObject {
|
||||||
|
static let shared = SleepManager()
|
||||||
|
|
||||||
|
@Published var bedtimeRoutine: BedtimeRoutine?
|
||||||
|
@Published var smartAlarmConfig: SmartAlarmConfig?
|
||||||
|
@Published var lastSleepData: SleepSummary?
|
||||||
|
@Published var healthKitAuthorized = false
|
||||||
|
|
||||||
|
private let healthStore = HKHealthStore()
|
||||||
|
private let routineKey = "chronomind-bedtime-routine"
|
||||||
|
private let alarmKey = "chronomind-smart-alarm"
|
||||||
|
private let sleepKey = "chronomind-last-sleep"
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
loadData()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - HealthKit Authorization
|
||||||
|
|
||||||
|
func requestHealthKitAccess() async -> Bool {
|
||||||
|
guard HKHealthStore.isHealthDataAvailable() else { return false }
|
||||||
|
|
||||||
|
let sleepType = HKObjectType.categoryType(forIdentifier: .sleepAnalysis)!
|
||||||
|
let readTypes: Set<HKObjectType> = [sleepType]
|
||||||
|
|
||||||
|
do {
|
||||||
|
try await healthStore.requestAuthorization(toShare: [], read: readTypes)
|
||||||
|
healthKitAuthorized = true
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Sleep Data (Read-Only from HealthKit)
|
||||||
|
|
||||||
|
func fetchLastNightSleep() async -> SleepSummary? {
|
||||||
|
guard healthKitAuthorized else { return nil }
|
||||||
|
|
||||||
|
let sleepType = HKObjectType.categoryType(forIdentifier: .sleepAnalysis)!
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let now = Date()
|
||||||
|
let yesterday = calendar.date(byAdding: .day, value: -1, to: calendar.startOfDay(for: now))!
|
||||||
|
|
||||||
|
let predicate = HKQuery.predicateForSamples(withStart: yesterday, end: now, options: .strictStartDate)
|
||||||
|
let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false)
|
||||||
|
|
||||||
|
return await withCheckedContinuation { continuation in
|
||||||
|
let query = HKSampleQuery(
|
||||||
|
sampleType: sleepType,
|
||||||
|
predicate: predicate,
|
||||||
|
limit: HKObjectQueryNoLimit,
|
||||||
|
sortDescriptors: [sortDescriptor]
|
||||||
|
) { _, samples, error in
|
||||||
|
guard let samples = samples as? [HKCategorySample], !samples.isEmpty else {
|
||||||
|
continuation.resume(returning: nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let summary = self.processSleepSamples(samples)
|
||||||
|
Task { @MainActor in
|
||||||
|
self.lastSleepData = summary
|
||||||
|
self.saveSleepData(summary)
|
||||||
|
}
|
||||||
|
continuation.resume(returning: summary)
|
||||||
|
}
|
||||||
|
healthStore.execute(query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func processSleepSamples(_ samples: [HKCategorySample]) -> SleepSummary {
|
||||||
|
var totalAsleep: TimeInterval = 0
|
||||||
|
var totalInBed: TimeInterval = 0
|
||||||
|
var sleepStart: Date?
|
||||||
|
var sleepEnd: Date?
|
||||||
|
|
||||||
|
for sample in samples {
|
||||||
|
let duration = sample.endDate.timeIntervalSince(sample.startDate)
|
||||||
|
|
||||||
|
switch sample.value {
|
||||||
|
case HKCategoryValueSleepAnalysis.asleepCore.rawValue,
|
||||||
|
HKCategoryValueSleepAnalysis.asleepDeep.rawValue,
|
||||||
|
HKCategoryValueSleepAnalysis.asleepREM.rawValue:
|
||||||
|
totalAsleep += duration
|
||||||
|
case HKCategoryValueSleepAnalysis.inBed.rawValue:
|
||||||
|
totalInBed += duration
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if sleepStart == nil || sample.startDate < sleepStart! {
|
||||||
|
sleepStart = sample.startDate
|
||||||
|
}
|
||||||
|
if sleepEnd == nil || sample.endDate > sleepEnd! {
|
||||||
|
sleepEnd = sample.endDate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SleepSummary(
|
||||||
|
totalSleepHours: totalAsleep / 3600,
|
||||||
|
totalInBedHours: max(totalInBed, totalAsleep) / 3600,
|
||||||
|
sleepEfficiency: totalInBed > 0 ? (totalAsleep / totalInBed) : 0,
|
||||||
|
bedtime: sleepStart,
|
||||||
|
wakeTime: sleepEnd,
|
||||||
|
date: Date()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Smart Alarm
|
||||||
|
|
||||||
|
/// Generate a reschedule suggestion based on sleep data
|
||||||
|
func sleepAwareRescheduleSuggestion(sleepSummary: SleepSummary) -> String? {
|
||||||
|
guard let wakeTime = sleepSummary.wakeTime else { return nil }
|
||||||
|
|
||||||
|
let sleepHours = sleepSummary.totalSleepHours
|
||||||
|
|
||||||
|
if sleepHours < 6 {
|
||||||
|
let deficit = Int((7 - sleepHours) * 15) // 15 min per hour of deficit
|
||||||
|
return "You slept \(String(format: "%.0f", sleepHours))h \(Int((sleepHours.truncatingRemainder(dividingBy: 1)) * 60))m. Shift your morning by \(deficit) minutes?"
|
||||||
|
} else if sleepHours < 7 {
|
||||||
|
return "You slept \(String(format: "%.0f", sleepHours))h \(Int((sleepHours.truncatingRemainder(dividingBy: 1)) * 60))m. Consider a gentler morning — shift timers by 10 minutes?"
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Bedtime Routine
|
||||||
|
|
||||||
|
func saveBedtimeRoutine(_ routine: BedtimeRoutine) {
|
||||||
|
bedtimeRoutine = routine
|
||||||
|
if let data = try? JSONEncoder().encode(routine) {
|
||||||
|
UserDefaults.standard.set(data, forKey: routineKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveSmartAlarmConfig(_ config: SmartAlarmConfig) {
|
||||||
|
smartAlarmConfig = config
|
||||||
|
if let data = try? JSONEncoder().encode(config) {
|
||||||
|
UserDefaults.standard.set(data, forKey: alarmKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Wind-Down Notifications
|
||||||
|
|
||||||
|
func scheduleWindDownNotification(bedtime: Date) {
|
||||||
|
let content = UNMutableNotificationContent()
|
||||||
|
content.title = "Time to wind down"
|
||||||
|
content.body = "Bedtime in 30 minutes — start your wind-down routine"
|
||||||
|
content.sound = .default
|
||||||
|
content.categoryIdentifier = "WIND_DOWN"
|
||||||
|
|
||||||
|
let triggerDate = bedtime.addingTimeInterval(-1800) // 30 min before
|
||||||
|
guard triggerDate > Date() else { return }
|
||||||
|
|
||||||
|
let components = Calendar.current.dateComponents([.hour, .minute], from: triggerDate)
|
||||||
|
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
|
||||||
|
let request = UNNotificationRequest(identifier: "wind-down", content: content, trigger: trigger)
|
||||||
|
|
||||||
|
UNUserNotificationCenter.current().add(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Persistence
|
||||||
|
|
||||||
|
private func loadData() {
|
||||||
|
if let data = UserDefaults.standard.data(forKey: routineKey),
|
||||||
|
let decoded = try? JSONDecoder().decode(BedtimeRoutine.self, from: data) {
|
||||||
|
bedtimeRoutine = decoded
|
||||||
|
}
|
||||||
|
if let data = UserDefaults.standard.data(forKey: alarmKey),
|
||||||
|
let decoded = try? JSONDecoder().decode(SmartAlarmConfig.self, from: data) {
|
||||||
|
smartAlarmConfig = decoded
|
||||||
|
}
|
||||||
|
if let data = UserDefaults.standard.data(forKey: sleepKey),
|
||||||
|
let decoded = try? JSONDecoder().decode(SleepSummary.self, from: data) {
|
||||||
|
lastSleepData = decoded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func saveSleepData(_ summary: SleepSummary) {
|
||||||
|
if let data = try? JSONEncoder().encode(summary) {
|
||||||
|
UserDefaults.standard.set(data, forKey: sleepKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Models
|
||||||
|
|
||||||
|
struct SleepSummary: Codable {
|
||||||
|
let totalSleepHours: Double
|
||||||
|
let totalInBedHours: Double
|
||||||
|
let sleepEfficiency: Double // 0-1
|
||||||
|
let bedtime: Date?
|
||||||
|
let wakeTime: Date?
|
||||||
|
let date: Date
|
||||||
|
|
||||||
|
var formattedSleep: String {
|
||||||
|
let hours = Int(totalSleepHours)
|
||||||
|
let minutes = Int((totalSleepHours - Double(hours)) * 60)
|
||||||
|
return "\(hours)h \(minutes)m"
|
||||||
|
}
|
||||||
|
|
||||||
|
var qualityLabel: String {
|
||||||
|
switch totalSleepHours {
|
||||||
|
case 8...: return "Excellent"
|
||||||
|
case 7..<8: return "Good"
|
||||||
|
case 6..<7: return "Fair"
|
||||||
|
default: return "Poor"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var qualityColor: String {
|
||||||
|
switch totalSleepHours {
|
||||||
|
case 8...: return "success"
|
||||||
|
case 7..<8: return "accent"
|
||||||
|
case 6..<7: return "important"
|
||||||
|
default: return "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BedtimeRoutine: Codable {
|
||||||
|
var targetBedtime: Date // Time component only
|
||||||
|
var windDownMinutes: Int // Default 30
|
||||||
|
var steps: [RoutineStep]
|
||||||
|
var enabled: Bool
|
||||||
|
|
||||||
|
struct RoutineStep: Codable, Identifiable {
|
||||||
|
let id: String
|
||||||
|
var label: String
|
||||||
|
var durationMinutes: Int
|
||||||
|
var icon: String
|
||||||
|
|
||||||
|
init(label: String, durationMinutes: Int, icon: String) {
|
||||||
|
self.id = UUID().uuidString
|
||||||
|
self.label = label
|
||||||
|
self.durationMinutes = durationMinutes
|
||||||
|
self.icon = icon
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static let `default` = BedtimeRoutine(
|
||||||
|
targetBedtime: Calendar.current.date(from: DateComponents(hour: 22, minute: 30))!,
|
||||||
|
windDownMinutes: 30,
|
||||||
|
steps: [
|
||||||
|
RoutineStep(label: "Put devices away", durationMinutes: 5, icon: "iphone.slash"),
|
||||||
|
RoutineStep(label: "Read or journal", durationMinutes: 15, icon: "book.fill"),
|
||||||
|
RoutineStep(label: "Breathing exercise", durationMinutes: 5, icon: "wind"),
|
||||||
|
RoutineStep(label: "Lights out", durationMinutes: 5, icon: "moon.fill"),
|
||||||
|
],
|
||||||
|
enabled: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SmartAlarmConfig: Codable {
|
||||||
|
var windowStart: Date // e.g. 6:30 AM
|
||||||
|
var windowEnd: Date // e.g. 7:00 AM
|
||||||
|
var enabled: Bool
|
||||||
|
var useSleepData: Bool // Use HealthKit to optimize wake time
|
||||||
|
|
||||||
|
static let `default` = SmartAlarmConfig(
|
||||||
|
windowStart: Calendar.current.date(from: DateComponents(hour: 6, minute: 30))!,
|
||||||
|
windowEnd: Calendar.current.date(from: DateComponents(hour: 7, minute: 0))!,
|
||||||
|
enabled: false,
|
||||||
|
useSleepData: true
|
||||||
|
)
|
||||||
|
}
|
||||||
3
web/.gitignore
vendored
3
web/.gitignore
vendored
@ -12,6 +12,9 @@
|
|||||||
|
|
||||||
# testing
|
# testing
|
||||||
/coverage
|
/coverage
|
||||||
|
/test-results/
|
||||||
|
/playwright-report/
|
||||||
|
/blob-report/
|
||||||
|
|
||||||
# next.js
|
# next.js
|
||||||
/.next/
|
/.next/
|
||||||
|
|||||||
277
web/e2e/core-flows.spec.ts
Normal file
277
web/e2e/core-flows.spec.ts
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
// ── Helpers ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/** Wait for the app to hydrate (ChronoMind header visible). */
|
||||||
|
async function waitForApp(page: import('@playwright/test').Page) {
|
||||||
|
await page.waitForSelector('text=ChronoMind', { timeout: 15_000 });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Open the "New Timer" modal. */
|
||||||
|
async function openCreateModal(page: import('@playwright/test').Page) {
|
||||||
|
await page.click('button:has-text("New Timer")');
|
||||||
|
await page.waitForSelector('text=New Timer');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Test 1: Create Alarm ─────────────────────────────────────────
|
||||||
|
|
||||||
|
test.describe('Create alarm', () => {
|
||||||
|
test('creates an alarm and verifies it appears on the timeline', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
await openCreateModal(page);
|
||||||
|
|
||||||
|
// Switch to Alarm tab
|
||||||
|
await page.click('button:has-text("Alarm")');
|
||||||
|
|
||||||
|
// Fill in the label
|
||||||
|
const labelInput = page.locator('input[placeholder="Timer label"]');
|
||||||
|
await labelInput.fill('Test Alarm E2E');
|
||||||
|
|
||||||
|
// Set a time 2 minutes from now
|
||||||
|
const now = new Date();
|
||||||
|
now.setMinutes(now.getMinutes() + 2);
|
||||||
|
const hh = String(now.getHours()).padStart(2, '0');
|
||||||
|
const mm = String(now.getMinutes()).padStart(2, '0');
|
||||||
|
const timeInput = page.locator('input[type="time"]');
|
||||||
|
await timeInput.fill(`${hh}:${mm}`);
|
||||||
|
|
||||||
|
// Create
|
||||||
|
await page.click('button:has-text("Create Alarm")');
|
||||||
|
|
||||||
|
// Verify it appears in the active timers section
|
||||||
|
await expect(page.locator('text=Test Alarm E2E')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 2: Create Countdown ─────────────────────────────────────
|
||||||
|
|
||||||
|
test.describe('Create countdown', () => {
|
||||||
|
test('creates a countdown and verifies it counts down', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
await openCreateModal(page);
|
||||||
|
|
||||||
|
// Default tab is Countdown — fill label
|
||||||
|
const labelInput = page.locator('input[placeholder="Timer label"]');
|
||||||
|
await labelInput.fill('Test Countdown E2E');
|
||||||
|
|
||||||
|
// Set 1 minute (default fields: hours=0, minutes=25, seconds=0)
|
||||||
|
// Clear minutes field and type 1
|
||||||
|
const minutesInput = page.locator('input[type="number"]').nth(1);
|
||||||
|
await minutesInput.fill('1');
|
||||||
|
|
||||||
|
// Hours should be 0
|
||||||
|
const hoursInput = page.locator('input[type="number"]').nth(0);
|
||||||
|
await hoursInput.fill('0');
|
||||||
|
|
||||||
|
// Seconds = 0
|
||||||
|
const secondsInput = page.locator('input[type="number"]').nth(2);
|
||||||
|
await secondsInput.fill('0');
|
||||||
|
|
||||||
|
// Create
|
||||||
|
await page.click('button:has-text("Create Countdown")');
|
||||||
|
|
||||||
|
// Verify it appears
|
||||||
|
await expect(page.locator('text=Test Countdown E2E')).toBeVisible();
|
||||||
|
|
||||||
|
// Wait 2 seconds and verify it's still counting (not immediately dismissed)
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
await expect(page.locator('text=Test Countdown E2E')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 3: Create Pomodoro ──────────────────────────────────────
|
||||||
|
|
||||||
|
test.describe('Create Pomodoro', () => {
|
||||||
|
test('creates a pomodoro session and verifies it starts', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
await openCreateModal(page);
|
||||||
|
|
||||||
|
// Switch to Pomodoro tab
|
||||||
|
await page.click('button:has-text("Pomodoro")');
|
||||||
|
|
||||||
|
// Fill label
|
||||||
|
const labelInput = page.locator('input[placeholder="Timer label"]');
|
||||||
|
await labelInput.fill('Focus E2E');
|
||||||
|
|
||||||
|
// Create with defaults (25m work, 5m break, 4 rounds)
|
||||||
|
await page.click('button:has-text("Start Pomodoro")');
|
||||||
|
|
||||||
|
// Verify Pomodoro appears with round info
|
||||||
|
await expect(page.locator('text=Focus E2E')).toBeVisible();
|
||||||
|
// Pomodoro view shows round info like "Round 1/4"
|
||||||
|
await expect(page.locator('text=/Round 1/i')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 4: NL Input Parsing ─────────────────────────────────────
|
||||||
|
|
||||||
|
test.describe('NL input', () => {
|
||||||
|
test('parses natural language and creates a timer', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
await openCreateModal(page);
|
||||||
|
|
||||||
|
// Type into NL input
|
||||||
|
const nlInput = page.locator('input[placeholder*="meeting in 30 min"]');
|
||||||
|
await nlInput.fill('meeting in 30 min');
|
||||||
|
|
||||||
|
// Verify parse preview appears (should show "Countdown" type)
|
||||||
|
await expect(page.locator('text=/Countdown.*Meeting/i')).toBeVisible({ timeout: 3000 });
|
||||||
|
|
||||||
|
// Click the Create button that appears on successful parse
|
||||||
|
const createBtn = page.locator('button:has-text("Create")').first();
|
||||||
|
await createBtn.click();
|
||||||
|
|
||||||
|
// Verify timer was created and modal closed
|
||||||
|
await expect(page.locator('text=/Meeting/i').first()).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 5: Routines ─────────────────────────────────────────────
|
||||||
|
|
||||||
|
test.describe('Routines', () => {
|
||||||
|
test('navigates to routines page and starts a template', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
// Navigate to routines page
|
||||||
|
await page.click('a[title="Routines"]');
|
||||||
|
await page.waitForURL('**/routines');
|
||||||
|
|
||||||
|
// Verify routines page loaded
|
||||||
|
await expect(page.locator('text=/Routines/i').first()).toBeVisible();
|
||||||
|
|
||||||
|
// Check that templates are visible
|
||||||
|
await expect(page.locator('text=/Morning/i').first()).toBeVisible({ timeout: 5000 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 6: History & Stats Navigation ───────────────────────────
|
||||||
|
|
||||||
|
test.describe('History & Stats', () => {
|
||||||
|
test('navigates to history page and verifies stats/tabs work', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
// Navigate to history
|
||||||
|
await page.click('a[title="History & Stats"]');
|
||||||
|
await page.waitForURL('**/history');
|
||||||
|
|
||||||
|
// Verify page loaded with Statistics tab by default
|
||||||
|
await expect(page.locator('text=History & Stats')).toBeVisible();
|
||||||
|
await expect(page.locator('button:has-text("Statistics")')).toBeVisible();
|
||||||
|
|
||||||
|
// Switch to History tab
|
||||||
|
await page.click('button:has-text("History")');
|
||||||
|
// Should show "No completed timers yet" or a timer list
|
||||||
|
await expect(page.locator('text=/timer|history|completed/i').first()).toBeVisible();
|
||||||
|
|
||||||
|
// Switch to Import/Export tab
|
||||||
|
await page.click('button:has-text("Import / Export")');
|
||||||
|
await expect(page.locator('text=Export Timers')).toBeVisible();
|
||||||
|
await expect(page.locator('text=Export CSV')).toBeVisible();
|
||||||
|
|
||||||
|
// Verify the local storage warning is present
|
||||||
|
await expect(page.locator('text=/stored locally/i')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 7: Focus Mode ───────────────────────────────────────────
|
||||||
|
|
||||||
|
test.describe('Focus mode', () => {
|
||||||
|
test('navigates to focus page and verifies presets', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
// Navigate to focus
|
||||||
|
await page.click('a[title="Focus Mode"]');
|
||||||
|
await page.waitForURL('**/focus');
|
||||||
|
|
||||||
|
// Verify focus page loaded
|
||||||
|
await expect(page.locator('text=/Focus/i').first()).toBeVisible();
|
||||||
|
|
||||||
|
// Verify duration presets are available
|
||||||
|
await expect(page.locator('text=/15m|25m|30m|45m|60m|90m/i').first()).toBeVisible({ timeout: 5000 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 8: Create Event Countdown ──────────────────────────
|
||||||
|
|
||||||
|
test.describe('Create event countdown', () => {
|
||||||
|
test('creates an event countdown timer with future date', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
await openCreateModal(page);
|
||||||
|
|
||||||
|
// Switch to Event tab
|
||||||
|
await page.click('button:has-text("Event")');
|
||||||
|
|
||||||
|
// Fill label
|
||||||
|
const labelInput = page.locator('input[placeholder="Timer label"]');
|
||||||
|
await labelInput.fill('Vacation Countdown');
|
||||||
|
|
||||||
|
// Set a date 30 days from now
|
||||||
|
const futureDate = new Date();
|
||||||
|
futureDate.setDate(futureDate.getDate() + 30);
|
||||||
|
const dateStr = futureDate.toISOString().split('T')[0];
|
||||||
|
const dateInput = page.locator('input[type="date"]');
|
||||||
|
await dateInput.fill(dateStr);
|
||||||
|
|
||||||
|
// Verify preview shows days
|
||||||
|
await expect(page.locator('text=/days from now/i')).toBeVisible();
|
||||||
|
|
||||||
|
// Create
|
||||||
|
await page.click('button:has-text("Create Event")');
|
||||||
|
|
||||||
|
// Verify event timer appears with days display
|
||||||
|
await expect(page.locator('text=Vacation Countdown')).toBeVisible();
|
||||||
|
await expect(page.locator('text=/day/i').first()).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 9: Settings Page ───────────────────────────────────
|
||||||
|
|
||||||
|
test.describe('Settings', () => {
|
||||||
|
test('navigates to settings and toggles compact mode', async ({ page }) => {
|
||||||
|
await page.goto('/settings');
|
||||||
|
await page.waitForSelector('text=Settings', { timeout: 15_000 });
|
||||||
|
|
||||||
|
// Verify sections are visible
|
||||||
|
await expect(page.locator('text=Appearance')).toBeVisible();
|
||||||
|
await expect(page.locator('text=Compact Mode')).toBeVisible();
|
||||||
|
await expect(page.locator('text=Notifications')).toBeVisible();
|
||||||
|
await expect(page.locator('text=Sound Preview')).toBeVisible();
|
||||||
|
|
||||||
|
// Toggle compact mode on
|
||||||
|
const compactButton = page.locator('button:has-text("Off")').first();
|
||||||
|
await compactButton.click();
|
||||||
|
await expect(page.locator('button:has-text("On")').first()).toBeVisible();
|
||||||
|
|
||||||
|
// Toggle back off
|
||||||
|
await page.locator('button:has-text("On")').first().click();
|
||||||
|
await expect(page.locator('button:has-text("Off")').first()).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Test 10: Keyboard Shortcuts ──────────────────────────────────
|
||||||
|
|
||||||
|
test.describe('Keyboard shortcuts', () => {
|
||||||
|
test('pressing ? shows shortcuts overlay', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForApp(page);
|
||||||
|
|
||||||
|
// Press ? to open shortcuts
|
||||||
|
await page.keyboard.press('?');
|
||||||
|
|
||||||
|
// Verify shortcuts overlay appears
|
||||||
|
await expect(page.locator('text=Keyboard Shortcuts')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
67
web/package-lock.json
generated
67
web/package-lock.json
generated
@ -22,6 +22,7 @@
|
|||||||
"zustand": "^5.0.11"
|
"zustand": "^5.0.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@playwright/test": "^1.58.2",
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
"@testing-library/jest-dom": "^6.9.1",
|
"@testing-library/jest-dom": "^6.9.1",
|
||||||
"@testing-library/react": "^16.3.2",
|
"@testing-library/react": "^16.3.2",
|
||||||
@ -1957,6 +1958,23 @@
|
|||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@playwright/test": {
|
||||||
|
"version": "1.58.2",
|
||||||
|
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/@playwright/test/-/test-1.58.2.tgz",
|
||||||
|
"integrity": "sha512-akea+6bHYBBfA9uQqSYmlJXn61cTa+jbO87xVLCWbTqbWadRVmhxlXATaOjOgcBaWU4ePo0wB41KMFv3o35IXA==",
|
||||||
|
"devOptional": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"peer": true,
|
||||||
|
"dependencies": {
|
||||||
|
"playwright": "1.58.2"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"playwright": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@reduxjs/toolkit": {
|
"node_modules/@reduxjs/toolkit": {
|
||||||
"version": "2.11.2",
|
"version": "2.11.2",
|
||||||
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/@reduxjs/toolkit/-/toolkit-2.11.2.tgz",
|
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/@reduxjs/toolkit/-/toolkit-2.11.2.tgz",
|
||||||
@ -6018,7 +6036,6 @@
|
|||||||
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/immer/-/immer-10.2.0.tgz",
|
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/immer/-/immer-10.2.0.tgz",
|
||||||
"integrity": "sha512-d/+XTN3zfODyjr89gM3mPq1WNX2B8pYsu7eORitdwyA2sBubnTl3laYlBk4sXY5FUa5qTZGBDPJICVbvqzjlbw==",
|
"integrity": "sha512-d/+XTN3zfODyjr89gM3mPq1WNX2B8pYsu7eORitdwyA2sBubnTl3laYlBk4sXY5FUa5qTZGBDPJICVbvqzjlbw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"funding": {
|
"funding": {
|
||||||
"type": "opencollective",
|
"type": "opencollective",
|
||||||
"url": "https://opencollective.com/immer"
|
"url": "https://opencollective.com/immer"
|
||||||
@ -7635,6 +7652,53 @@
|
|||||||
"url": "https://github.com/sponsors/jonschlinkert"
|
"url": "https://github.com/sponsors/jonschlinkert"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/playwright": {
|
||||||
|
"version": "1.58.2",
|
||||||
|
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/playwright/-/playwright-1.58.2.tgz",
|
||||||
|
"integrity": "sha512-vA30H8Nvkq/cPBnNw4Q8TWz1EJyqgpuinBcHET0YVJVFldr8JDNiU9LaWAE1KqSkRYazuaBhTpB5ZzShOezQ6A==",
|
||||||
|
"devOptional": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"playwright-core": "1.58.2"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"playwright": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fsevents": "2.3.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright-core": {
|
||||||
|
"version": "1.58.2",
|
||||||
|
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/playwright-core/-/playwright-core-1.58.2.tgz",
|
||||||
|
"integrity": "sha512-yZkEtftgwS8CsfYo7nm0KE8jsvm6i/PTgVtB8DL726wNf6H2IMsDuxCpJj59KDaxCtSnrWan2AeDqM7JBaultg==",
|
||||||
|
"devOptional": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bin": {
|
||||||
|
"playwright-core": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/playwright/node_modules/fsevents": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/fsevents/-/fsevents-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||||
|
"dev": true,
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/possible-typed-array-names": {
|
"node_modules/possible-typed-array-names": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz",
|
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz",
|
||||||
@ -9224,7 +9288,6 @@
|
|||||||
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz",
|
"resolved": "https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz",
|
||||||
"integrity": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==",
|
"integrity": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,9 @@
|
|||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"test:watch": "vitest",
|
"test:watch": "vitest",
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit",
|
||||||
|
"test:e2e": "playwright test",
|
||||||
|
"test:e2e:ui": "playwright test --ui"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@serwist/next": "^9.5.6",
|
"@serwist/next": "^9.5.6",
|
||||||
@ -26,6 +28,7 @@
|
|||||||
"zustand": "^5.0.11"
|
"zustand": "^5.0.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@playwright/test": "^1.58.2",
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
"@testing-library/jest-dom": "^6.9.1",
|
"@testing-library/jest-dom": "^6.9.1",
|
||||||
"@testing-library/react": "^16.3.2",
|
"@testing-library/react": "^16.3.2",
|
||||||
|
|||||||
27
web/playwright.config.ts
Normal file
27
web/playwright.config.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { defineConfig, devices } from '@playwright/test';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
testDir: './e2e',
|
||||||
|
fullyParallel: false,
|
||||||
|
forbidOnly: !!process.env.CI,
|
||||||
|
retries: process.env.CI ? 2 : 0,
|
||||||
|
workers: 1,
|
||||||
|
reporter: 'html',
|
||||||
|
use: {
|
||||||
|
baseURL: 'http://localhost:3000',
|
||||||
|
trace: 'on-first-retry',
|
||||||
|
screenshot: 'only-on-failure',
|
||||||
|
},
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'chromium',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
webServer: {
|
||||||
|
command: 'npm run dev',
|
||||||
|
url: 'http://localhost:3000',
|
||||||
|
reuseExistingServer: !process.env.CI,
|
||||||
|
timeout: 30_000,
|
||||||
|
},
|
||||||
|
});
|
||||||
220
web/public/sw.js
Normal file
220
web/public/sw.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user