[ui] LetterSlot: Add the page for A Letter from the Gardener, shown once the author writes it
docs/LETTER.md holds slots as comments only, so the player sees no change
until the author writes. The app bundles the letter at build time, a small
Markdown subset renders without {@html}, only https: and tel: become links,
and lint:copy now reads the letter. Review found turbo replaying a stale
build after the letter changed; docs/LETTER.md is now in its cache key.
This commit is contained in:
@@ -1,10 +1,23 @@
|
||||
import { PRODUCT_NAME } from '@rosea/schema';
|
||||
import { cleanup, render, screen } from '@testing-library/svelte';
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/svelte';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import Shell from '../src/Shell.svelte';
|
||||
import { en } from '../src/copy/en.js';
|
||||
|
||||
afterEach(cleanup);
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
window.location.hash = '';
|
||||
});
|
||||
|
||||
const LETTER = [
|
||||
'# Why',
|
||||
'',
|
||||
'A line.',
|
||||
'',
|
||||
'[Read](https://example.org) or [call](tel:+420123) or [not](javascript:alert(1)).'
|
||||
].join('\n');
|
||||
|
||||
const h1 = (): HTMLElement => screen.getByRole('heading', { level: 1 });
|
||||
|
||||
describe('Shell', () => {
|
||||
it('names the product in the page heading, from the schema constant', () => {
|
||||
@@ -24,3 +37,49 @@ describe('Shell', () => {
|
||||
expect(screen.getByRole('main')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Shell and the Letter', () => {
|
||||
it('with an empty letter offers no way to it, and #letter shows the garden', () => {
|
||||
window.location.hash = '#letter';
|
||||
render(Shell, { letter: '<!-- Slot: the signature. -->\n' });
|
||||
expect(h1().textContent).toBe(PRODUCT_NAME);
|
||||
expect(screen.queryAllByRole('link')).toEqual([]);
|
||||
});
|
||||
|
||||
it('with a letter, a link opens it, Back returns, and focus follows each heading', async () => {
|
||||
render(Shell, { letter: LETTER });
|
||||
expect(document.activeElement, 'nothing is focused on first load').toBe(document.body);
|
||||
|
||||
await fireEvent.click(screen.getByRole('link', { name: en.letter.title }));
|
||||
await waitFor(() => expect(h1().textContent).toBe(en.letter.title));
|
||||
await waitFor(() => expect(document.activeElement).toBe(h1()));
|
||||
expect(screen.getByRole('heading', { level: 2 }).textContent).toBe('Why');
|
||||
expect(screen.getByRole('main')).toBeTruthy();
|
||||
|
||||
await fireEvent.click(screen.getByRole('link', { name: en.letter.back }));
|
||||
await waitFor(() => expect(h1().textContent).toBe(PRODUCT_NAME));
|
||||
await waitFor(() => expect(document.activeElement).toBe(h1()));
|
||||
});
|
||||
|
||||
it('opens straight at #letter, as from a bookmark', () => {
|
||||
window.location.hash = '#letter';
|
||||
render(Shell, { letter: LETTER });
|
||||
expect(h1().textContent).toBe(en.letter.title);
|
||||
});
|
||||
|
||||
it('renders https links in a new tab with no referrer, tel links in place, and nothing else as a link', () => {
|
||||
window.location.hash = '#letter';
|
||||
render(Shell, { letter: LETTER });
|
||||
const read = screen.getByRole('link', { name: 'Read' });
|
||||
expect(read.getAttribute('href')).toBe('https://example.org');
|
||||
expect(read.getAttribute('target')).toBe('_blank');
|
||||
expect(read.getAttribute('rel')).toBe('noopener noreferrer');
|
||||
|
||||
const call = screen.getByRole('link', { name: 'call' });
|
||||
expect(call.getAttribute('href')).toBe('tel:+420123');
|
||||
expect(call.getAttribute('target')).toBeNull();
|
||||
|
||||
expect(screen.queryByRole('link', { name: 'not' })).toBeNull();
|
||||
expect(screen.getByText(/or not\./)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user