Files
token-circles/frontend/tests/recurring-form-errors.spec.ts
KomediruzeckiandGitHub 08ad641383 feat(forms): housing, portfolio, tags, recurring and onboarding say what is wrong at the field (slice 5 of 6) (#614)
Housing, Portfolio, Tags, the Recurring dialog, the subscription catalog and scan, and the setup
wizard move onto the form kit from #602: a refused entry is said under the field that is wrong, in
the same words in cloud and local-first. Both runtimes run one set of rules from shared/ for a
tag, a housing expense, a holding and a recurring rule, and answer a refusal with 400
{ error, fields }. An edit checks and writes only what it changes, so a row an older version
stored can still be edited.

- A tag name that is blank, over 50 characters, or another tag's in other case is refused at name.
  A colour must be #RRGGBB; a tag created without one takes the palette's next colour, and an edit
  without one keeps it.
- A housing expense is refused at the field: a name up to 100 characters, six types, an amount to
  the cent, a real due month and a day that month has (29 February taken). One posted without a
  due month falls due this month.
- A holding needs a ticker up to 20 characters, stored in capitals, shares and a price above zero
  and below one trillion, and a real date. The edit dialog sends back what is stored, and a buy
  merges only into the open profile's holding.
- A recurring rule needs a description, an amount to the cent, a type, a frequency and a next date.
  Deleting one the profile does not have is a 404. A rule's period is added once, and a second add
  of it is a 409 in both runtimes. Local-first's upcoming list is the Worker's.
- Another profile's tag, category or account is a 400 at the field it names.
- A new tag and a new recurring rule answer 201 in both runtimes, as housing does.
- Deleting a housing expense, holding, tag or recurring rule another tab already deleted says so
  and reloads the list.
- MCP's upsert_tag_rule finds and creates tags by the tag rules.
- The contract suite settles 12 pins (31 to 19).

Slice 5 of 6 in docs/plans/2026-10-07-form-errors.md.
2026-10-10 09:19:28 +02:00

114 lines
4.5 KiB
TypeScript

/**
* The Recurring section's dialog on Transactions, in both storage modes: a recurring transaction
* without a description or an amount is marked at each field and nothing is sent, and a category
* deleted in another tab is marked at the category, in the runtime's words.
*
* The dialog said what the transaction rules or zod said, in a toast ("Transaction amount must be
* a positive number", "Validation failed"), with nothing marked, and the Worker saved a rule with
* no description. Now it checks with the rules both runtimes run (shared/recurringSchema.ts)
* before it sends anything, and marks the field.
*
* Every case runs signed in (the Worker) and local-first (the IndexedDB router). Pull requests
* run the `@smoke` one; main runs them all.
*/
import { expect, test } from '@playwright/test'
import {
caseStamp,
elsewhere,
errorToasts,
MODES,
REFUSAL_LOGGED,
sweepProfiles,
viaApp,
watchErrors,
watchWrites,
} from './form-errors-helpers'
import type { Locator, Page } from '@playwright/test'
interface Rule {
id: number
description: string
}
const header = (page: Page): Locator => page.getByTestId('transactions-header')
const dialog = (page: Page): Locator => page.getByTestId('recurring-modal')
const descriptionField = (page: Page): Locator => page.getByTestId('recurring-form-description')
const amountField = (page: Page): Locator => page.getByTestId('recurring-form-amount')
const categoryField = (page: Page): Locator => page.getByTestId('recurring-form-category')
const submit = (page: Page) => page.getByTestId('recurring-form-submit').click()
/** The Recurring section's Add button, beside its heading. */
const addButton = (page: Page): Locator =>
page
.getByRole('heading', { name: 'Recurring Transactions' })
.locator('xpath=..')
.getByRole('button', { name: 'Add', exact: true })
for (const mode of MODES) {
test.describe(`the recurring dialog, ${mode.name}`, () => {
/** In the name of everything a case makes, so the sweep can find it. */
let stamp = ''
test.beforeEach(() => {
test.setTimeout(120_000)
stamp = caseStamp()
})
test.afterEach(async ({ page }) => {
await sweepProfiles(page, mode, stamp)
})
test('a rule without a description or an amount is marked at each and nothing is sent, and a category deleted in another tab is marked at the category @smoke', async ({
page,
}) => {
const errors = watchErrors(page, REFUSAL_LOGGED)
const profileId = await mode.open(page, 'transactions', header, `zz-recurring-${stamp}`)
const writes = watchWrites(page, /^\/api\/recurring/)
const name = `zz-recur-${stamp}`
const category = `zz-recur-cat-${stamp}`
await addButton(page).click()
await expect(dialog(page)).toBeVisible()
await submit(page)
await expect(descriptionField(page)).toHaveAttribute('aria-invalid', 'true')
await expect(descriptionField(page)).toHaveAccessibleDescription(
'Describe the payment, like Rent or Salary.'
)
await expect(amountField(page)).toHaveAccessibleDescription('Enter the amount.')
await expect(descriptionField(page)).toBeFocused()
expect(writes).toEqual([])
await expect(errorToasts(page)).toHaveCount(0)
// A category added through the app reaches the dialog's list; deleted in another tab, it
// does not leave it.
const { id } = await viaApp<{ id: number }>(page, 'POST', '/api/categories', {
name: category,
type: 'expense',
color: '#0ea5e9',
icon: 'tag',
})
await expect(categoryField(page).locator('option', { hasText: category })).toHaveCount(1, {
timeout: 15_000,
})
await descriptionField(page).fill(name)
await amountField(page).fill('25,50')
await categoryField(page).selectOption({ label: category })
await elsewhere(page, mode, 'DELETE', `/api/categories/${String(id)}`, profileId)
await submit(page)
await expect(categoryField(page)).toHaveAttribute('aria-invalid', 'true')
await expect(categoryField(page)).toHaveAccessibleDescription(
'Choose a category from the list, or leave it blank.'
)
await expect(categoryField(page)).toBeFocused()
await expect(descriptionField(page)).not.toHaveAttribute('aria-invalid', 'true')
await expect(dialog(page)).toBeVisible()
await expect(errorToasts(page)).toHaveCount(0)
const rules = await viaApp<Rule[]>(page, 'GET', '/api/recurring')
expect(rules.filter((rule) => rule.description === name)).toEqual([])
expect(errors).toEqual([])
})
})
}