Skip to content

test(fit): assert mxGraphView calls in the fit integration tests#3527

Merged
tbouffard merged 2 commits into
masterfrom
test/improve_fit_integration_tests
May 27, 2026
Merged

test(fit): assert mxGraphView calls in the fit integration tests#3527
tbouffard merged 2 commits into
masterfrom
test/improve_fit_integration_tests

Conversation

@tbouffard
Copy link
Copy Markdown
Member

Replace the smoke tests (which only checked that no error was thrown) with assertions on the scaleAndTranslate calls and the resulting scale, for every FitType and for the margin option. Mock getGraphBounds and force the container dimensions to make the scale and translation deterministic and decoupled from the parse/render pipeline.

This prepares the migration to maxGraph (the mxGraph successor, with a close API) by mirroring its FitPlugin tests: configure the container dimensions, then verify the underlying mxGraphView method calls and their arguments. Pinning the exact scale and translation values lets us detect any numerical discrepancy introduced by the migration. The e2e visual tests also catch such discrepancies, on the whole computation against the real rendered bounds; these integration tests complement them with fast, precise, per-branch checks.

Notes

These test improvements prepare the maxGraph migration (#3238).

Replace the smoke tests (which only checked that no error was thrown) with assertions on the
scaleAndTranslate calls and the resulting scale, for every FitType and for the margin option. Mock
getGraphBounds and force the container dimensions to make the scale and translation deterministic and
decoupled from the parse/render pipeline.

This prepares the migration to maxGraph (the mxGraph successor, with a close API) by mirroring its
FitPlugin tests: configure the container dimensions, then verify the underlying mxGraphView method calls
and their arguments. Pinning the exact scale and translation values lets us detect any numerical
discrepancy introduced by the migration. The e2e visual tests also catch such discrepancies, on the whole
computation against the real rendered bounds; these integration tests complement them with fast, precise,
per-branch checks.
// even when the scale is capped to the maximum value (8). A negative margin is treated as 0 (see the 'Center' tests).
it.each`
type | dimensions | bounds | margin | expectedScale | expectedTranslateX | expectedTranslateY
${FitType.HorizontalVertical} | ${{ offsetWidth: 480, offsetHeight: 820 }} | ${{ x: 70, y: -60, width: 100, height: 100 }} | ${undefined} | ${4.78} | ${-70} | ${60}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but this is a false positive for the test data, so I'll keep the table as is.

it.each here uses a tagged template literal. Unlike a plain template string, a tagged template does not coerce its interpolated expressions: Jest's each receives the raw values and passes them to the test unchanged. The margin cell is therefore the actual undefined, not the string "undefined".

Proof from the suite itself: margin reaches ensurePositiveValue, i.e. Math.max(input ?? 0, 0). With a real undefined this returns 0, which is exactly why the ${undefined} rows assert the no-margin results (4.78 / 5.72 / 8 at translate -70, 60). If the value were the string "undefined", the expression would be Math.max(NaN, 0)NaN, the computed scale would be NaN, and those assertions would fail. They pass, so the value is genuinely undefined.

The only undefined → string conversion happens in the generated test name ($margin → "undefined"), which is intentional: it documents the no-margin case and distinguishes those rows from the margin: 30 / margin: 100 ones. The suggestion on line 142 correctly identifies the title as the sole conversion path; the suggestions on lines 139-141 assume the data itself is converted, which it isn't.

On the proposed workarounds: each trades readability for silencing a rule that misfires on tagged-template semantics. ${null} would also change the documented input (and the Zoom table already interpolates ${null} / ${undefined} on purpose). So I'll resolve this as a false positive rather than change the code.

Comment thread test/integration/diagram.navigation.test.ts Dismissed
Comment thread test/integration/diagram.navigation.test.ts Dismissed
Comment thread test/integration/diagram.navigation.test.ts Dismissed
@tbouffard tbouffard added chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...) mxgraph integration Something involving mxGraph (be aware of EOL) labels May 27, 2026
@sonarqubecloud
Copy link
Copy Markdown

@tbouffard tbouffard merged commit d9faaaa into master May 27, 2026
9 checks passed
@tbouffard tbouffard deleted the test/improve_fit_integration_tests branch May 27, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...) mxgraph integration Something involving mxGraph (be aware of EOL)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant