Files
editor/AGENTS.md
T
SHAIK KHADEER BASHA 6876ffa08e Add missing translations and a test that fails when one is missing (#2407)
Follow-up to the review on #2403.

New unit test `src/locales/translations.test.ts` runs the i18next-cli
extractor (the code behind `npm run i18n:extract`) without writing
anything. It fails if any locale is missing a key used in the code, or
still has the `__STRING_NOT_TRANSLATED__` placeholder. It's part of `npm
run test-unit`, so the existing unit test job in CI runs it and no
workflow change is needed. On failure it lists each missing `locale:
key`.

On `main` the test fails with 8 keys missing in all 10 locales. They
came from #2395, #2397 and #2405. This PR adds translations for them:

- `{{label}} row {{row}} anchor` / `X offset` / `Y offset`
- `Generate feature IDs`, `Feature ID property`, `Feature ID properties
by source layer`, `Enter a JSON object mapping source layer names to
property names.`
- `Use current map view`

The translators listed in `src/locales/README.md` may want to check the
wording. I matched the terms each locale already uses (for example
"Source Layer", "Map view").

The AGENTS.md Translations section now mentions the test.

**Performance:** no runtime impact. It only adds JSON entries and a unit
test, which takes about 2 seconds.

## Launch Checklist

 - [x] Briefly describe the changes in this PR.
 - [x] Link to related issues: follow-up to #2403.
- [x] Include before/after visuals or gifs if this PR includes visual
changes. (No visual change in English. The other locales show the new
strings instead of the English fallback.)
- [x] Write tests for all new functionality: `translations` in
`src/locales/translations.test.ts`. It fails on `main` with the 8
missing keys.
 - [x] Add an entry to `CHANGELOG.md` under the `## main` section.

Tested locally: `npm run lint` clean, `npm run build` clean, `npx vitest
run` (60 passed), `npm run test-unit-ci` passed, and `npx i18next-cli
extract --ci --dry-run` reports no changes. Before adding the
translations, the new test failed with the 80 missing `locale: key`
entries.

Assisted-By: Claude Opus 5.5 (Claude Code). It helped write the test,
the translations and this description. I've reviewed and tested the
change and can answer questions about it.
2026-12-05 08:16:50 +02:00

161 lines
5.9 KiB
Markdown

Maputnik is a MapLibre style editor written using React and TypeScript.
To get started, install all npm packages:
```
npm install
```
Verify code correctness by running ESLint:
```
npm run lint
```
Or try fixing lint issues with:
```
npm run lint -- --fix
```
The project type checked and built with:
```
npm run build
```
Install the Playwright browser (first time only):
```
npx playwright install --with-deps chromium
```
Then run the end-to-end tests (Playwright starts the dev server automatically):
```
npm run test
```
Run the unit tests with Vitest:
```
npm run test-unit
```
## Accessibility
- Every input, select and button needs an accessible name. `InputString`, `InputNumber`, `InputSelect` and `InputButton` accept an `aria-label`.
- When a control repeats, as in the rows of an array or collection field, give each copy its own label that names the row and what it edits (for example `… row 2 X offset`), and pass it through `t()`. Controls that share one label can't be told apart with a screen reader.
## Translations
- Every new user-visible string goes through `t()` and needs a translation in each `src/locales/*/translation.json`, kept in alphabetical key order.
- `npm run i18n:extract` adds missing keys with the value `__STRING_NOT_TRANSLATED__`; replace each one with a real translation. `npx i18next-cli status` lists keys that are still missing, and `src/locales/translations.test.ts` fails in `npm run test-unit` until every locale has them.
## Pull Requests
- Pull requests should update `CHANGELOG.md` with a short description of the change.
## Testing
### Prefer end-to-end tests
Most of this codebase is React components, and they are only reachable from an
end-to-end test. E2E coverage is the primary signal.
Reach for a unit test only for pure logic that e2e cannot cheaply reach (parsers,
sorting, watchers, stores). Before writing one, check whether e2e already covers
the file — a unit test that duplicates existing e2e coverage adds test code and
almost no coverage:
```
npx nyc report --reporter=text --include="src/libs/style.ts"
```
Do **not** merge the Vitest (v8) and e2e (istanbul) coverage reports locally. They
produce conflicting statement maps for the same files and the combined percentage
is meaningless. Codecov merges the two uploads server-side; that is the number to
trust. Locally, read them separately:
- e2e: `npx playwright test` then `npx nyc report --reporter=text-summary` (reads `.nyc_output/`)
- unit: `npx vitest run --coverage` (writes `coverage/`)
### E2E layering
Three layers, and the boundaries matter:
- `e2e/playwright-helper.ts` — generic, app-agnostic browser actions. **The only
file allowed to import `@playwright/test`** (besides `e2e/utils/fixtures.ts`).
- `e2e/maputnik-driver.ts` — domain actions (layers, filters, functions, the
style). Knows nothing about `page` or Playwright.
- `e2e/modal-driver.ts` — actions scoped to a modal, exposed as `when.modal.*`.
Specs get a driver at describe scope and assert fluently:
```ts
describe("layer editor", () => {
const { given, get, when, then } = new MaputnikDriver();
...
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({ layers: [{ id, type: "fill" }] });
});
```
New UI interactions belong in a driver, not inline in a spec.
### Writing assertions
- `shouldDeepNestedInclude` is a recursive partial match (`toMatchObject`): nested
objects are matched as subsets, arrays and primitives must match exactly
(including array length).
- Assert against the whole style, not an extracted slice. Avoid
`get.styleFromLocalStorage().then(style => style.layers.find(...))` — it moves
test logic into the test. Compare the real object instead.
- `Query.then()` is lazy and returns a new `Query`, **not** a Promise. `await
get.styleFromLocalStorage()` hangs forever. Use `.get()` to await it directly,
or pass the Query to `then(...)`.
### One behaviour per test
If a test needs comments narrating "and now this…", it is several tests. Split it,
and hoist the shared setup into a nested `describe` + `beforeEach`.
### Test ids
Test ids use the `data-wd-key` attribute and are read via `get.elementByTestId`.
The `Input*` components already accept `data-wd-key` and render it on the real
`<input>`; the `Field*` wrappers forward it through their `{...props}` spread. So
passing `data-wd-key` to a `Field*` component is usually enough. Do **not** also
add it to `Block`/`Fieldset` — the id then matches two elements and locators fail
in strict mode.
Note `InputNumber` renders `<key>-text` and `<key>-range` when `allowRange` is set,
and `<key>` otherwise.
### Input commit semantics (common source of "the value didn't save")
- `InputString` only fires its `onChange` on **blur** or **Enter**. Typing alone
fires `onInput`. A driver that calls `fill()` must then call `blur()`, or the
value never reaches the style.
- `InputNumber` commits on every change; no blur needed.
- The autocomplete inputs (layer source, add-layer source) are controlled
downshift comboboxes. Keystroke typing is dropped/reordered — `{selectall}` then
typing `raster` yields `"exampleaster"`. Use `fill()`, which dispatches a single
input event, then pick from the filtered menu.
- CodeMirror auto-closes brackets and quotes, and types over its own closers, so
inserting a well-formed JSON fragment stays well-formed. To break JSON on
purpose, insert a bare word.
### Fixtures
Style fixtures live in `e2e/fixtures/`. A new one must be registered in two places
in `maputnik-driver.ts`: the list in `given.setupMockBackedResponses` and the
`styleFileByKey` map in `when.setStyle`.
### Verify a new test can fail
A test that passes for the wrong reason is worse than no test. After writing one,
mutate the expected value and confirm it fails. This has caught real mistakes
(e.g. a driver that never committed its input, so the assertion was matching a
value written by the *previous* step).