Skip to content

Create test to select#78

Open
rotemergty5 wants to merge 4 commits into
mainfrom
SGLSelect-test
Open

Create test to select#78
rotemergty5 wants to merge 4 commits into
mainfrom
SGLSelect-test

Conversation

@rotemergty5

@rotemergty5 rotemergty5 commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Description

Please include a summary of the changes and the related issue.

Related Issue(s)

Fixes # (issue number)

Checklist:

  • I have performed a self-review of my own code
  • My changes generate no new warnings

Screenshots (if appropriate):

Summary by CodeRabbit

  • Tests
    • Added test coverage for the Select component to verify dropdown opening, option selection (including replacing a selection), and Escape/interaction handling.
    • Added a test helper to render components with the application theme for more reliable UI tests and consistent styling in test environments.

@rotemergty5 rotemergty5 requested review from GilHeller and Tamir198 May 25, 2026 20:54
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a theme-aware RTL render helper and a Vitest test suite for SGLSelect covering dropdown open, option selection, Escape dismissal, and changing selections.

Changes

SGLSelect Test Suite

Layer / File(s) Summary
Test render helper
src/tests/renderWithTheme.tsx
Exports renderWithTheme(ui: ReactElement) that wraps ui with MUI ThemeProvider using the project theme and renders via RTL.
SGLSelect selection and keyboard interaction tests
src/components/UI/Select/SGLSelect.test.tsx, src/tests/renderWithTheme.tsx
Vitest test suite with afterEach(cleanup) and three interaction tests: opening dropdown and selecting "Banana" updates combobox text; opening dropdown and pressing Escape prevents selection; selecting "Banana" then "Orange" updates combobox text to the latest choice.

Possibly Related PRs

Suggested Reviewers

  • Tamir198
  • GilHeller

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops to run the test,
Wraps each component in theme dressed best.
Clicks for Banana, then Orange takes stage,
Escape skips choice — assertions engage.
Hooray, the select behaved: time to rest!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only the template placeholders with no actual content; all required sections are empty or unfilled. Complete the description by summarizing the changes (test suite for SGLSelect and renderWithTheme utility), filling in the related issue number, and checking the verification boxes.
Title check ❓ Inconclusive The title 'Create test to select' is vague and incomplete; it does not clearly specify what test is being created or what selection mechanism is being tested. Improve the title to be more specific, such as 'Add SGLSelect test suite with option selection tests' or 'Add test utilities and SGLSelect dropdown tests'.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SGLSelect-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/components/UI/Select/SGLSelect.test.tsx (1)

7-9: 💤 Low value

Consider removing redundant cleanup.

React Testing Library automatically performs cleanup after each test when used with Vitest, making this afterEach call unnecessary.

♻️ Simplify by removing redundant cleanup
-afterEach(() => {
-  cleanup()
-})
-
 describe('SGLSelect', () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/UI/Select/SGLSelect.test.tsx` around lines 7 - 9, The
afterEach block calling cleanup() is redundant because React Testing Library
with Vitest auto-cleans between tests; remove the afterEach(() => { cleanup() })
block from the SGLSelect.test.tsx file (the explicit cleanup call) so tests rely
on the test runner's automatic teardown and avoid duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/UI/Select/SGLSelect.test.tsx`:
- Line 25: Remove the trailing whitespace and extra newline after the test block
closing token shown as "})" in SGLSelect.test.tsx; replace the "})  " with a
clean "})" (no spaces or extra blank line) so the file passes Prettier
formatting; ensure there are no other trailing spaces in the file.
- Around line 28-37: The test currently renders <SGLSelect options={options}
value="" /> so asserting the combobox does not contain "Banana" cannot verify
Escape behavior; update the test to render with a non-empty initial value (e.g.,
value="Banana") or with a controlled value variable set to "Banana", open the
dropdown via fireEvent.mouseDown(select), send Escape with
fireEvent.keyDown(select, { key: 'Escape' }), and then assert the combobox still
contains "Banana" (or that the controlled value didn't change) to confirm the
original value is preserved after pressing Escape; use the existing SGLSelect
component and the select element obtained by screen.getByRole('combobox') to
locate the element.
- Around line 39-57: The third test case "should change the selected value when
selecting a different option" in SGLSelect.test.tsx has incorrect 2-space
indentation causing Prettier errors; update the block that renders <SGLSelect
options={options} />, the queries (screen.getByRole/getByText), fireEvent calls,
and expect assertions to use the project's 4-space indentation for all nested
lines so the file passes formatting checks and the test remains functionally
unchanged.

---

Nitpick comments:
In `@src/components/UI/Select/SGLSelect.test.tsx`:
- Around line 7-9: The afterEach block calling cleanup() is redundant because
React Testing Library with Vitest auto-cleans between tests; remove the
afterEach(() => { cleanup() }) block from the SGLSelect.test.tsx file (the
explicit cleanup call) so tests rely on the test runner's automatic teardown and
avoid duplication.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb047916-8e1d-41f3-9e30-26a14225cb21

📥 Commits

Reviewing files that changed from the base of the PR and between 0213a24 and 5959861.

📒 Files selected for processing (1)
  • src/components/UI/Select/SGLSelect.test.tsx

Comment thread src/components/UI/Select/SGLSelect.test.tsx Outdated
Comment on lines +28 to +37
it('should not select any item when dropdown is opened and closed', () => {
render(<SGLSelect options={options} value="" />)

const select = screen.getByRole('combobox')

fireEvent.mouseDown(select)
fireEvent.keyDown(select, { key: 'Escape' })

expect(select).not.toHaveTextContent('Banana')
})

@coderabbitai coderabbitai Bot May 25, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Strengthen the Escape key test assertion.

The current assertion doesn't properly verify Escape behavior. Since value="" is set initially, the combobox would not contain "Banana" regardless of whether Escape works correctly. The test should verify that the original value is preserved after pressing Escape.

🧪 Improved test for Escape key behavior
-  it('should not select any item when dropdown is opened and closed', () => {
-    render(<SGLSelect options={options} value="" />)
+  it('should preserve the selected value when Escape is pressed', () => {
+    render(<SGLSelect options={options} />)
 
     const select = screen.getByRole('combobox')
+    
+    // Initially should show first option (Apple) due to defaultValue
+    expect(select).toHaveTextContent('Apple')
 
     fireEvent.mouseDown(select)
     fireEvent.keyDown(select, { key: 'Escape' })
 
-    expect(select).not.toHaveTextContent('Banana')
+    // After Escape, should still show Apple
+    expect(select).toHaveTextContent('Apple')
   })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/UI/Select/SGLSelect.test.tsx` around lines 28 - 37, The test
currently renders <SGLSelect options={options} value="" /> so asserting the
combobox does not contain "Banana" cannot verify Escape behavior; update the
test to render with a non-empty initial value (e.g., value="Banana") or with a
controlled value variable set to "Banana", open the dropdown via
fireEvent.mouseDown(select), send Escape with fireEvent.keyDown(select, { key:
'Escape' }), and then assert the combobox still contains "Banana" (or that the
controlled value didn't change) to confirm the original value is preserved after
pressing Escape; use the existing SGLSelect component and the select element
obtained by screen.getByRole('combobox') to locate the element.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rotemergty5 I agree with this comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rotemergty5 Reminder

Comment thread src/components/UI/Select/SGLSelect.test.tsx

@Tamir198 Tamir198 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you checked yourself locally? your tests are failing:

Image

Before you pushed the code did you tests passed?

@rotemergty5

Copy link
Copy Markdown
Collaborator Author

@Tamir198 Fixed the failing tests. I verified locally and all tests are now passing.


it('should select the relevant item', () => {
render(
<ThemeProvider theme={theme}>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be extracted into general helper component, we can put it inside src/tests/....

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Do you want me to create a shared test helper under src/tests and move the ThemeProvider wrapper there?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done, I extracted the ThemeProvider wrapper into a shared helper under src/tests and updated the tests to use it.

Comment on lines +28 to +37
it('should not select any item when dropdown is opened and closed', () => {
render(<SGLSelect options={options} value="" />)

const select = screen.getByRole('combobox')

fireEvent.mouseDown(select)
fireEvent.keyDown(select, { key: 'Escape' })

expect(select).not.toHaveTextContent('Banana')
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rotemergty5 I agree with this comment

Comment thread src/tests/renderWithTheme.tsx Outdated

import { theme } from '../theme'

export const renderWithTheme = (ui: ReactElement) =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

React got a prop for this called children

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean using a wrapper component with children and passing it to render as wrapper?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done, updated renderWithTheme to use a wrapper component with children.

Comment on lines +28 to +37
it('should not select any item when dropdown is opened and closed', () => {
render(<SGLSelect options={options} value="" />)

const select = screen.getByRole('combobox')

fireEvent.mouseDown(select)
fireEvent.keyDown(select, { key: 'Escape' })

expect(select).not.toHaveTextContent('Banana')
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rotemergty5 Reminder

@GilHeller GilHeller left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See @Tamir198 comments

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/tests/renderWithTheme.tsx (1)

7-11: ⚡ Quick win

Resolve the Fast Refresh lint warning by inlining the wrapper.

Line 7 defines a top-level component in a file exporting a non-component utility, which triggers the react-refresh warning. Inlining the wrapper inside renderWithTheme keeps behavior unchanged and removes the warning.

Suggested diff
-import type { PropsWithChildren, ReactElement } from 'react'
+import type { PropsWithChildren, ReactElement } from 'react'
@@
-const Wrapper = ({ children }: PropsWithChildren) => (
-  <ThemeProvider theme={theme}>{children}</ThemeProvider>
-)
-
-export const renderWithTheme = (ui: ReactElement) => render(ui, { wrapper: Wrapper })
+export const renderWithTheme = (ui: ReactElement) => {
+  const wrapper = ({ children }: PropsWithChildren) => (
+    <ThemeProvider theme={theme}>{children}</ThemeProvider>
+  )
+  return render(ui, { wrapper })
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tests/renderWithTheme.tsx` around lines 7 - 11, The top-level Wrapper
component causes a Fast Refresh lint warning; remove the exported Wrapper and
inline it inside renderWithTheme by replacing the external Wrapper reference
with an inline wrapper function passed to render (e.g., wrapper: ({ children })
=> <ThemeProvider theme={theme}>{children}</ThemeProvider>); update
renderWithTheme to accept the same ReactElement input and call render(ui, {
wrapper: inlineWrapper }) so ThemeProvider and theme usage remains unchanged
while eliminating the top-level component (references: Wrapper, renderWithTheme,
ThemeProvider, theme).

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/tests/renderWithTheme.tsx`:
- Around line 7-11: The top-level Wrapper component causes a Fast Refresh lint
warning; remove the exported Wrapper and inline it inside renderWithTheme by
replacing the external Wrapper reference with an inline wrapper function passed
to render (e.g., wrapper: ({ children }) => <ThemeProvider
theme={theme}>{children}</ThemeProvider>); update renderWithTheme to accept the
same ReactElement input and call render(ui, { wrapper: inlineWrapper }) so
ThemeProvider and theme usage remains unchanged while eliminating the top-level
component (references: Wrapper, renderWithTheme, ThemeProvider, theme).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e00265d4-2c36-4af4-9de6-282ec38ace1b

📥 Commits

Reviewing files that changed from the base of the PR and between ff73993 and fb7fc70.

📒 Files selected for processing (1)
  • src/tests/renderWithTheme.tsx

<ThemeProvider theme={theme}>{children}</ThemeProvider>
)

export const renderWithTheme = (ui: ReactElement) => render(ui, { wrapper: Wrapper })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can just export the Wrapper component. Also rename it to more indicative name

Comment on lines +27 to +36
it('should not select any item when dropdown is opened and closed', () => {
renderWithTheme(<SGLSelect options={options} value="" />)

const select = screen.getByRole('combobox')

fireEvent.mouseDown(select)
fireEvent.keyDown(select, { key: 'Escape' })

expect(select).not.toHaveTextContent('Banana')
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As @Tamir198 and the coderabbit said, you have a logic flaw. If you wont click anything the value obviously wont be "Banana". Consider to change the test for trying to click "Banana" option while not appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants