codeant-ai-for-open-source[bot] commented on code in PR #37112:
URL: https://github.com/apache/superset/pull/37112#discussion_r2730433635


##########
superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx:
##########
@@ -600,11 +626,69 @@ test('Should render RowCountLabel when row limit is hit, 
and hide it otherwise',
   );
 
   expect(screen.queryByTestId('warning')).not.toBeInTheDocument();
+
+  mockUseUiConfig.mockRestore();

Review Comment:
   **Suggestion:** Calling `mockUseUiConfig.mockRestore()` on a mock created 
via `jest.fn()` will throw because `mockRestore` is only available on spies 
created with `jest.spyOn()`; restore the original test default by resetting the 
mock's return value instead. [possible bug]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ SliceHeader unit test fails with runtime TypeError.
   - ❌ CI job running Jest will fail this test suite.
   - ⚠️ Developers blocked by failing local test runs.
   ```
   </details>
   
   ```suggestion
     mockUseUiConfig.mockReturnValue({
       hideTitle: false,
       hideTab: false,
       hideNav: false,
       hideChartControls: false,
       emitDataMasks: false,
       showRowLimitWarning: false,
     });
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Run the test file
   
`superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx` 
(e.g. `jest
   SliceHeader.test.tsx`).
   
   2. In the test setup the mock is created/typed at lines 601-604:
   
      - `601 const mockUseUiConfig = useUiConfig as jest.MockedFunction<`
   
      - `602 typeof useUiConfig`
   
      - `603 >;`
   
      - `604 mockUseUiConfig.mockReturnValue({ ... });`
   
      This shows `useUiConfig` is a `jest.fn()` mock, not a spy.
   
   3. Later the test calls the line at 630: `630 
mockUseUiConfig.mockRestore();`. Because
   `mockUseUiConfig` is a plain `jest.fn()` created via `jest.mock(...)`, 
`mockRestore` is
   not defined on it.
   
   4. Expected outcome: running the test will throw a runtime TypeError (e.g.,
   "mockUseUiConfig.mockRestore is not a function") at line 630, failing the 
test run.
   Replacing the call with `mockReturnValue(...)` (or 
`mockReset()`/`mockImplementationOnce`)
   restores intended behavior without throwing.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx
   **Line:** 630:630
   **Comment:**
        *Possible Bug: Calling `mockUseUiConfig.mockRestore()` on a mock 
created via `jest.fn()` will throw because `mockRestore` is only available on 
spies created with `jest.spyOn()`; restore the original test default by 
resetting the mock's return value instead.
   
   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.
   ```
   </details>



##########
superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx:
##########
@@ -632,11 +716,13 @@ test('Should hide RowCountLabel in embedded by default', 
() => {
   });
 
   expect(screen.queryByTestId('warning')).not.toBeInTheDocument();
+  expect(screen.queryByTestId('row-count-label')).not.toBeInTheDocument();
 
   mockIsEmbedded.mockRestore();

Review Comment:
   **Suggestion:** Calling `mockIsEmbedded.mockRestore()` on a `jest.fn()` mock 
will throw because `mockRestore` isn't supported; restore the original behavior 
by setting the mock return value back to `false`. [possible bug]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ SliceHeader embedded-mode tests fail at runtime.
   - ❌ CI Jest job will fail this test suite.
   - ⚠️ Local development interrupted by failing tests.
   ```
   </details>
   
   ```suggestion
     mockIsEmbedded.mockReturnValue(false);
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Run the test file
   
`superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx`.
   
   2. The `isEmbedded` mock is created/typed in this test around line 678:
   
      - `678 const mockIsEmbedded = isEmbedded as jest.MockedFunction<typeof 
isEmbedded>;`
   
      - The test sets `mockIsEmbedded.mockReturnValue(true);` at ~683.
   
   3. Later the test calls `721 mockIsEmbedded.mockRestore();`. Since 
`mockIsEmbedded` is a
   `jest.fn()` mock (created via `jest.mock(...)`), `mockRestore` is not 
present.
   
   4. Running the test triggers a TypeError at line 721 
("mockIsEmbedded.mockRestore is not a
   function"), causing the test to fail. Resetting the mock via 
`mockReturnValue(false)` or
   `mockReset()` is the correct non-throwing behavior.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/dashboard/components/SliceHeader/SliceHeader.test.tsx
   **Line:** 721:721
   **Comment:**
        *Possible Bug: Calling `mockIsEmbedded.mockRestore()` on a `jest.fn()` 
mock will throw because `mockRestore` isn't supported; restore the original 
behavior by setting the mock return value back to `false`.
   
   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.
   ```
   </details>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to