-
Notifications
You must be signed in to change notification settings - Fork 0
Create test to select #78
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: main
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,57 @@ | ||
| import { describe, it, expect, afterEach } from 'vitest' | ||
| import '@testing-library/jest-dom/vitest' | ||
| import { screen, fireEvent, cleanup } from '@testing-library/react' | ||
| import { renderWithTheme } from '../../../tests/renderWithTheme' | ||
| import { SGLSelect } from './SGLSelect' | ||
|
|
||
| afterEach(() => { | ||
| cleanup() | ||
| }) | ||
|
|
||
| describe('SGLSelect', () => { | ||
| const options = ['Apple', 'Banana', 'Orange'] | ||
|
|
||
| it('should select the relevant item', () => { | ||
| renderWithTheme(<SGLSelect options={options} />) | ||
|
|
||
| const select = screen.getByRole('combobox') | ||
|
|
||
| fireEvent.mouseDown(select) | ||
|
|
||
| const option = screen.getByText('Banana') | ||
| fireEvent.click(option) | ||
|
|
||
| expect(select).toHaveTextContent('Banana') | ||
| }) | ||
|
|
||
| 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') | ||
| }) | ||
|
Comment on lines
+27
to
+36
Collaborator
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. 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.
Collaborator
Author
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. Done. Updated the wrapper name and improved the test. |
||
|
|
||
| it('should change the selected value when selecting a different option', () => { | ||
| renderWithTheme(<SGLSelect options={options} />) | ||
|
|
||
| const select = screen.getByRole('combobox') | ||
|
|
||
| fireEvent.mouseDown(select) | ||
|
|
||
| const bananaOption = screen.getByText('Banana') | ||
| fireEvent.click(bananaOption) | ||
|
|
||
| expect(select).toHaveTextContent('Banana') | ||
|
|
||
| fireEvent.mouseDown(select) | ||
|
|
||
| const orangeOption = screen.getByText('Orange') | ||
| fireEvent.click(orangeOption) | ||
|
|
||
| expect(select).toHaveTextContent('Orange') | ||
| }) | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { ThemeProvider } from '@mui/material/styles' | ||
| import type { PropsWithChildren, ReactElement } from 'react' | ||
|
|
||
| import { theme } from '../theme' | ||
|
|
||
| const Wrapper = ({ children }: PropsWithChildren) => ( | ||
| <ThemeProvider theme={theme}>{children}</ThemeProvider> | ||
| ) | ||
|
|
||
| export const renderWithTheme = (ui: ReactElement) => render(ui, { wrapper: Wrapper }) | ||
|
Collaborator
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. You can just export the |
||
Uh oh!
There was an error while loading. Please reload this page.
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.
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
🤖 Prompt for AI Agents
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.
@rotemergty5 I agree with this comment
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.
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.
@rotemergty5 Reminder