Skip to content
Widget Library

Conformance Scenarios

The JSON scenarios that define correct widget behaviour on every platform.

This page describes the scenario format. A scenario is the definition of a behaviour: if it is not in a scenario, it is not part of the contract.


The web widget is TypeScript; the mobile renderers will be Swift and Kotlin. They cannot share code, but they can read the same files. A scenario says, in data, “with this config, after these steps, the runtime must have received exactly these calls”. Each platform has a small runner that applies it.

Scenarios live in scenarios/, example configs in fixtures/. Both are published in the npm package.


{
"name": "a product tap sends click with the product id",
"config": "fixtures/valid/reco-basic.json",
"steps": [
{ "do": "render" },
{ "do": "tap", "target": "product:p2" }
],
"expect": {
"rendered": true,
"calls": [
{ "interaction": { "type": "impression", "instanceId": "scn_1", "interactionId": "act_1" } },
{ "interaction": { "type": "click", "instanceId": "scn_1", "interactionId": "p2" } }
]
}
}

Field Meaning
name One sentence that states the behaviour.
platforms The platforms that run it. All when absent.
requires What the runner must have. "layout": real sizes and scrolling. "styles": the computed CSS cascade. A runner without them, such as the happy-dom one, skips the scenario.
initTheme The theme set when the library is initialised, before the widget renders (web: setWidgetTheme).
now The moment the scenario starts at, ISO-8601 with a time zone. The runner sets its clock to it, and the clock stands still except in a wait step. Needed by anything that reads the time, such as a countdown.
config The fixture to start from, as a path from the repository root.
override Values deep-merged over the fixture. Arrays and primitives replace.
context Parts of the runtime context to set (device, language, …).
capabilities Runtime capabilities to set.
runtime What the runtime answers: basketResult, favoriteResult; added when absent. hold: true keeps the answers pending until an answer step.
steps What happens, in order.
expect What must be true afterwards.

Step Meaning
{ "do": "render" } Mount the widget with the config.
{ "do": "show" } The widget scrolls into view.
{ "do": "resize", "width": 1200 } The widget’s container becomes this wide, in pixels.
{ "do": "tap", "target": "..." } The visitor taps a target.
{ "do": "answer" } The runtime gives every answer it was holding.
{ "do": "remove" } The page removes the widget.
{ "do": "wait", "ms": 2000 } Time passes: this many milliseconds, with every timer that is due.
{ "do": "observe-view" } Data only delivery: the site hands the element it drew to observeView(). A later show makes it visible.
{ "do": "report-click", "productId": "p2" } Data only delivery: the site calls reportClick().
{ "do": "add-to-basket", "productId": "p2", "quantity": 2 } Data only delivery: the site calls addToBasket(). quantity is optional.

Tap targets have stable names: product:<id>, basket:<id>, favorite:<id>, arrow-prev, arrow-next, page:<n>. Texts that are not tapped have names too, for example countdown and slot-text. On the web they are data-target attributes inside the widget.


Field Meaning
rendered Whether the widget is on the page.
calls Every runtime call, in order. Nothing more and nothing less.
title The text of the title.
texts The text of named targets.
columns The number of cards visible in a row.
enabled Targets that must exist and accept a tap.
disabled Targets that must exist and refuse a tap.
hidden Targets that must exist and be hidden.
current Targets that must be marked as the current one, such as a pagination dot.
layout The layout the product list must be in: slider, grid, list or compact.
card The kind of card every product must be drawn as: standard or compact.
labels The accessible label per target, for controls that show an icon.
selected, unselected Toggle targets, such as a favourite, that must show as selected or not.
absent Targets that must not exist.
theme Theme tokens that must be applied, with their values.
themeAbsent Theme tokens that must not be applied.
effectiveTheme Theme tokens with the value the widget ends up with after the layers: campaign theme over initialisation theme. Needs requires: ["styles"].
effectiveThemeAbsent Theme tokens that must have no value after the layers.
nameLines The line limit applied to product names.
basketResults What each add-to-basket step resolved with, in order.

A data delivery is recorded in calls as { "deliverData": { "instanceId", "title", "productIds" } }.

calls is strict on purpose. A widget that sends one extra event fails the scenario, because an extra event is a measurement error.


  1. Add a JSON file under scenarios/recommendation/. The number at the start of the name follows the scenario list in the contract.
  2. Run pnpm test:dom and see it fail.
  3. Implement the behaviour.
  4. Run pnpm check; the scenario now runs in happy-dom and in Chrome.