-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/husky-sidepanel: Fixed dropdown issue
- Loading branch information
1 parent
1fa4f58
commit 85e0e2f
Showing
8 changed files
with
3,837 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import SingleSelectWithImage from '../../components/form/single-select-with-image'; | ||
import '@testing-library/jest-dom'; | ||
|
||
describe('SingleSelectWithImage Component', () => { | ||
const mockOptions = [ | ||
{ id: 1, name: 'Option 1', icon: 'icon1.png' }, | ||
{ id: 2, name: 'Option 2', icon: 'icon2.png' }, | ||
]; | ||
|
||
const mockOnItemSelect = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('renders with default props', () => { | ||
const { getByPlaceholderText } = render( | ||
<SingleSelectWithImage | ||
options={mockOptions} | ||
selectedOption={null} | ||
onItemSelect={mockOnItemSelect} | ||
uniqueKey="id" | ||
displayKey="name" | ||
defaultIcon="default.png" | ||
id="single-select" | ||
/> | ||
); | ||
expect(getByPlaceholderText('Select')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays label when provided', () => { | ||
const { getByText } = render( | ||
<SingleSelectWithImage | ||
options={mockOptions} | ||
selectedOption={null} | ||
onItemSelect={mockOnItemSelect} | ||
uniqueKey="id" | ||
displayKey="name" | ||
defaultIcon="default.png" | ||
label="Select an option" | ||
id="single-select" | ||
/> | ||
); | ||
expect(getByText('Select an option')).toBeInTheDocument(); | ||
}); | ||
|
||
test('shows options when input is clicked', () => { | ||
const { getByPlaceholderText, getByText } = render( | ||
<SingleSelectWithImage | ||
options={mockOptions} | ||
selectedOption={null} | ||
onItemSelect={mockOnItemSelect} | ||
uniqueKey="id" | ||
displayKey="name" | ||
defaultIcon="default.png" | ||
id="single-select" | ||
/> | ||
); | ||
fireEvent.click(getByPlaceholderText('Select')); | ||
expect(getByText('Option 1')).toBeInTheDocument(); | ||
expect(getByText('Option 2')).toBeInTheDocument(); | ||
}); | ||
|
||
test('selects an option when clicked', () => { | ||
const { getByPlaceholderText, getByText } = render( | ||
<SingleSelectWithImage | ||
options={mockOptions} | ||
selectedOption={null} | ||
onItemSelect={mockOnItemSelect} | ||
uniqueKey="id" | ||
displayKey="name" | ||
defaultIcon="default.png" | ||
id="single-select" | ||
/> | ||
); | ||
fireEvent.click(getByPlaceholderText('Select')); | ||
fireEvent.click(getByText('Option 1')); | ||
expect(mockOnItemSelect).toHaveBeenCalledWith(mockOptions[0]); | ||
}); | ||
|
||
test('shows no results message when filtered options are empty', () => { | ||
const { getByPlaceholderText, getByText } = render( | ||
<SingleSelectWithImage | ||
options={[]} | ||
selectedOption={null} | ||
onItemSelect={mockOnItemSelect} | ||
uniqueKey="id" | ||
displayKey="name" | ||
defaultIcon="default.png" | ||
id="single-select" | ||
/> | ||
); | ||
fireEvent.click(getByPlaceholderText('Select')); | ||
expect(getByText('No results found')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders selected option correctly', () => { | ||
const { getByPlaceholderText } = render( | ||
<SingleSelectWithImage | ||
options={mockOptions} | ||
selectedOption={mockOptions[0]} | ||
onItemSelect={mockOnItemSelect} | ||
uniqueKey="id" | ||
displayKey="name" | ||
defaultIcon="default.png" | ||
id="single-select" | ||
/> | ||
); | ||
expect(getByPlaceholderText('Select').value).toBe('Option 1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Config } from 'jest' | ||
import nextJest from 'next/jest.js' | ||
|
||
const createJestConfig = nextJest({ | ||
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment | ||
dir: './', | ||
}) | ||
|
||
// Add any custom config to be passed to Jest | ||
const config: Config = { | ||
coverageProvider: 'v8', | ||
testEnvironment: 'jsdom', | ||
// Add more setup options before each test is run | ||
// setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'], | ||
} | ||
|
||
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | ||
export default createJestConfig(config) |
Oops, something went wrong.