-
Notifications
You must be signed in to change notification settings - Fork 16.6k
fix(world-map): reset hover highlight on mouse out #37580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,307 @@ | ||||||||
| /** | ||||||||
| * Licensed to the Apache Software Foundation (ASF) under one | ||||||||
| * or more contributor license agreements. See the NOTICE file | ||||||||
| * distributed with this work for additional information | ||||||||
| * regarding copyright ownership. The ASF licenses this file | ||||||||
| * to you under the Apache License, Version 2.0 (the | ||||||||
| * "License"); you may not use this file except in compliance | ||||||||
| * with the License. You may obtain a copy of the License at | ||||||||
| * | ||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||
| * | ||||||||
| * Unless required by applicable law or agreed to in writing, | ||||||||
| * software distributed under the License is distributed on an | ||||||||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||
| * KIND, either express or implied. See the License for the | ||||||||
| * specific language governing permissions and limitations | ||||||||
| * under the License. | ||||||||
| */ | ||||||||
|
|
||||||||
| import d3 from 'd3'; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Importing d3 as a default export may fail at runtime if the d3 package doesn't provide a default export in the test environment; this will cause Severity Level: Major
|
||||||||
| import d3 from 'd3'; | |
| import * as d3 from 'd3'; |
Steps of Reproduction ✅
1. Run the WorldMap test file:
superset-frontend/plugins/legacy-plugin-chart-world-map/test/WorldMap.test.ts (for example
via `yarn test WorldMap.test.ts`).
2. The test "stores original fill color on mouseover" (defined starting at line 107 in
that file) reaches the code that calls jest.spyOn(d3, 'select') at line 136:
`jest.spyOn(d3, 'select').mockReturnValue(mockD3Selection as any);`.
3. If the environment's module resolution does not provide a default export for d3, the
default import `import d3 from 'd3';` at line 20 results in `d3` being undefined or
lacking `select`. When the test executes `jest.spyOn(d3, 'select')` at line 136, Jest will
throw because `d3.select` is undefined (TypeError from jest.spyOn).
4. The failure is concrete and reproducible: running that test file in an environment
without a default d3 export will produce an immediate test error at the spy site. Using
`import * as d3 from 'd3';` guarantees `d3.select` is present in CommonJS/ESM interop
environments, avoiding the TypeError.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/plugins/legacy-plugin-chart-world-map/test/WorldMap.test.ts
**Line:** 20:20
**Comment:**
*Possible Bug: Importing d3 as a default export may fail at runtime if the d3 package doesn't provide a default export in the test environment; this will cause `jest.spyOn(d3, 'select')` to throw because `d3.select` is undefined. Use a namespace import so `d3.select` is reliably available.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The test suite calls jest.clearAllMocks() in beforeEach, which clears mock call history but does not reset mock implementations created in earlier tests (for example, mockImplementation on mockSvg.on). This can cause test cross-contamination and flakiness; replace with jest.resetAllMocks() (and also clear calls) to restore mocks to their original implementations before each test. [possible bug]
Severity Level: Major ⚠️
- ❌ WorldMap tests may intermittently assert incorrect handler behavior.
- ⚠️ CI builds can show flaky failures for this test file.| jest.clearAllMocks(); | |
| // Reset mock implementations and clear call history to avoid leakage between tests | |
| jest.resetAllMocks(); |
Steps of Reproduction ✅
1. Observe tests that set mock implementations on the shared mockSvg object, e.g. the
"stores original fill color on mouseover" test sets `mockSvg.on.mockImplementation(...)`
when capturing the mouseover handler at lines ~139-144 in the test file.
2. The next test in the file runs its setup (the beforeEach starting at line 83), which
currently calls only `jest.clearAllMocks()` at line 84. `clearAllMocks()` clears call
history but does NOT revert mock implementations created by `mockImplementation`.
3. Because the previous test's `mockImplementation` persists, the subsequent test can see
the prior custom behavior of `mockSvg.on`, causing incorrect handler capture or unexpected
calls (for example, mouseover/mouseout handlers bound in one test being active in
another).
4. Reproduce by running the full WorldMap.test.ts file multiple times or changing test
order: flakiness appears as tests intermittently fail expectations about handler
registration or attr/style calls. Replacing `jest.clearAllMocks()` with
`jest.resetAllMocks()` (or calling both reset then clear) will restore mocks to their
original implementations and remove the cross-test leakage.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/plugins/legacy-plugin-chart-world-map/test/WorldMap.test.ts
**Line:** 84:84
**Comment:**
*Possible Bug: The test suite calls `jest.clearAllMocks()` in `beforeEach`, which clears mock call history but does not reset mock implementations created in earlier tests (for example, `mockImplementation` on `mockSvg.on`). This can cause test cross-contamination and flakiness; replace with `jest.resetAllMocks()` (and also clear calls) to restore mocks to their original implementations before each test.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Spies created with jest.spyOn are not restored anywhere in the test file; leaving spies in place can interfere with other tests. Restore spies after each test by calling jest.restoreAllMocks() in afterEach. [possible bug]
Severity Level: Major ⚠️
- ❌ WorldMap tests leak spies causing cross-test interference.
- ⚠️ Other tests may be affected by lingering spies.| }); | |
| // Restore any spies (e.g. jest.spyOn) to avoid leaking altered implementations across tests | |
| jest.restoreAllMocks(); |
Steps of Reproduction ✅
1. Multiple tests in this file call `jest.spyOn(d3, 'select')` to replace `d3.select` with
controlled return values (see calls at lines 136, 185, 235, 275 where `jest.spyOn(d3,
'select')` is invoked).
2. The current afterEach (lines 89-91) only removes the test DOM container and does not
call `jest.restoreAllMocks()`, so spies applied by `jest.spyOn(...)` remain in effect for
subsequent tests.
3. Run the test suite: a test that expects the real behavior of `d3.select` (or a
different spy) can be executed after another test that established a spy, leading to tests
observing the wrong implementation or unexpected behavior (for example, a stale spy
returning a mocked selection).
4. Add `jest.restoreAllMocks()` in afterEach to restore original implementations and avoid
cross-test interference; this is a concrete fix observed to prevent spy leakage in
Jest-based tests.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/plugins/legacy-plugin-chart-world-map/test/WorldMap.test.ts
**Line:** 91:91
**Comment:**
*Possible Bug: Spies created with `jest.spyOn` are not restored anywhere in the test file; leaving spies in place can interfere with other tests. Restore spies after each test by calling `jest.restoreAllMocks()` in `afterEach`.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "extends": "../../../tsconfig.options.json", | ||
| "include": ["**/*"], | ||
| "compilerOptions": { | ||
| "esModuleInterop": true, | ||
| "types": ["jest", "node"] | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Overwrites the stored original fill with the highlighted color: the handler always sets
data-original-fillon every mouseover, which can capture the highlight color (if Datamaps already applied it) and then restore to that wrong color on mouseout. Only store the original fill if it hasn't been stored yet. [logic error]Severity Level: Major⚠️
Steps of Reproduction ✅
Prompt for AI Agent 🤖