Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# form-builder-sample

Two small apps built with [form-builder](https://whatsaaaa.github.io/form-builder/) `1.0.0-rc.0`, using only what a new user has: the documentation site and the packages on npm. The repository is the release-candidate trial for form-builder 1.0: it shows that real forms can be built from the public material, and records every problem met on the way.
Two small apps built with [form-builder](https://whatsaaaa.github.io/form-builder/) `1.0.0-rc.0`, using only what a new user has: the documentation site and the packages on npm. The repository is the release-candidate trial for form-builder 1.0: it shows that real forms can be built from the public material, and records every problem met on the way. The apps take their look from the [Whatsaaaa design system](https://github.com/whatsaaaa/design-system), installed from npm as `@whatsaaaa/design-system` like any other package: the Vue app now, the React app once its own restyle lands.

**The record of the trial is [FRICTION-LOG.md](FRICTION-LOG.md).** Start there if you work on form-builder.

Expand All @@ -11,9 +11,9 @@ Two small apps built with [form-builder](https://whatsaaaa.github.io/form-builde
| [`vue-event-registration`](vue-event-registration) | A multi-step event registration in Vue | Steps, rows, a section and a slot, conditional fields and a conditional step, a repeating guest list, form rules, a definition loaded from a JSON file |
| [`react-checkout`](react-checkout) | A checkout in React, with a small server | A definition served by the server and validated again there, messages in English and German, a repeating list of items, conditional fields, server errors shown on the fields |

Each app is self-contained: its own `package.json`, lockfile and tooling. Both need Node 20.19 or later and pnpm 11.
Each app is self-contained: its own `package.json`, lockfile and tooling. Both need pnpm 11. The Vue app needs Node 22.18 or a later 22, or Node 24.12 or later, as the design system does. The React app needs Node 20.19 or later.

Both look plain on purpose. Everything visual lives in each app's `src/ui` folder (field, layout and page components) and its one stylesheet, `src/styles.css`, so a later restyle swaps those and leaves the forms alone.
Everything visual lives in each app's `src/ui` folder (field, layout and page components) and its one stylesheet, `src/styles.css`, so a restyle swaps those and leaves the forms alone. The Vue app is restyled on the design system: its page is the system's terminal frame, with a tab bar, a status line that switches the theme and the shortcut keys, and a dark and a light theme. The React app still looks plain until its own restyle lands.

## Run the Vue app

Expand Down
203 changes: 203 additions & 0 deletions vue-event-registration/e2e/frame.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { expect, test, type Page } from '@playwright/test'

/** The item of the status line that names the theme on show, and switches it. */
function themeName(page: Page, name: 'rose-pine' | 'rose-pine-dawn') {
return page.getByRole('button', {
name: `Switch theme, now ${name}`,
exact: true,
})
}

function keysSwitch(page: Page) {
return page.getByRole('switch', { name: 'Shortcut keys' })
}

/**
* Fails when the status line cuts what it holds. It fits in the line, and its path shows whole or
* not at all: when it shows, "~…" fits in its text box, and the text has as much room before the
* keys switch as after the mode. It is gone only when "~…" and its padding have no room there.
*/
async function expectStatusLineWhole(page: Page) {
const line = await page.locator('.ws-status-line').evaluate((line) => {
const find = (selector: string) => {
const element = line.querySelector(selector)
if (!element) throw new Error(`The status line has no ${selector}`)
return element
}
const path = find('.ws-status-line__file')
const text = find('.ws-status-line__file > span')
const pathStyle = getComputedStyle(path)
const textStyle = getComputedStyle(text)
const probe = document.createElement('span')
probe.style.position = 'absolute'
probe.style.font = textStyle.font
probe.textContent = '~…'
document.body.append(probe)
const shortest = probe.getBoundingClientRect().width
probe.remove()
const mode = find('.ws-status-line__mode').getBoundingClientRect().right
const keys = find('.ws-status-line__switch').getBoundingClientRect().left
const box = text.getBoundingClientRect()
const left = box.left + parseFloat(textStyle.paddingLeft)
const right = box.right - parseFloat(textStyle.paddingRight)
return {
overflow: line.scrollWidth - line.clientWidth,
shown: path.checkVisibility(),
room: keys - mode,
needed:
shortest +
parseFloat(pathStyle.paddingLeft) +
parseFloat(pathStyle.paddingRight) +
parseFloat(textStyle.paddingLeft) +
parseFloat(textStyle.paddingRight),
text: right - left,
shortest,
before: left - mode,
after: keys - right,
}
})
expect(line.overflow, 'the status line cuts its end').toBeLessThanOrEqual(0)
if (line.shown) {
expect(line.text, 'the path shows a cut glyph').toBeGreaterThanOrEqual(
line.shortest,
)
expect(
line.after,
'the path runs into the keys switch',
).toBeGreaterThanOrEqual(line.before)
} else {
expect(line.room, 'the path is gone with room for "~…"').toBeLessThan(
line.needed,
)
}
return line.shown
}

/** The color of the page behind the window: it changes with the theme. */
function pageColor(page: Page) {
return page.evaluate(() => getComputedStyle(document.body).backgroundColor)
}

test.beforeEach(async ({ page }) => {
await page.goto('/')
})

test.describe('on a light system', () => {
test.use({ colorScheme: 'light' })

test('switches the theme, and remembers it', async ({ page }) => {
const html = page.locator('html')

// Until it is switched, the theme is the system's.
await expect(html).not.toHaveAttribute('data-theme')
await expect(themeName(page, 'rose-pine-dawn')).toBeVisible()
await expect(themeName(page, 'rose-pine')).toBeHidden()
const light = await pageColor(page)

await themeName(page, 'rose-pine-dawn').click()
await expect(html).toHaveAttribute('data-theme', 'dark')
await expect(themeName(page, 'rose-pine')).toBeVisible()
await expect(themeName(page, 'rose-pine-dawn')).toBeHidden()
const dark = await pageColor(page)
expect(dark).not.toBe(light)

// The head script applies the choice again before the page is drawn.
await page.reload()
await expect(html).toHaveAttribute('data-theme', 'dark')
expect(await pageColor(page)).toBe(dark)

await themeName(page, 'rose-pine').click()
await expect(html).toHaveAttribute('data-theme', 'light')
expect(await pageColor(page)).toBe(light)
})
})

test('switches the shortcut keys off and on, and remembers it', async ({
page,
}) => {
const html = page.locator('html')
await expect(keysSwitch(page)).toBeChecked()
await expect(keysSwitch(page)).toHaveText(/keys\s*on/, {
useInnerText: true,
})
await expect(html).toHaveAttribute('data-ws-keys', 'on')

await keysSwitch(page).click()
await expect(keysSwitch(page)).not.toBeChecked()
await expect(keysSwitch(page)).toHaveText(/keys\s*off/, {
useInnerText: true,
})
await expect(html).toHaveAttribute('data-ws-keys', 'off')

await page.reload()
await expect(keysSwitch(page)).not.toBeChecked()
await expect(html).toHaveAttribute('data-ws-keys', 'off')

await keysSwitch(page).click()
await expect(keysSwitch(page)).toBeChecked()
await expect(html).toHaveAttribute('data-ws-keys', 'on')
})

test.describe('on a dark system', () => {
test.use({ colorScheme: 'dark' })

test('switches the theme with the t key while the keys are on', async ({
page,
isMobile,
}) => {
test.skip(isMobile, 'Key hints show on a wide screen only')
const html = page.locator('html')
const hint = page.getByRole('button', { name: 'Switch theme', exact: true })
const mode = page.locator('.ws-status-line__mode')
await expect(hint.locator('kbd')).toBeVisible()
await expect(mode).toHaveText('NORMAL')

await page.keyboard.press('t')
await expect(html).toHaveAttribute('data-theme', 'light')
await page.keyboard.press('t')
await expect(html).toHaveAttribute('data-theme', 'dark')

// A key typed into a field is only a letter.
const firstName = page.getByRole('textbox', { name: 'First name' })
await firstName.press('t')
await expect(firstName).toHaveValue('t')
await expect(mode).toHaveText('INSERT')
await expect(html).toHaveAttribute('data-theme', 'dark')
await firstName.blur()
await expect(mode).toHaveText('NORMAL')

// With the keys off, the key rests and its cap goes, but the button still works by hand.
await keysSwitch(page).click()
await expect(hint.locator('kbd')).toBeHidden()
await page.keyboard.press('t')
await expect(html).toHaveAttribute('data-theme', 'dark')
await hint.click()
await expect(html).toHaveAttribute('data-theme', 'light')
})
})

for (const colorScheme of ['dark', 'light'] as const) {
test.describe(`in the ${colorScheme} theme`, () => {
test.use({ colorScheme })

// From the width the content must reflow to (WCAG 1.4.10) up, with each width of the switch.
test('keeps the status line whole on a narrow screen', async ({ page }) => {
let shown = 0
for (const keys of ['on', 'off']) {
if (keys === 'off') await keysSwitch(page).click()
await expect(keysSwitch(page)).toHaveText(
new RegExp(`keys\\s*${keys}`),
{
useInnerText: true,
},
)
for (let width = 320; width <= 400; width += 2) {
await page.setViewportSize({ width, height: 700 })
if (await expectStatusLineWhole(page)) shown++
}
}
// The path showed at some width, so the checks of a shown path ran too.
expect(shown).toBeGreaterThan(0)
})
})
}
112 changes: 105 additions & 7 deletions vue-event-registration/e2e/registration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,25 @@ async function next(page: Page) {
await page.getByRole('button', { name: 'Next' }).click()
}

/** Fails when the page scrolls sideways: something is wider than the screen. */
/**
* Fails when something is wider than the screen: the page scrolls sideways, or a part of the
* window frame clips it or scrolls it sideways: the window, its main area, its status line, or a
* code block on show.
*/
async function expectNoSidewaysScroll(page: Page) {
const overflow = await page.evaluate(
() =>
document.documentElement.scrollWidth -
document.documentElement.clientWidth,
)
expect(overflow).toBeLessThanOrEqual(0)
const boxes = [
page.locator('html'),
page.locator('.page'),
page.locator('.page__main'),
page.locator('.ws-status-line'),
...(await page.locator('.ws-code, .ws-code > pre').all()),
]
for (const box of boxes) {
const overflow = await box.evaluate(
(element) => element.scrollWidth - element.clientWidth,
)
expect(overflow, `${box} is wider than its box`).toBeLessThanOrEqual(0)
}
}

async function fillAboutYou(
Expand Down Expand Up @@ -306,3 +317,90 @@ test('moves with Enter and with the step indicator', async ({ page }) => {
await expect(currentStep(page)).toHaveText(/Invoice/)
await expect(page.getByText('Enter the company name')).toBeVisible()
})

// 320 px is the width the content must reflow to (WCAG 1.4.10), and 390 px a common phone.
for (const width of [320, 390]) {
for (const colorScheme of ['dark', 'light'] as const) {
test.describe(`on a ${width} px screen, in the ${colorScheme} theme`, () => {
test.use({ viewport: { width, height: 844 }, colorScheme })

test('fits the screen at every step, with its errors', async ({
page,
}) => {
// The page follows the system's theme, and names it in the status line.
const name = colorScheme === 'dark' ? 'rose-pine' : 'rose-pine-dawn'
await expect(
page.getByRole('button', {
name: `Switch theme, now ${name}`,
exact: true,
}),
).toBeVisible()

await next(page)
await expect(page.getByText('Enter your first name')).toBeVisible()
await expectNoSidewaysScroll(page)
// The keys switch is a letter wider off than on, and the status line still holds it.
const keys = page.getByRole('switch', { name: 'Shortcut keys' })
await keys.click()
await expect(keys).toHaveText(/keys\s*off/, { useInnerText: true })
await expectNoSidewaysScroll(page)
await fillAboutYou(page, 'Business')
await page
.getByRole('textbox', { name: 'Phone' })
.fill('+381 61 234 5678')
await next(page)

await next(page)
await expect(page.getByText('Pick at least one session')).toBeVisible()
await expectNoSidewaysScroll(page)
await page
.getByRole('checkbox', { name: 'Hands-on forms workshop' })
.check()
await page.getByLabel('Workshop level').selectOption('Advanced')
await page
.getByRole('checkbox', { name: 'I have access or dietary needs' })
.check()
await page
.getByLabel('What do you need?')
.fill('Pristup bez stepenica, i čaj bez šećera za večeru.')
await expectNoSidewaysScroll(page)
await next(page)

await page.getByRole('button', { name: 'Add guest' }).click()
await next(page)
await expect(page.getByText("Enter the guest's name")).toBeVisible()
await expectNoSidewaysScroll(page)
await page
.getByRole('region', { name: 'Guest 1' })
.getByRole('textbox', { name: 'Name' })
.fill('Đurđa Živković')
await next(page)

await next(page)
await expect(page.getByText('Enter the company name')).toBeVisible()
await expectNoSidewaysScroll(page)
await page.getByLabel('Company name').fill('Petrović d.o.o.')
await page.getByLabel('Street and number').fill('Knez Mihailova 1')
await page.getByLabel('City').fill('Belgrade')
await page.getByLabel('ZIP code').fill('11000')
await page.getByLabel('Country').selectOption('Serbia')
await next(page)

await expect(currentStep(page)).toHaveText(/Confirm/)
await page.getByRole('button', { name: 'Register' }).click()
await expect(
page.getByText('Please accept the code of conduct'),
).toBeVisible()
await expectNoSidewaysScroll(page)
await page
.getByRole('checkbox', { name: 'I accept the code of conduct' })
.check()
await page.getByRole('button', { name: 'Register' }).click()
await expect(
page.getByRole('heading', { name: "You're registered" }),
).toBeVisible()
await expectNoSidewaysScroll(page)
})
})
}
}
6 changes: 4 additions & 2 deletions vue-event-registration/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Event registration - form-builder sample</title>
<title>Harbour Conf 2027 registration - form-builder sample</title>
<link rel="icon" href="/favicon.ico" sizes="48x48" />
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
</head>
<body>
<div id="app"></div>
Expand Down
4 changes: 3 additions & 1 deletion vue-event-registration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
},
"dependencies": {
"@formisch/vue": "^1.2.0",
"@whatsaaaa/design-system": "^0.1.0",
"@whatsaaaa/form-builder-affects": "0.2.2-rc.0",
"@whatsaaaa/form-builder-schema": "1.0.0-rc.0",
"@whatsaaaa/form-builder-vue": "1.0.0-rc.0",
"shiki": "^4.6.0",
"valibot": "^1.5.0",
"vue": "^3.5.44"
},
Expand All @@ -40,6 +42,6 @@
},
"packageManager": "pnpm@11.27.0",
"engines": {
"node": ">=20.19"
"node": "^22.18.0 || >=24.12.0"
}
}
Loading
Loading