// First-run setup (plan step 6.14b, "done when"): a fresh install (an empty database, no manager) // sends the sign-in page to the setup wizard; the wizard is filled in Greek (it switches language // at once), finishes, and the new owner signs in and reaches the overview. // Starts its own backend (:8065, an empty data folder) and the manager (:5189). // node setup.mjs import path from 'node:path' import { mkdtempSync, openSync } from 'node:fs' import { spawn } from 'node:child_process' import { chromium } from 'playwright' import { BROWSER_CHANNEL, CS, OUT, reporter } from './lib/env.mjs' import { killTree, startBackend, waitHttp } from './lib/proc.mjs' const dataDir = mkdtempSync(path.join(OUT, 'fresh-')) // no pos.db: the backend creates it const backend = await startBackend({ port: 8065, dataDir }) const APP = 'http://localhost:5189' const log = openSync(path.join(OUT, 'vite-5189.log'), 'w') const vite = spawn('npx', ['vite', '--port', '5189', '--strictPort'], { cwd: path.join(CS, 'manager_dashboard'), shell: process.platform === 'win32', detached: process.platform !== 'win32', stdio: ['ignore', log, log], env: { ...process.env, XENIA_BACKEND: backend.url }, }) const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {}) const r = reporter('setup (6.14b): a fresh install goes through the wizard, in Greek, to the overview') const errors = [] try { await waitHttp(APP) const page = await browser.newPage({ locale: 'en-US' }) page.on('pageerror', e => errors.push(String(e))) const status = await fetch(`${backend.url}/api/setup/status`).then(x => x.json()) r.check('a fresh install needs setup', status.needs_setup === true, JSON.stringify(status)) await page.goto(`${APP}/login`) const wizard = page.getByTestId('setup-wizard') r.check('the sign-in page sends to the wizard', await wizard.waitFor({ timeout: 60_000 }).then(() => true).catch(() => false) && new URL(page.url()).pathname === '/setup') r.check('…in English for an English browser', (await wizard.textContent()).includes('Welcome to Xenia POS')) await page.getByTestId('setup-lang-el').click() r.check('choosing Ελληνικά switches the wizard at once', await page.getByText('Καλώς ήρθατε στο Xenia POS').waitFor({ timeout: 5000 }).then(() => true).catch(() => false)) await page.getByTestId('setup-start').click() await page.getByTestId('setup-next').click() r.check('the account step says what is missing', await wizard.getAttribute('data-step') === 'account' && (await wizard.textContent()).includes('Υποχρεωτικό')) await page.getByTestId('setup-username').fill('olga') await page.getByTestId('setup-full-name').fill('Όλγα Ιδιοκτήτρια') await page.getByTestId('setup-password').fill('kalimera1') await page.getByTestId('setup-confirm').fill('kalimera1') await page.getByTestId('setup-next').click() await page.getByTestId('setup-type-coffee_shop').click() await page.getByTestId('setup-venue-name').fill('Καφέ E2E') r.check('the venue step starts in Greek with the browser\'s time zone', await page.getByTestId('setup-language').inputValue() === 'el' && !!(await page.getByTestId('setup-timezone').inputValue())) await page.getByTestId('setup-next').click() await page.getByTestId('setup-pin').fill('2468') await page.getByTestId('setup-pin-again').fill('2468') await page.getByTestId('setup-next').click() await page.screenshot({ path: path.join(OUT, 'setup-done.png'), fullPage: true }) await page.getByTestId('setup-finish').click() r.check('finishing goes to the sign-in page', await page.getByTestId('login-form').waitFor({ timeout: 15_000 }).then(() => true).catch(() => false)) const boot = await fetch(`${backend.url}/api/platform/bootstrap`).then(x => x.json()) r.check('the venue is set up in Greek', boot.venue?.language === 'el', JSON.stringify(boot.venue)) await page.locator('input[type=password]').waitFor({ timeout: 10_000 }) if (!(await page.getByTestId('login-account').count())) await page.locator('input[autocomplete=username]').fill('olga') // one manager: the form shows the account await page.locator('input[type=password]').fill('kalimera1') await page.locator('button[type=submit]').click() r.check('the new owner signs in and reaches the overview', await page.getByTestId('overview').waitFor({ timeout: 20_000 }).then(() => true).catch(() => false)) await page.screenshot({ path: path.join(OUT, 'setup-overview.png'), fullPage: true }) r.check('the setup is done (no second owner can be made)', (await fetch(`${backend.url}/api/setup/status`).then(x => x.json())).needs_setup === false) r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | ')) } finally { await browser.close() killTree(vite) await backend.stop() } process.exit(r.done() ? 1 : 0)