Something went wrong. Try again.
A free, open-source, self-hosted place to write a novel.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104import { expect, test } from '@playwright/test';import { enterLibrary } from './session.ts';
/** * A goal, the words it counts, and the streak the writer has to ask for. * * The run makes its own project, so the day's count is exactly the words typed * here. Sharing the example project would make today's count depend on file * order. */test('sets a goal, counts words today, and keeps the streak off until asked', async ({ page }) => { await enterLibrary(page);
// An empty library offers "Start a project" instead; both open the same form. await page.getByRole('button', { name: /^(New project|Start a project)$/ }).click(); await page.getByLabel('What is the project called?').fill(`Longhand ${Date.now()}`); await page.getByRole('button', { name: 'Create', exact: true }).click();
await expect(page).toHaveURL(/\/p\/.+/); await expect(page.locator('.ProseMirror')).toBeVisible();
/* * "Words today" comes from the save response, so this also proves the route * echoed the day's total. The name is exact because the manuscript tree's * rows are buttons too. */ await page.locator('.ProseMirror').click(); await page.keyboard.type('One two three four five six seven eight nine ten eleven twelve '); await expect(page.locator('.foot-today')).toContainText('today 12');
await page.getByRole('button', { name: 'Progress', exact: true }).click(); const panel = page.getByRole('complementary', { name: 'Progress' }); const readout = panel.locator('.readout');
// The streak is off until the writer asks for it. await expect(readout).toContainText('12'); await expect(readout).not.toContainText('Streak');
await panel.getByLabel('Words a day').fill('20'); await panel.getByRole('button', { name: 'Save', exact: true }).click(); await expect(readout).toContainText('12 / 20'); await expect(readout).not.toContainText('met');
await panel.getByLabel('Words a day').fill('5'); await panel.getByRole('button', { name: 'Save', exact: true }).click(); await expect(readout).toContainText('12 / 5'); await expect(readout).toContainText('met');
await panel.getByLabel('Show a streak').check(); await panel.getByRole('button', { name: 'Save', exact: true }).click(); await expect(readout).toContainText('1 day');
/* * The box is found by value, not label: the manuscript tree's `aria-label` * makes a scene called "Mon" a second match. A day off survives a reload. */ const monday = panel.locator('input[name="daysOff"][value="1"]'); await monday.check(); await panel.getByRole('button', { name: 'Save', exact: true }).click(); await expect(monday).toBeChecked();
// Today's words count toward a deadline set today, so the readout answers at once. const aim = new Date(); aim.setDate(aim.getDate() + 14); const deadline = `${aim.getFullYear()}-${String(aim.getMonth() + 1).padStart(2, '0')}-${String(aim.getDate()).padStart(2, '0')}`;
await panel.getByLabel('Words to add').fill('100'); await panel.getByLabel('By', { exact: true }).fill(deadline); await panel.getByRole('button', { name: 'Save', exact: true }).click(); await expect(readout).toContainText('Deadline'); await expect(readout).toContainText('12 / 100');
await page.reload(); await expect(page.locator('.ProseMirror')).toBeVisible(); await page.getByRole('button', { name: 'Progress', exact: true }).click(); const reopened = page.getByRole('complementary', { name: 'Progress' });
await expect(reopened.locator('.readout')).toContainText('12 / 5'); await expect(reopened.locator('.readout')).toContainText('12 / 100'); await expect(reopened.getByLabel('Words to add')).toHaveValue('100'); await expect(reopened.getByLabel('By', { exact: true })).toHaveValue(deadline); await expect(reopened.locator('input[name="daysOff"][value="1"]')).toBeChecked(); await expect(reopened.getByLabel('Show a streak')).toBeChecked();
// Clearing the target leaves the day's words, the streak and the deadline alone. await reopened.getByLabel('Words a day').fill('0'); await reopened.getByRole('button', { name: 'Save', exact: true }).click(); const todayRow = reopened.locator('.readout > div').first(); await expect(todayRow).not.toContainText('/'); await expect(todayRow).toContainText('12'); await expect(reopened.locator('.readout')).toContainText('1 day'); await expect(reopened.locator('.readout')).toContainText('12 / 100'); await expect(page.locator('.foot-today')).toContainText('today 12'); await expect(page.locator('.foot-today')).not.toContainText('no goal');
// Clearing both deadline fields removes it without touching the streak. await reopened.getByLabel('Words to add').fill('0'); await reopened.getByLabel('By', { exact: true }).fill(''); await reopened.getByRole('button', { name: 'Save', exact: true }).click(); await expect(reopened.locator('.readout')).not.toContainText('Deadline'); await expect(reopened.locator('.readout')).toContainText('1 day'); await expect(page.locator('.foot-today')).toContainText('no goal');});