import { test, expect } from '@playwright/test'; import { login } from './helpers/auth'; import { testHabits } from './helpers/fixtures'; test.describe('Habit Tracking', () => { test.beforeEach(async ({ page }) => { await login(page); await page.goto('/habits'); // Wait for the habits page to load await expect(page.getByRole('heading', { name: /habits/i })).toBeVisible(); }); test.describe('Habits page', () => { test('should display habits page with summary banner', async ({ page }) => { // Summary banner should show today's progress await expect(page.getByText(/today's progress/i)).toBeVisible(); await expect(page.getByText(/completion rate/i)).toBeVisible(); }); test('should show "New habit" button', async ({ page }) => { await expect(page.getByRole('button', { name: /new habit/i })).toBeVisible(); }); }); test.describe('Create habit', () => { test('should open new habit dialog when clicking "New habit"', async ({ page }) => { await page.getByRole('button', { name: /new habit/i }).click(); // A dialog or form should appear // The habit creation might be a dialog or inline form await page.waitForTimeout(500); }); }); test.describe('Habit completion', () => { test('should display habit cards in a grid', async ({ page }) => { // Habit cards should be in a grid layout const habitCards = page.locator('.grid > div, [class*="habit"]'); // Verify the grid container exists await expect(page.locator('.grid')).toBeVisible(); }); test('should show consistency heatmap section', async ({ page }) => { // The heatmap section should exist await expect(page.getByText(/consistency overview/i)).toBeVisible(); }); }); test.describe('Quick completion mode', () => { test('should complete a quick-mode habit with a single click', async ({ page }) => { // Find a habit card with a complete button const completeButtons = page.locator('button:has-text("Complete"), button[aria-label*="complete"]'); const count = await completeButtons.count(); if (count > 0) { await completeButtons.first().click(); // Should update without showing a dialog (quick mode) await page.waitForTimeout(1_000); } else { test.skip(); } }); }); test.describe('Detailed completion mode', () => { test('should open completion dialog for detailed habits', async ({ page }) => { // Detailed mode habits open a dialog with mood/quantity fields const detailedButtons = page.locator('button:has-text("Complete")'); const count = await detailedButtons.count(); if (count > 0) { // Try clicking - if it's detailed mode, a dialog should open await detailedButtons.first().click(); await page.waitForTimeout(1_000); } else { test.skip(); } }); }); test.describe('Habit streaks', () => { test('should display streak information on habit cards', async ({ page }) => { // Habit cards should show streak/fire icons const streakElements = page.locator('[class*="streak"], [class*="fire"], [class*="flame"]'); // Just verify the page loaded properly await expect(page.getByRole('heading', { name: /habits/i })).toBeVisible(); }); }); });