test: fix FailedTestCaseSampleData tests with mock Table component#28028
Conversation
Code Review ✅ ApprovedEnhanced FailedTestCaseSampleData tests by introducing mock implementations for UI components and streamlining attribute access. No issues found. OptionsDisplay: compact → Showing less information. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
There was a problem hiding this comment.
Pull request overview
This PR updates the UI unit test for FailedTestCaseSampleData to better isolate the component under test by mocking the @openmetadata/ui-core-components Table implementation, while keeping the existing routing assertion around observabilityRouterClassBase.getTestCaseDetailPagePath().
Changes:
- Added a lightweight mock implementation of
Table/Typographyfrom@openmetadata/ui-core-componentsto make the test less coupled to the real table internals. - Simplified the test render flow by removing an explicit
act()wrapper and relying on RTL async queries (findByTestId) to await state updates. - Switched the Link mock assertion from
getAttribute('data-to')todataset.to.
|
🟡 Playwright Results — all passed (14 flaky)✅ 4071 passed · ❌ 0 failed · 🟡 14 flaky · ⏭️ 86 skipped
🟡 14 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |



RCA:
FailedTestCaseSampleData.test.tsxfailing onmainfixs: #28030
Summary
After PR #27956 and PR #27985 both landed on
main,FailedTestCaseSampleData.test.tsxstarted crashing with:Both PRs were green on their own branches. The breakage only surfaced once they were combined on
main.Root Cause
Dual React instances triggered by an unmocked dependency.
@openmetadata/ui-core-componentsships a prebuilt CJS bundle resolved against its own nestednode_modules/react— separate from the one Jest is running with. When a component pulls a real export (Table,Typography, etc.) into a Jest test, two React copies are live in the same process. The dispatcher inside the package's React copy isnull, so the firstuseContextcall inside the bundle throws.This was missed because two PRs touched complementary parts of the same file and
pull_request_targetCI runs against the PR head, not against a hypothetical merge withmain.Timeline
Tableimport fromantd→@openmetadata/ui-core-componentsinFailedTestCaseSampleData.component.tsxFailedTestCaseSampleData.test.tsx. On this PR's branch, the component still importedTablefromantdrc-table/lib/Table.js,antd/lib/spin)mainDirect evidence from PR #27956's CI run (
25601970266):Git auto-merged the two changes without conflict (they touched different parts of the file), so no human noticed the interaction at merge time.
Fix
Mock
@openmetadata/ui-core-componentsin the test (matches the pattern already used inIncidentManager.test.tsxand 30+ other tests in the repo). Provides minimal stubs forTable,Table.Header/Head/Body/Row/Cell, andTypography— keeps the package's real bundled code out of the render tree, eliminating the dual-React issue.Verification
yarn test --testPathPattern=FailedTestCaseSampleData→ PASS (1/1)eslinton the test file → cleantsc --noEmit→ cleanprettier+organize-imports-cli→ no diffProcess Gap
yarn-coverageCI runs againstpull_request_targethead, not against a trial merge withmain. Two PRs that individually pass can still produce a brokenmainif they touch complementary parts of the same file. Worth considering: run UI tests against the merge ref (refs/pull/N/merge) instead of the head SHA so this class of interaction surfaces before merge.