[ui] DaySentence: Her folded petal, the words and their source; the library bundled after validation
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"id": "e2e-first",
|
||||
"text": { "en": "An e2e fixture sentence, not a real one." },
|
||||
"source": { "work": "Fixture 1", "author": null, "tradition": "fixture", "translation": null, "publicDomain": true, "verifiedBy": "e2e", "verifiedAt": "2026-11-01" },
|
||||
"use": ["sunset"],
|
||||
"tone": "gentle",
|
||||
"promisesOutcome": false
|
||||
},
|
||||
{
|
||||
"id": "e2e-second",
|
||||
"text": { "en": "A second e2e fixture sentence." },
|
||||
"source": { "work": "Fixture 2", "author": "A Writer", "tradition": "fixture", "translation": null, "publicDomain": true, "verifiedBy": "e2e", "verifiedAt": "2026-11-01" },
|
||||
"use": ["sunset"],
|
||||
"tone": "gentle",
|
||||
"promisesOutcome": false
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,91 @@
|
||||
import AxeBuilder from '@axe-core/playwright';
|
||||
import { expect, test, type Page } from '@playwright/test';
|
||||
import { en } from '@rosea/ui/copy';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { startStaticServer, type StaticServer } from './static-server.js';
|
||||
import { storedCare } from './stored.js';
|
||||
import fixture from './fixtures/library/fixture.json' with { type: 'json' };
|
||||
|
||||
/**
|
||||
* The rose's folded petal (.agents/features/day-sentence.md), in the BUILT app.
|
||||
*
|
||||
* The shipped library is empty until the author verifies sentences, so the main
|
||||
* build can only show that there is no petal. This spec also builds the app a second
|
||||
* time, with a fixture library (ROSEA_LIBRARY_DIR, P5), into a folder of its own, and
|
||||
* serves that. The second build passes through the same validate:library step.
|
||||
*/
|
||||
const ROOT = fileURLToPath(new URL('..', import.meta.url));
|
||||
const MORNING = Date.parse('2026-03-01T10:00:00+01:00');
|
||||
const texts = fixture.map((s) => s.text.en);
|
||||
|
||||
test.use({ timezoneId: 'Europe/Prague', locale: 'en-US' });
|
||||
|
||||
let server: StaticServer;
|
||||
test.beforeEach(async () => {
|
||||
server = await startStaticServer();
|
||||
});
|
||||
test.afterEach(async () => {
|
||||
await server.close();
|
||||
});
|
||||
|
||||
async function open(page: Page): Promise<void> {
|
||||
await page.clock.setFixedTime(MORNING);
|
||||
await page.goto(server.url);
|
||||
await expect(page.getByRole('button', { name: en.rose.water })).toBeVisible();
|
||||
}
|
||||
|
||||
test('with the shipped library still empty, she holds no petal and says nothing about one', async ({ page }) => {
|
||||
await open(page);
|
||||
await expect(page.getByRole('button', { name: en.rose.petal.open })).toHaveCount(0);
|
||||
await expect(page.getByText(en.rose.petal.waiting)).toHaveCount(0);
|
||||
});
|
||||
|
||||
test.describe('with a fixture library', () => {
|
||||
let dist: string;
|
||||
test.beforeAll(() => {
|
||||
dist = mkdtempSync(join(tmpdir(), 'rosea-petal-'));
|
||||
// The same build the player gets, with the fixture library in place of the real one.
|
||||
execSync(`pnpm --filter @rosea/app run build --outDir "${dist}" --emptyOutDir`, {
|
||||
cwd: ROOT,
|
||||
env: { ...process.env, ROSEA_LIBRARY_DIR: 'e2e/fixtures/library' },
|
||||
stdio: 'pipe'
|
||||
});
|
||||
});
|
||||
test.afterAll(() => {
|
||||
rmSync(dist, { recursive: true, force: true });
|
||||
});
|
||||
test.beforeEach(() => server.serveFrom(dist));
|
||||
|
||||
test('open her petal: the words and their source; a reload keeps it open, and no second one today', async ({ page }) => {
|
||||
await open(page);
|
||||
await page.getByRole('button', { name: en.rose.petal.open }).click();
|
||||
const words = page.locator('blockquote');
|
||||
await expect(words).toHaveCount(1);
|
||||
const said = (await words.textContent()) ?? '';
|
||||
expect(texts).toContain(said);
|
||||
|
||||
await storedCare(page, 1);
|
||||
await page.reload();
|
||||
await expect(page.getByRole('button', { name: en.rose.petal.today })).toHaveAttribute('aria-expanded', 'true');
|
||||
await expect(page.locator('blockquote')).toHaveText(said);
|
||||
await expect(page.getByRole('button', { name: en.rose.petal.open })).toHaveCount(0);
|
||||
|
||||
// Tomorrow, the next one is folded.
|
||||
await page.clock.setFixedTime(MORNING + 24 * 3_600_000);
|
||||
await page.reload();
|
||||
await expect(page.getByRole('button', { name: en.rose.petal.open })).toBeVisible();
|
||||
});
|
||||
|
||||
test('the folded and the open petal have no accessibility violations', async ({ page }) => {
|
||||
await open(page);
|
||||
await expect(page.getByRole('button', { name: en.rose.petal.open })).toBeVisible();
|
||||
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||
await page.getByRole('button', { name: en.rose.petal.open }).click();
|
||||
await expect(page.locator('blockquote')).toBeVisible();
|
||||
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -7,7 +7,7 @@ import { defineConfig, devices } from '@playwright/test';
|
||||
*/
|
||||
export default defineConfig({
|
||||
testDir: '.',
|
||||
testMatch: /(shell|update)\.spec\.ts/,
|
||||
testMatch: /(shell|update|petal)\.spec\.ts/,
|
||||
fullyParallel: false,
|
||||
workers: 1,
|
||||
retries: 0,
|
||||
|
||||
+1
-1
@@ -253,7 +253,7 @@ test.describe('keep her safe, in Prague at 08:00 on 1 March 2026', () => {
|
||||
} finally {
|
||||
await first.close();
|
||||
}
|
||||
expect(JSON.parse(saved)).toMatchObject({ format: 'rosea-rose', version: 1 });
|
||||
expect(JSON.parse(saved)).toMatchObject({ format: 'rosea-rose', version: 2 });
|
||||
expect(saved).not.toMatch(/Brno|privateKey/);
|
||||
|
||||
// A fresh profile: the shape of an evicted garden, or a new phone.
|
||||
|
||||
Reference in New Issue
Block a user