Skip to content

fix(widget-plugin-test-utils): produce new value objects on change - #2583

Merged
r0b1n merged 5 commits into
mainfrom
r0b1n/tests-utils-check
Dec 4, 2026
Merged

r0b1n merged 5 commits into
mainfrom
r0b1n/tests-utils-check

Conversation

@r0b1n

@r0b1n r0b1n commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Pull request type

Test related change (New E2E test, test automation, etc.)


Why

combobox-web is moving to one MobX computed per Mendix prop value. That only works if the Mendix client passes a new object when a value changes and the same object when it doesn't. Our test builders didn't model that: EditableValueBuilder, ReferenceValueBuilder and ReferenceSetValueBuilder wrote the new value into the object already handed to the widget on setValue, and the selection builders did the same on setSelection. A spec could then read the change back through the old object and pass, even if the widget never handled a new prop.

Before changing anything I checked the real client: I instrumented Combobox.tsx (temporary, not committed) and drove combobox-web's test project on Mendix 11.15.0 with the modern client.

Value type Event Next render gets Old object changed?
EditableValue (boolean, enum, string) setValue, from the UI or called directly new object no: still the old value right after setValue and 1 s later
ReferenceValue / ReferenceSetValue setValue from the UI, called directly, or by another widget bound to the same reference set new object no
ReferenceSetValue setValue([]) when it is already [] new object (the inner array keeps its identity) no
SelectionSingleValue setSelection from the UI or called directly new object no
ListValue setLimit, setFilter, reload() new object, new items array no
ObjectItem refetch (setLimit, filter, reload) new object for the same id –
ActionValue canExecute / isExecuting changes new object no
any prop a re-render where that prop didn't change same object no

Out of 3,806 probe lines, none shows an old object changing after the client passed it on. The mendix typings say the same about setSelection: "returns nothing, but will cause the widget to receive new props."

What changed

  • build() returns a new object every time.
  • setValue / setSelection are jest.fns that record the call and update only the builder. The object already handed out never changes, and the next build() is the object the client would pass on the next render.
  • The objects one builder produces share their mocks, so expect(attr.setValue).toHaveBeenCalledWith(...) still works on any of them.

Builders changed: EditableValueBuilder, ReferenceValueBuilder, ReferenceSetValueBuilder, SelectionSingleValueBuilder, SelectionMultiValueBuilder. Already correct and unchanged: ListValueBuilder (copies on build(), setters are plain jest.fn()), ListReference(Set)ValueBuilder, actionValue, dynamic, listAttribute, listExpression, listWidget.

New __tests__/builders.test.ts pins this. It fails if a setter changes a built object, and also if the next build() misses the new value; I checked both by putting each break back temporarily. One test in __tests__/functions.test.ts asserted the old behaviour (setValue then read .value on the same object) and now asserts the new one.

Specs touched, all because they relied on the old in-place changes:

  • widget-plugin-grid selection/__tests__/helpers.spec.ts: pushes builder.build() through MultiSelectionHelper.updateProps before reading what the grid shows. No assertion changed.
  • datagrid-web personalization specs, added to main after this PR was opened. GridPersonalizationStore.spec.ts: storedJson reads the value passed to setValue instead of .value on the attribute the grid already holds. AttributePersonalizationStorage.spec.ts (2 tests): after a write, the storage gets the next attribute object through updateProps before its settings are read back. The "latest props" test now also asserts the read from the new props before writing.
  • Component tests (Vitest browser mode, added to main after this PR was opened) in switch-web, rating-web, slider-web, range-slider-web, checkbox-radio-selection-web and rich-text-web. The first five wrapped the widget in a "Live" component that re-rendered the same props object after setValue, so the new value only showed because the builder changed that object in place. The wrapper now takes the builder and renders builder.build() after setValue, as the client does, and the tests assert on the builder's setValue mock. RangeSlider reads the bounds from the builders. RichText reads the value passed to setValue instead of .value on the attribute it already holds.
  • switch-web Switch.spec.tsx (2 tests): click, assert the exact value passed to setValue, re-render with the next object, click again. Before, the second click only toggled because the first one had changed the shared object.
  • combobox-web
    • SingleSelection.spec.tsx, MultiSelection.spec.tsx, StaticSelection.spec.tsx: re-render with the next object instead of the same one. expect(attr.value) read-backs became toHaveBeenLastCalledWith(<exact value>). Select All now asserts the exact four items instead of a length. The chip-focus setup no longer needs its "updates its value in place" workaround. A bare toHaveBeenCalled() right before a stricter toHaveBeenLastCalledWith(...) was dropped.
    • StaticSelection "removes selected item": the old expect(value).toEqual("value1") after re-selecting the current option proved nothing, because the value was already "value1". It now asserts that re-selecting writes nothing.
    • DatabaseSingleSelectionSelector.spec.ts: hands a fresh selection object to each updateProps. It also adds the re-render the client performs after the selector's own setSelection(A) (confirmed on the real client, see Scope), and asserts the selection the client would end up with.

Docs. docs/requirements/backend-structure.md gets a short, generic section, "Dynamic values are immutable snapshots": every change to a dynamic value (its data, its status such as loading → available, or its metadata) arrives as a new object, an unchanged value keeps its object, and widget code and test mocks have to work with that. The existing static-props paragraph moves out of the property-types list into a sibling section, "Static props never change", and the list keeps a one-line pointer. AGENTS.md gets one line in Testing on mocking values the same way.

Scope

widget-plugin-test-utils, unit specs in widget-plugin-grid, switch-web, combobox-web and datagrid-web, component specs in six widgets, and the two docs above. No widget source changed. No CHANGELOG, because the only package changed outside specs is a shared package.

Left out on purpose:

  • SelectionMultiValue isn't observed: the test project only has a Single selection. It gets the same model as everything that was observed.
  • DatabaseSingleSelectionSelector reads the previous render's selection, but users can't hit it today. updateProps checks this.selection before reassigning it from the new props. That only matters if one render brings both the selector's own setSelection(A) and an outside clear of the attribute. I tried to make that happen on the test project (Mendix 11.15, modern client), clearing the attribute after a user pick (0–1500 ms later and in the same microtask) and during the widget's auto-select on page load. The client never produced that render. It either rendered the selector's selection on its own first (synchronously after a user pick), or it batched both changes and the selection it delivered was already empty. Every run ended with both the attribute and the selection empty. Moving the assignment up would still be a worthwhile refactor, but no fix ships here.
  • Pre-existing: date-time-picker-web's test script calls a removed pluggable-widgets-tools command and runs no tests at all, though it exits 0. Unrelated.

Tradeoffs

  • setValue updates the builder rather than being a plain jest.fn(). Specs that keep the builder can then get the next object with build(), with no second source of truth.
  • The objects share their mocks. Identity of the functions themselves wasn't probed, and sharing keeps call assertions working across re-renders.

Blast radius

The builders are used by the unit tests of 55 packages (on main as of the latest rebase) and nothing ships them. Unit tests ran in every package that depends on @mendix/widget-plugin-test-utils. Only the four packages above had specs that relied on the old behaviour.

Verification

pnpm run test inside each dependent package, before and after (first run on 40 packages; datagrid-web's personalization specs were added to main later and found when rebasing):

before after the builder change only after the spec fixes
widget-plugin-test-utils 52 passed, 2 todo 1 failed 59 passed, 2 todo (+7 new)
combobox-web 235 passed 19 failed 235 passed
widget-plugin-grid 150 passed 14 failed 150 passed
switch-web 24 passed 2 failed 24 passed
datagrid-web – 10 failed (personalization specs from main) 330 passed
the other packages all passing unchanged unchanged

After rebasing on main (8761b1c7a), all 55 dependent packages pass, except accessibility-helper-web and selection-helper-web, which have no test script. pnpm run test:browser passes in all 53 packages that have component tests. Lint is clean on every changed file, and tsc --noEmit passes in the touched packages.

@r0b1n
r0b1n marked this pull request as ready for review November 26, 2026 10:13
@r0b1n
r0b1n requested a review from a team as a code owner November 26, 2026 10:13
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@r0b1n
r0b1n force-pushed the r0b1n/tests-utils-check branch from 95a3657 to 881445f Compare November 26, 2026 10:28
@github-actions

This comment has been minimized.

leonardomendix
leonardomendix previously approved these changes Nov 26, 2026
@r0b1n
r0b1n force-pushed the r0b1n/tests-utils-check branch from 881445f to ebf2b77 Compare November 30, 2026 12:22
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

r0b1n added 3 commits December 4, 2026 15:39
The Mendix client never changes a value object it has passed to a widget.
setValue and setSelection leave it untouched and the widget receives a new
object on the next render (verified in combobox-web's test project on
Mendix 11.15.0, modern client).

EditableValueBuilder, ReferenceValueBuilder and ReferenceSetValueBuilder
wrote the new value into the built object, and the selection builders did
the same on setSelection. Specs that read the change back through the old
object passed even when the widget never handled a new prop.

build() now returns a new object every time, and setters record the call
and update only the builder, so the next build() is the object the client
would pass. Specs that relied on the old behaviour now re-render with the
next object and assert the value passed to setValue.
@r0b1n
r0b1n force-pushed the r0b1n/tests-utils-check branch from 289a2f9 to cadc984 Compare December 4, 2026 14:39
@r0b1n
r0b1n force-pushed the r0b1n/tests-utils-check branch from cadc984 to 51f1b5f Compare December 4, 2026 14:40
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

AI Code Review

✅ Approved — no issues found


What was reviewed

Package Change
docs, AGENTS.md New "Dynamic values are immutable snapshots" and "Static props never change" sections, plus one line in Testing
widget-plugin-test-utils Five builders (Editable, ReferenceValue, ReferenceSet, SelectionSingle, SelectionMulti) now return a new object on every build(). setValue and setSelection update only the builder. New tests in builders.test.ts, and one test in functions.test.ts updated.
widget-plugin-grid helpers.spec.ts re-renders with builder.build() before reading state
combobox-web Four unit specs re-render with the next object and assert the exact values passed to setValue
datagrid-web Two personalization specs updated for new-object semantics
switch-web Unit and component tests updated
rating-web, slider-web, range-slider-web, checkbox-radio-selection-web, rich-text-web Component tests now render builder.build() after setValue

Skipped (out of scope): dist/, pnpm-lock.yaml

CI: pending: Check SHA in GH Actions, sigridci · unrelated failures: security/snyk (external scanner; no widget code changed)


Positives

  • The builder change is tested in both directions. A setter must not mutate a built object, and the next build() must carry the new value. The PR description says each break was put back temporarily to check that the tests fail.
  • The affected specs now assert the exact values passed to setValue. They no longer read .value back from an old object, and a re-select test that proved nothing now checks that nothing is written.
  • The PR description has a Blast radius section and a table of how the real Mendix client behaves. Both back the builder change with evidence.

@r0b1n
r0b1n merged commit a2485c4 into main Dec 4, 2026
19 of 20 checks passed
@r0b1n
r0b1n deleted the r0b1n/tests-utils-check branch December 4, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants