Repository navigation
fix(widget-plugin-test-utils): produce new value objects on change - #2583
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
r0b1n
force-pushed
the
r0b1n/tests-utils-check
branch
from
November 26, 2026 10:28
95a3657 to
881445f
Compare
This comment has been minimized.
This comment has been minimized.
leonardomendix
previously approved these changes
Nov 26, 2026
r0b1n
force-pushed
the
r0b1n/tests-utils-check
branch
from
November 30, 2026 12:22
881445f to
ebf2b77
Compare
This comment has been minimized.
This comment has been minimized.
r0b1n
force-pushed
the
r0b1n/tests-utils-check
branch
from
December 2, 2026 16:32
ebf2b77 to
bf22b5d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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
force-pushed
the
r0b1n/tests-utils-check
branch
from
December 4, 2026 14:39
289a2f9 to
cadc984
Compare
… the next attribute value
r0b1n
force-pushed
the
r0b1n/tests-utils-check
branch
from
December 4, 2026 14:40
cadc984 to
51f1b5f
Compare
This comment has been minimized.
This comment has been minimized.
Contributor
AI Code Review
What was reviewed
Skipped (out of scope): CI: pending: Check SHA in GH Actions, sigridci · unrelated failures: security/snyk (external scanner; no widget code changed) Positives
|
gjulivan
approved these changes
Dec 4, 2026
iobuhov
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,ReferenceValueBuilderandReferenceSetValueBuilderwrote the new value into the object already handed to the widget onsetValue, and the selection builders did the same onsetSelection. 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.setValue, from the UI or called directlysetValueand 1 s latersetValuefrom the UI, called directly, or by another widget bound to the same reference setsetValue([])when it is already[]setSelectionfrom the UI or called directlysetLimit,setFilter,reload()itemsarraycanExecute/isExecutingchangesOut of 3,806 probe lines, none shows an old object changing after the client passed it on. The
mendixtypings say the same aboutsetSelection: "returns nothing, but will cause the widget to receive new props."What changed
build()returns a new object every time.setValue/setSelectionarejest.fns that record the call and update only the builder. The object already handed out never changes, and the nextbuild()is the object the client would pass on the next render.expect(attr.setValue).toHaveBeenCalledWith(...)still works on any of them.Builders changed:
EditableValueBuilder,ReferenceValueBuilder,ReferenceSetValueBuilder,SelectionSingleValueBuilder,SelectionMultiValueBuilder. Already correct and unchanged:ListValueBuilder(copies onbuild(), setters are plainjest.fn()),ListReference(Set)ValueBuilder,actionValue,dynamic,listAttribute,listExpression,listWidget.New
__tests__/builders.test.tspins this. It fails if a setter changes a built object, and also if the nextbuild()misses the new value; I checked both by putting each break back temporarily. One test in__tests__/functions.test.tsasserted the old behaviour (setValuethen read.valueon the same object) and now asserts the new one.Specs touched, all because they relied on the old in-place changes:
selection/__tests__/helpers.spec.ts: pushesbuilder.build()throughMultiSelectionHelper.updatePropsbefore reading what the grid shows. No assertion changed.GridPersonalizationStore.spec.ts:storedJsonreads the value passed tosetValueinstead of.valueon the attribute the grid already holds.AttributePersonalizationStorage.spec.ts(2 tests): after a write, the storage gets the next attribute object throughupdatePropsbefore its settings are read back. The "latest props" test now also asserts the read from the new props before writing.setValue, so the new value only showed because the builder changed that object in place. The wrapper now takes the builder and rendersbuilder.build()aftersetValue, as the client does, and the tests assert on the builder'ssetValuemock. RangeSlider reads the bounds from the builders. RichText reads the value passed tosetValueinstead of.valueon the attribute it already holds.Switch.spec.tsx(2 tests): click, assert the exact value passed tosetValue, re-render with the next object, click again. Before, the second click only toggled because the first one had changed the shared object.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 becametoHaveBeenLastCalledWith(<exact value>). Select All now asserts the exact four items instead of a length. The chip-focussetupno longer needs its "updates its value in place" workaround. A baretoHaveBeenCalled()right before a strictertoHaveBeenLastCalledWith(...)was dropped.StaticSelection"removes selected item": the oldexpect(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 eachupdateProps. It also adds the re-render the client performs after the selector's ownsetSelection(A)(confirmed on the real client, see Scope), and asserts the selection the client would end up with.Docs.
docs/requirements/backend-structure.mdgets a short, generic section, "Dynamic values are immutable snapshots": every change to a dynamic value (its data, its status such asloading→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.mdgets 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:
DatabaseSingleSelectionSelectorreads the previous render's selection, but users can't hit it today.updatePropschecksthis.selectionbefore reassigning it from the new props. That only matters if one render brings both the selector's ownsetSelection(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.date-time-picker-web'stestscript calls a removed pluggable-widgets-tools command and runs no tests at all, though it exits 0. Unrelated.Tradeoffs
setValueupdates the builder rather than being a plainjest.fn(). Specs that keep the builder can then get the next object withbuild(), with no second source of truth.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 testinside 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):After rebasing on main (
8761b1c7a), all 55 dependent packages pass, exceptaccessibility-helper-webandselection-helper-web, which have notestscript.pnpm run test:browserpasses in all 53 packages that have component tests. Lint is clean on every changed file, andtsc --noEmitpasses in the touched packages.