-
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.
Signed-off-by: guido <[email protected]>
- Loading branch information
Showing
3 changed files
with
136 additions
and
10 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
58 changes: 58 additions & 0 deletions
58
tests/js/unit/components/__snapshots__/entities-toggle-control.test.tsx.snap
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,58 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EntitiesToggleControl renders correctly 1`] = ` | ||
<div | ||
class="test-class wz-toggle-control wz-toggle-control--entities" | ||
> | ||
<div | ||
class="wz-toggle-control-item" | ||
> | ||
<label | ||
for="wz-toggle-control-item__input-1" | ||
> | ||
<input | ||
id="wz-toggle-control-item__input-1" | ||
type="checkbox" | ||
value="1" | ||
/> | ||
Option 1 | ||
</label> | ||
</div> | ||
<div | ||
class="wz-toggle-control-item" | ||
> | ||
<label | ||
for="wz-toggle-control-item__input-2" | ||
> | ||
<input | ||
id="wz-toggle-control-item__input-2" | ||
type="checkbox" | ||
value="2" | ||
/> | ||
Option 2 | ||
</label> | ||
</div> | ||
<div | ||
class="wz-toggle-control-item" | ||
> | ||
<label | ||
for="wz-toggle-control-item__input-3" | ||
> | ||
<input | ||
id="wz-toggle-control-item__input-3" | ||
type="checkbox" | ||
value="3" | ||
/> | ||
Option 3 | ||
</label> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`EntitiesToggleControl renders the NoOptionsMessage when there are no options 1`] = ` | ||
<p | ||
class="wz-entities-search-no-option-message" | ||
> | ||
No options | ||
</p> | ||
`; |
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,74 @@ | ||
import { OrderedSet } from 'immutable'; | ||
import React from 'react'; | ||
|
||
import { describe, expect, it, jest } from '@jest/globals'; | ||
|
||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
|
||
import { EntitiesToggleControl } from '../../../../sources/js/src/components/entities-toggle-control'; | ||
|
||
const options = OrderedSet([ | ||
{ label: 'Option 1', value: '1' }, | ||
{ label: 'Option 2', value: '2' }, | ||
{ label: 'Option 3', value: '3' }, | ||
]); | ||
|
||
describe('EntitiesToggleControl', () => { | ||
it('renders correctly', () => { | ||
const { container } = render( | ||
<EntitiesToggleControl | ||
className="test-class" | ||
options={options} | ||
onChange={() => {}} | ||
/> | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders the NoOptionsMessage when there are no options', () => { | ||
const { container } = render( | ||
<EntitiesToggleControl | ||
className="test-class" | ||
options={OrderedSet([])} | ||
onChange={() => {}} | ||
/> | ||
); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('updates the value when one or more option are selected', () => { | ||
const onChange = jest.fn(); | ||
|
||
render( | ||
<EntitiesToggleControl | ||
className="test-class" | ||
options={options} | ||
value={OrderedSet()} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
fireEvent.click(screen.getByLabelText('Option 1')); | ||
|
||
expect(onChange).toHaveBeenCalledWith(OrderedSet(['1'])); | ||
}); | ||
|
||
it('updates the value when one or more option are unselected', () => { | ||
const onChange = jest.fn(); | ||
|
||
render( | ||
<EntitiesToggleControl | ||
className="test-class" | ||
options={options} | ||
value={OrderedSet(['1', '2'])} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
fireEvent.click(screen.getByLabelText('Option 1')); | ||
|
||
expect(onChange).toHaveBeenCalledWith(OrderedSet(['2'])); | ||
}); | ||
}); |