diff --git a/web/src/pages/404.astro b/web/src/pages/404.astro index 0c8b0e9..7ea20c1 100644 --- a/web/src/pages/404.astro +++ b/web/src/pages/404.astro @@ -1,10 +1,14 @@ --- // Any address with no page (the server serves this with a real 404). import PageHead from '../components/PageHead.astro' +import { iconEntry } from '../icons/registry' import Shell from '../layouts/Shell.astro' --- - + {/* data-static-icons: boot decorates the icon with the user's word and glyph (icons/render.ts). */} + diff --git a/web/src/sections/overview.ts b/web/src/sections/overview.ts index a6d3518..a379d9b 100644 --- a/web/src/sections/overview.ts +++ b/web/src/sections/overview.ts @@ -19,8 +19,8 @@ export class BacklogOverviewElement extends LiveElement { protected update(): void { const { data, error } = q.dataset.state - const aside = link('/backlog/', glyph('➡️', 'Open the planner')) - const icon = '📚' + const aside = link('/backlog/', glyph('action.open', 'Open the planner')) + const icon = 'dash.outlook' if (!data) { this.replaceChildren(card('Backlog outlook', error ? errorNotice(error) : loading('backlog'), { aside, icon })) return diff --git a/web/src/sections/pages.icons.test.ts b/web/src/sections/pages.icons.test.ts new file mode 100644 index 0000000..816b8b2 --- /dev/null +++ b/web/src/sections/pages.icons.test.ts @@ -0,0 +1,104 @@ +// Pass 2 wiring for the dashboard, picks, store, setup and library pages: +// a ledger word shows right of its icon, a chosen alternative glyph replaces +// the default, and the spoken text is unchanged. + +import { screen, waitFor } from '@testing-library/dom' +import { describe, expect, it } from 'vitest' +import { makeInstalled, makeLibGame, makeStatus } from '../test/fixtures' +import { mount, stubApi } from '../test/harness' +import { useIcons } from '../test/iconLedger' +import './dashboard' +import './library' +import './picks' +import './setup' +import './store' + +const word = (el: Element | null | undefined) => el?.nextElementSibling?.textContent +const markOf = (root: ParentNode, id: string) => root.querySelector(`[data-icon="${id}"], [data-icon-word="${id}"]`) + +describe('dashboard icons', () => { + it('a fact row paints its icon word and chosen glyph, the label stays spoken', async () => { + useIcons({ 'dash.finished': { word: 'trophies', glyph: '🥇' }, 'state.yes': { word: 'yes' } }) + stubApi({ 'GET /api/status': makeStatus(), 'GET /api/commands': [] }) + mount('') + const label = await screen.findByText('Games finished', { selector: 'dt .sr-only' }) + const icon = label.closest('dt')?.querySelector('[data-icon="dash.finished"]') + expect(icon?.textContent).toBe('🥇') + expect(word(icon)).toBe('Trophies') + expect(label).toHaveClass('sr-only') + const installed = screen.getByText('Installed', { selector: 'dt .sr-only' }).closest('dt')?.nextElementSibling + expect(word(installed?.querySelector('[data-icon="state.yes"]'))).toBe('Yes') + }) + + it('the store row and the block countdown use their own icons', async () => { + useIcons({ 'dash.store-blocked': { word: 'shut' }, 'dash.block-left': { word: 'left' } }) + stubApi({ + 'GET /api/status': makeStatus({ total_block: { active: true, days_remaining: 2, until: null } }), + 'GET /api/commands': [], + }) + const el = mount('') + await screen.findAllByText('Store', { selector: 'dt .sr-only' }) + expect(word(markOf(el, 'dash.store-blocked'))).toBe('Shut') + expect(word(markOf(el, 'dash.block-left'))).toBe('Left') + }) +}) + +describe('store notice icon', () => { + it('paints the store-lock icon, its word and glyph, the sentence stays spoken', async () => { + useIcons({ 'store.blocked': { word: 'sealed', glyph: '🛑' } }) + stubApi({ 'GET /api/status': makeStatus({ store_blocked: true }) }) + mount('') + const notice = await screen.findByRole('status') + const icon = markOf(notice, 'store.blocked') + expect(icon?.textContent).toBe('🛑') + expect(word(icon)).toBe('Sealed') + expect(screen.getByText(/Store blocked\./)).toHaveClass('sr-only') + }) +}) + +describe('picks icons', () => { + it('a pick row paints the age icon and the kept pin with their words', async () => { + const pick = (app_id: number, name: string) => ({ app_id, name, age_days: 3 }) + useIcons({ 'picks.age': { word: 'picked' }, 'picks.kept': { word: 'kept', glyph: '💚' } }) + stubApi({ + 'GET /api/status': makeStatus({ manual_picks: [pick(1, 'Celeste')], kept_picks: [pick(2, 'Hades')] }), + 'GET /api/commands': [], + }) + const el = mount('') + await screen.findByText('Celeste') + expect(word(markOf(el, 'picks.age'))).toBe('Picked') + const kept = markOf(el, 'picks.kept') + expect(kept?.textContent).toBe('💚') + expect(word(kept)).toBe('Kept') + expect(screen.getByText('· picked 3 d ago · 1')).toHaveClass('sr-only') + }) +}) + +describe('setup icons', () => { + it('the field icons and the stored-key placeholder follow the ledger', async () => { + useIcons({ 'setup.api-key': { word: 'key' }, 'setup.key-stored': { word: 'stored', glyph: '🔐' } }) + stubApi({ 'GET /api/setup': { configured: true, has_api_key: true, steam_id: '76561198000000000' } }) + const el = mount('') + expect(word(markOf(el, 'setup.api-key'))).toBe('Key') + expect(screen.getByLabelText('Steam Web API key')).toBeInTheDocument() + await waitFor(() => { + expect(screen.getByLabelText('Steam Web API key').placeholder).toBe(`🔐 Stored ${'•'.repeat(32)}`) + }) + }) +}) + +describe('library page icons', () => { + it('the installed table headers and the view switch paint their words', async () => { + useIcons({ 'libpage.size': { word: 'space', glyph: '📏' }, 'libpage.all': { word: 'covers' } }) + stubApi({ + 'GET /api/library': { games: [makeLibGame({ app_id: 1, name: 'Hollow Knight' })] }, + 'GET /api/installed': { games: [makeInstalled({ app_id: 5, name: 'Portal' })] }, + 'GET /api/commands': [], + }) + mount('') + const th = (await screen.findByText('Size', { selector: 'th .sr-only' })).closest('th') + expect(th?.querySelector('[data-icon="libpage.size"]')?.textContent).toBe('📏') + expect(word(th?.querySelector('[data-icon="libpage.size"]'))).toBe('Space') + expect(screen.getByRole('button', { name: 'All games' })).toHaveTextContent('Covers') + }) +}) diff --git a/web/src/sections/setup.ts b/web/src/sections/setup.ts index 239e96a..c7b5da2 100644 --- a/web/src/sections/setup.ts +++ b/web/src/sections/setup.ts @@ -7,6 +7,8 @@ import { api } from '../api/client' import { q } from '../api/queries' import { Action } from '../lib/action' +import type { IconId } from '../icons/registry' +import { iconFor, iconInline } from '../icons/render' import { append, define, h, type Child } from '../lib/dom' import { LiveElement } from '../lib/element' import { invalidateAll } from '../lib/query' @@ -27,9 +29,9 @@ export function idError(id: string): string | null { return ID_RE.test(id.trim()) ? null : 'A SteamID64 is 17 digits and starts with 7656.' } -// Textgate: help is a 🔗 to where the value comes from; its sentence is spoken only. +// Textgate: help is a link icon to where the value comes from; its sentence is spoken only. const helpLink = (href: string, spoken: string, sentence: string): Child[] => [ - h('a', { href, target: '_blank', rel: 'noreferrer', class: 'setup-link', 'aria-label': spoken }, '🔗'), + h('a', { href, target: '_blank', rel: 'noreferrer', class: 'setup-link', 'aria-label': spoken }, iconInline('setup.help')), h('span', { class: 'sr-only' }, sentence), ] const KEY_HELP = (): Child[] => @@ -38,19 +40,24 @@ const ID_HELP = (): Child[] => helpLink('https://steamid.io', 'steamid.io', 'You /** Placeholders paint the expected shape: one dot per character, the fixed 7656 prefix. */ const KEY_SHAPE = '·'.repeat(32) -const KEY_STORED = `🔒 ${'•'.repeat(32)}` const ID_SHAPE = `7656${'·'.repeat(13)}` +/** A placeholder is plain text: the stored-key icon (and its word, if any) then filled dots. */ +function keyStored(): string { + const { glyph: mark, word } = iconFor('setup.key-stored') + return `${mark}${word ? ` ${word}` : ''} ${'•'.repeat(32)}` +} + interface Field { input: HTMLInputElement help: HTMLParagraphElement hint: () => Child[] baseClass: string - /** Characters a valid value has; a bad value paints `⚠️ typed/want`. */ + /** Characters a valid value has; a bad value paints the warning icon and `typed/want`. */ want: number } -function field(id: string, label: string, icon: string, input: HTMLInputElement, hint: () => Child[], want: number): { el: HTMLDivElement; f: Field } { +function field(id: string, label: string, icon: IconId, input: HTMLInputElement, hint: () => Child[], want: number): { el: HTMLDivElement; f: Field } { const help = h('p', { id: `${id}-help`, class: 'field-help' }, hint()) input.id = id input.setAttribute('aria-describedby', `${id}-help`) @@ -59,7 +66,7 @@ function field(id: string, label: string, icon: string, input: HTMLInputElement, 'div', { class: 'form-field' }, // The glyph is painted beside a spoken-only