diff --git a/e2e/editor.smoke.spec.ts b/e2e/editor.smoke.spec.ts index 0403330..5294e14 100644 --- a/e2e/editor.smoke.spec.ts +++ b/e2e/editor.smoke.spec.ts @@ -109,6 +109,95 @@ test('keeps valid images when another image in the same import batch is corrupt' await expect(page.locator('.filmstrip__count')).toHaveText('1/1') }) +const FREE_PACK_LOOKS = [ + 'Coastal Mist', + 'Golden Hour Glow', + 'Ink Stone', + 'Sage Garden', + 'Rose Fade', + 'Midnight City', + 'Ember Portrait', + 'Silver Rain', +] + +async function openPresets(page: Page) { + const tab = page.getByRole('tab', { name: 'Presets', exact: true }) + if (await tab.isVisible()) { + await tab.click() + return + } + await page.getByRole('button', { name: 'Editing tools' }).click() + await page.getByRole('button', { name: 'Presets', exact: true }).click() +} + +test('loads one sample photo from an empty-state thumbnail', async ({ page }) => { + await page.goto('/editor') + + await expect(page.getByRole('button', { name: 'Open photos' })).toBeVisible() + await expect(page.getByRole('button', { name: 'Try sample photos' })).toBeVisible() + await expect(page.getByRole('button', { name: 'Watch demo' })).toBeVisible() + await page.getByRole('button', { name: 'Open sample photo Pagoda' }).click() + + await expect(page.locator('.toolbar__status')).toHaveText('Loaded 1 image') + await expect(page.locator('canvas[aria-label="pagoda.jpg"]')).toBeVisible() +}) + +test('spanish editor localizes the empty state', async ({ page }) => { + await page.goto('/es/editor') + + const title = 'El editor de fotos open source que se queda en tu dispositivo' + await expect(page.getByRole('heading', { level: 1, name: title })).toBeVisible() + expect(await visibleH1Text(page)).toEqual([title]) + await expect(page.getByRole('button', { name: 'Abrir fotos' })).toBeVisible() + await expect(page.getByRole('button', { name: 'Probar fotos de ejemplo' })).toBeVisible() + await expect(page.getByRole('button', { name: 'Ver la demo' })).toBeVisible() + await expect(page.getByRole('button', { name: 'Abrir la foto de ejemplo Pagoda' })).toBeVisible() + await expect(page.getByRole('button', { name: 'Sin subir archivos' })).toBeVisible() + await expect(page.getByRole('heading', { level: 1, name: 'The open-source photo editor that stays on your device' })).toHaveCount(0) + await expect(page.getByRole('tab', { name: 'Editar' })).toBeVisible() + await expect(page.getByRole('button', { name: 'Abrir', exact: true })).toBeVisible() +}) + +test('lists the eight free pack looks in the presets panel', async ({ page }) => { + await page.goto('/editor') + await page.getByRole('button', { name: 'Open sample photo Pagoda' }).click() + await expect(page.locator('.toolbar__status')).toHaveText('Loaded 1 image') + + await openPresets(page) + const panel = page.getByRole('region', { name: 'Presets' }) + for (const name of FREE_PACK_LOOKS) { + await expect(panel.getByRole('button', { name, exact: true })).toBeVisible() + } + await expect(panel.getByRole('link', { name: 'Download ZIP' })).toHaveAttribute( + 'href', + '/downloads/lightframes-free-presets-luts.zip', + ) + await expect(panel.getByRole('link', { name: 'About the pack' })).toHaveAttribute('href', '/free-presets-luts') +}) + +test('spanish presets panel names the free pack in Spanish', async ({ page }) => { + await page.goto('/es/editor') + await page.getByRole('button', { name: 'Abrir la foto de ejemplo Pagoda' }).click() + await expect(page.locator('.toolbar__status')).toHaveText('1 imagen cargada') + + const tab = page.getByRole('tab', { name: 'Preajustes', exact: true }) + if (await tab.isVisible()) { + await tab.click() + } else { + await page.getByRole('button', { name: 'Herramientas de edición' }).click() + await page.getByRole('button', { name: 'Preajustes', exact: true }).click() + } + + const panel = page.getByRole('region', { name: 'Preajustes' }) + await expect(panel.getByText('Pack gratis')).toBeVisible() + await expect(panel.getByRole('button', { name: 'Bruma costera', exact: true })).toBeVisible() + await expect(panel.getByRole('link', { name: 'Descargar ZIP' })).toHaveAttribute( + 'href', + '/downloads/lightframes-free-presets-luts.zip', + ) + await expect(panel.getByRole('link', { name: 'Sobre el pack' })).toHaveAttribute('href', '/es/presets-luts-gratis') +}) + test('reports a batch with no importable images without creating a photo', async ({ page }) => { await prepareFilePicker(page, false) diff --git a/scripts/editor-copy.test.mjs b/scripts/editor-copy.test.mjs new file mode 100644 index 0000000..18acc74 --- /dev/null +++ b/scripts/editor-copy.test.mjs @@ -0,0 +1,63 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import { editorCopy, editorLangFromLocation } from '../src/lib/editorCopy.ts' +import pack from '../src/data/free-pack-looks.json' with { type: 'json' } +import { trackFreePackDownload, setAnalyticsTransportForTests } from '../src/lib/analytics.ts' + +test('editor language follows the route when html lang is missing', () => { + assert.equal(editorLangFromLocation('/editor', ''), 'en') + assert.equal(editorLangFromLocation('/es/editor', ''), 'es') + assert.equal(editorLangFromLocation('/es/editor', 'en'), 'en') + assert.equal(editorLangFromLocation('/editor', 'es'), 'es') +}) + +test('empty-state copy keeps the tagline and never says 100% private', () => { + const en = editorCopy('en') + const es = editorCopy('es') + assert.equal(en.empty.title, 'The open-source photo editor that stays on your device') + assert.equal(es.empty.title, 'El editor de fotos open source que se queda en tu dispositivo') + assert.equal(en.empty.nothingUploaded, 'Nothing uploaded') + assert.equal(es.empty.nothingUploaded, 'Sin subir archivos') + assert.deepEqual( + en.empty.samples.map((sample) => sample.file), + ['pagoda.jpg', 'twelve-apostles.jpg', 'opera-night.jpg'], + ) + assert.deepEqual( + es.empty.samples.map((sample) => sample.file), + en.empty.samples.map((sample) => sample.file), + ) + const blob = JSON.stringify({ en, es }) + assert.equal(blob.toLowerCase().includes('100% private'), false) + assert.equal(blob.toLowerCase().includes('100 % privado'), false) +}) + +test('english status lines used by the editor stay exact', () => { + const status = editorCopy('en').status + assert.equal(status.loaded(1, 1, false), 'Loaded 1 image; 1 failed') + assert.equal(status.loaded(2, 0, false), 'Loaded 2 images') + assert.equal(status.loaded(1, 0, true), 'Added 1 image') + assert.equal(status.couldNotOpen(1), 'Could not open 1 image') + assert.equal(status.couldNotOpen(2), 'Could not open 2 images') + assert.equal(status.openToBegin, 'Open images to begin') + assert.equal(status.exportFailed, 'Export failed') + assert.equal(editorCopy('es').status.loaded(1, 0, false), '1 imagen cargada') + assert.equal(editorCopy('es').status.couldNotOpen(1), 'No se ha podido abrir 1 imagen') +}) + +test('the free pack is eight looks with Spanish names', () => { + assert.equal(pack.looks.length, 8) + assert.equal(pack.looks[0].name, 'Coastal Mist') + assert.equal(pack.looks[0].nameEs, 'Bruma costera') + assert.equal(editorCopy('es').presets.freePack, 'Pack gratis') + assert.equal(editorCopy('en').presets.freePack, 'Free Pack') +}) + +test('the pack zip download event stays free_pack_download', () => { + const events = [] + setAnalyticsTransportForTests((name, props) => { + events.push({ name, props }) + }) + trackFreePackDownload('full-pack') + assert.deepEqual(events, [{ name: 'free_pack_download', props: { look: 'full-pack' } }]) + setAnalyticsTransportForTests(null) +}) diff --git a/src/App.tsx b/src/App.tsx index 9c3a91f..9e5e6e1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -30,6 +30,7 @@ import { Toast } from './components/Toast' import { ToneCurvePanel } from './components/ToneCurvePanel' import { Toolbar } from './components/Toolbar' import { PANELS, useEditorSession, type PanelId } from './hooks/useEditorSession' +import { useEditorLang } from './hooks/useEditorLang' import { PHONE_QUERY, useMediaQuery } from './hooks/useMediaQuery' import { useSheetSwipe } from './hooks/useSheetSwipe' import type { StudioApi, StudioFormat } from './hooks/useStudio' @@ -38,6 +39,7 @@ import { createCollageDoc, type CollageDoc } from './lib/collage' import { trackToolUsed } from './lib/analytics' import { aspectRatioFor, fitCropInImage, type FrameSize } from './lib/crop' import type { ClippingStats, HistogramBins } from './lib/histogram' +import { isSamplePhoto } from './lib/files' import { isRawFile } from './lib/rawDecode' import { DEFAULT_EDITS, type HealSpot, type LiquifyStroke } from './types/edits' @@ -54,6 +56,7 @@ function loadHistogramHidden(): boolean { } export default function App() { + const { copy } = useEditorLang() const [mode, setMode] = useState('edit') const modeRef = useRef(mode) useEffect(() => { @@ -427,6 +430,9 @@ export default function App() { onFrameSize={setFrameSize} onOpen={() => session.handleOpen()} onOpenSamples={session.openSamples} + onOpenSample={(name) => { + if (isSamplePhoto(name)) void session.openSample(name) + }} cropOverlay={ canEdit && session.panelFocus === 'crop' && session.cropMode ? { @@ -517,15 +523,20 @@ export default function App() { overlay={histogramHidden ? null : histogramPanel} exit={ photoTool - ? { label: `Close ${PANELS.find((p) => p.id === session.panelFocus)?.label ?? 'tool'}`, onExit: exitTool } + ? { + label: copy.panels.closeTool( + copy.panels[session.panelFocus] ?? 'tool', + ), + onExit: exitTool, + } : null } action={{ kind: 'menu', items: [ - ...PANELS.map(({ id, label }) => ({ + ...PANELS.map(({ id }) => ({ id, - label, + label: copy.panels[id], icon: , active: sheetOpen && id === session.panelFocus, onSelect: () => selectPanel(id), @@ -535,7 +546,7 @@ export default function App() { ? [ { id: 'histogram', - label: 'Histogram', + label: copy.panels.histogram, icon: , extra: true, onSelect: () => changeHistogramHidden(false), @@ -550,21 +561,25 @@ export default function App() { {/* Phones show the tool sheet only once a tool is picked: until then the photo gets the whole screen. */} {(!phone || (canEdit && sheetOpen)) && (