2026-07-16 06:19:58 -04:00
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
|
import { login } from './helpers/auth';
|
|
|
|
|
import { testHabits } from './helpers/fixtures';
|
|
|
|
|
|
2026-08-10 08:53:18 +00:00
|
|
|
test.describe('Habits', () => {
|
2026-07-16 06:19:58 -04:00
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
|
await login(page);
|
|
|
|
|
await page.goto('/habits');
|
|
|
|
|
await expect(page.getByRole('heading', { name: /habits/i })).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-10 08:53:18 +00:00
|
|
|
test('shows the empty state when there are no habits', async ({ page }) => {
|
|
|
|
|
if (await page.getByText('No habits yet').isVisible().catch(() => false)) {
|
|
|
|
|
await expect(page.getByText(/create your first one/i)).toBeVisible();
|
|
|
|
|
}
|
2026-07-16 06:19:58 -04:00
|
|
|
});
|
|
|
|
|
|
2026-08-10 08:53:18 +00:00
|
|
|
test('creates a habit via the New Habit dialog', async ({ page }) => {
|
|
|
|
|
await page.getByRole('button', { name: /new habit/i }).click();
|
2026-07-16 06:19:58 -04:00
|
|
|
|
2026-08-10 08:53:18 +00:00
|
|
|
const dialog = page.getByRole('dialog');
|
|
|
|
|
await expect(dialog).toBeVisible();
|
|
|
|
|
await expect(dialog.getByRole('heading', { name: 'New Habit' })).toBeVisible();
|
2026-07-16 06:19:58 -04:00
|
|
|
|
2026-08-10 08:53:18 +00:00
|
|
|
await dialog.getByLabel('Name').fill(testHabits.name);
|
|
|
|
|
await dialog.getByLabel('Description').fill(testHabits.description);
|
|
|
|
|
await dialog.getByRole('button', { name: /create habit/i }).click();
|
2026-07-16 06:19:58 -04:00
|
|
|
|
2026-08-10 08:53:18 +00:00
|
|
|
// The dialog closes and the habit appears in the list.
|
|
|
|
|
await expect(dialog).toBeHidden();
|
|
|
|
|
await expect(page.getByText(testHabits.name, { exact: true })).toBeVisible({
|
|
|
|
|
timeout: 10_000,
|
2026-07-16 06:19:58 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-10 08:53:18 +00:00
|
|
|
test('marks a habit complete from the list', async ({ page }) => {
|
|
|
|
|
// Ensure the fixture habit exists.
|
|
|
|
|
if (!(await page.getByText(testHabits.name, { exact: true }).isVisible().catch(() => false))) {
|
|
|
|
|
await page.getByRole('button', { name: /new habit/i }).click();
|
|
|
|
|
const dialog = page.getByRole('dialog');
|
|
|
|
|
await dialog.getByLabel('Name').fill(testHabits.name);
|
|
|
|
|
await dialog.getByRole('button', { name: /create habit/i }).click();
|
|
|
|
|
await expect(page.getByText(testHabits.name, { exact: true })).toBeVisible({ timeout: 10_000 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Completing today's habit bumps the streak to 1 day.
|
|
|
|
|
await page.getByRole('button', { name: /mark .* complete/i }).first().click();
|
|
|
|
|
await expect(page.getByText('1 day streak', { exact: true })).toBeVisible({ timeout: 10_000 });
|
2026-07-16 06:19:58 -04:00
|
|
|
});
|
|
|
|
|
});
|