-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Niloofar Sadeghi / Task - Refactor tests in the toggle-button-group.s…
…pec.tsx file (#7330) * refactor: toggle-button-group tests * fix: test issue Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>
- Loading branch information
1 parent
4c3f477
commit 906c784
Showing
3 changed files
with
39 additions
and
129 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...ges/trader/src/App/Components/Elements/ToggleButton/__tests__/toggle-button-group.spec.js
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,38 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import ToggleButtonGroup from '../toggle-button-group.jsx'; | ||
import ToggleButton from '../toggle-button.jsx'; | ||
|
||
const MockToggleButtonGroup = ({ value, className, multiple, onChange }) => ( | ||
<ToggleButtonGroup value={value} className={className} onChange={onChange} multiple={multiple}> | ||
<ToggleButton value='first-button'>first test button</ToggleButton> | ||
{multiple && <ToggleButton value='second-button'>second test button</ToggleButton>} | ||
</ToggleButtonGroup> | ||
); | ||
|
||
describe('ToggleButtonGroup', () => { | ||
it('should have "test-class" class when "className" passed', () => { | ||
render(<MockToggleButtonGroup className='test-class' />); | ||
expect(screen.getByTestId('dt_toggle_button_group')).toHaveClass('test-class'); | ||
}); | ||
|
||
it('should be called when the "ToggleButton" is clicked with value of the button', () => { | ||
const mock_click = jest.fn(); | ||
render(<MockToggleButtonGroup onChange={mock_click} />); | ||
const button = screen.getByRole('button', { name: 'first test button' }); | ||
userEvent.click(button); | ||
expect(mock_click).toHaveBeenCalledTimes(1); | ||
expect(mock_click.mock.calls[0][1]).toBe('first-button'); | ||
}); | ||
|
||
it('should be called when the "ToggleButton" is clicked with an empty array', () => { | ||
const mock_click = jest.fn(); | ||
render(<MockToggleButtonGroup value={['first-button']} multiple onChange={mock_click} />); | ||
const button = screen.getByRole('button', { name: 'first test button' }); | ||
userEvent.click(button); | ||
expect(mock_click).toHaveBeenCalledTimes(1); | ||
expect(Array.isArray(mock_click.mock.calls[0][1])).toBeTruthy(); | ||
expect(mock_click.mock.calls[0][1]).toHaveLength(0); | ||
}); | ||
}); |
128 changes: 0 additions & 128 deletions
128
...es/trader/src/App/Components/Elements/ToggleButton/__tests__/toggle-button-group.spec.tsx
This file was deleted.
Oops, something went wrong.
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