codeant-ai-for-open-source[bot] commented on code in PR #38033:
URL: https://github.com/apache/superset/pull/38033#discussion_r3627552126
##########
superset-frontend/src/pages/Register/Register.test.tsx:
##########
@@ -80,3 +111,71 @@ test('should render input placeholders', () => {
expect(screen.getByPlaceholderText('Password')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Confirm password')).toBeInTheDocument();
});
+
+// --- Recaptcha tests ---
+
+test('should not render captcha when RECAPTCHA_PUBLIC_KEY is empty', () => {
+ renderRegister();
+ expect(screen.queryByTestId('captcha-input')).not.toBeInTheDocument();
+});
+
+test('should render captcha when RECAPTCHA_PUBLIC_KEY is set', () => {
+ mockGetBootstrapData.mockReturnValue({
+ common: {
+ conf: {
+ RECAPTCHA_PUBLIC_KEY: 'test-key-123',
+ },
+ },
+ });
+ renderRegister();
+ expect(screen.getByTestId('captcha-input')).toBeInTheDocument();
Review Comment:
**Suggestion:** This assertion queries `data-testid`, but the mocked captcha
component in this file renders `data-test`, so the test will fail even when
captcha is correctly rendered. Use a selector consistent with the mock (or
update the mock attribute) so the test validates real behavior. [logic error]
<details>
<summary><b>Severity Level:</b> Critical π¨</summary>
```mdx
- β Register page tests fail in current Jest test suite.
- β οΈ Recaptcha conditional rendering behavior not properly validated.
```
</details>
<details>
<summary><b>Steps of Reproduction β
</b></summary>
```mdx
1. In `superset-frontend/src/pages/Register/Register.test.tsx` lines 40β43,
note the mock
for `react-google-recaptcha` returns `<div data-test="captcha-input" />`,
i.e., it sets
`data-test`, not `data-testid`.
2. In the same file, lines 122β132 define `test('should render captcha when
RECAPTCHA_PUBLIC_KEY is set', ...)` and at line 131 call
`screen.getByTestId('captcha-input')` expecting the element to be present.
3. Run the front-end Jest test suite (e.g., `npm test` or `yarn test`),
which executes
`Register.test.tsx` and renders the `Register` component with
`RECAPTCHA_PUBLIC_KEY` set
in the mocked `getBootstrapData` (lines 122β129).
4. When the test runs, the mock reCAPTCHA component renders a `div` with
`data-test="captcha-input"`, but React Testing Libraryβs `getByTestId`
searches for
`data-testid="captcha-input"`, cannot find it, and throws an error at line
131, causing
this test (and the suite) to fail even though the captcha mock is rendered.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f50cd2b31c59496f8f4d131271ac54b4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=f50cd2b31c59496f8f4d131271ac54b4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent π€ </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/pages/Register/Register.test.tsx
**Line:** 131:131
**Comment:**
*Logic Error: This assertion queries `data-testid`, but the mocked
captcha component in this file renders `data-test`, so the test will fail even
when captcha is correctly rendered. Use a selector consistent with the mock (or
update the mock attribute) so the test validates real behavior.
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.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38033&comment_hash=a838f1968f779476a43f47c938438b158814c3c14bca3c178cc34b384cdec1e9&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38033&comment_hash=a838f1968f779476a43f47c938438b158814c3c14bca3c178cc34b384cdec1e9&reaction=dislike'>π</a>
--
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]