generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from eea/develop
Release
- Loading branch information
Showing
6 changed files
with
125 additions
and
5 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
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,50 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import renderer from 'react-test-renderer'; | ||
import ThemePicker from './ThemePicker'; | ||
|
||
describe('ThemePicker', () => { | ||
const props = { | ||
id: 'test-theme-picker', | ||
title: 'Test Theme Picker', | ||
value: 'color1', | ||
colors: [ | ||
{ name: 'color1', label: 'Color 1' }, | ||
{ name: 'color2', label: 'Color 2' }, | ||
], | ||
onChange: () => {}, | ||
}; | ||
|
||
it('renders correctly', () => { | ||
const component = renderer.create(<ThemePicker {...props} />); | ||
|
||
const json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
const label = component.toJSON().children[0].children[0].children[0] | ||
.children[0].children[0]; | ||
const buttons = component.toJSON().children[0].children[0].children[0] | ||
.children[0].children[1]; | ||
|
||
expect(label.children[0]).toBe('Test Theme Picker'); | ||
expect(buttons.children[0].props.className).toContain('color1'); | ||
expect(buttons.children[1].props.className).toContain('color2'); | ||
}); | ||
|
||
it('calls onChange with correct value when a color button is clicked', () => { | ||
const onChange = jest.fn(); | ||
const { getByTitle } = render( | ||
<ThemePicker {...props} onChange={onChange} />, | ||
); | ||
|
||
fireEvent.click(getByTitle('Color 2')); | ||
expect(onChange).toHaveBeenCalledWith('test-theme-picker', 'color2'); | ||
}); | ||
|
||
it('does not render when no colors are provided', () => { | ||
const component = renderer.create(<ThemePicker {...props} colors={[]} />); | ||
|
||
let json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
expect(json).toBeNull(); | ||
}); | ||
}); |
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,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ThemePicker does not render when no colors are provided 1`] = `null`; | ||
|
||
exports[`ThemePicker renders correctly 1`] = ` | ||
<div | ||
className="inline field" | ||
id="field-test-theme-picker" | ||
> | ||
<div | ||
className="ui grid" | ||
> | ||
<div | ||
className="row" | ||
> | ||
<div | ||
className="middle aligned twelve wide column color-picker-widget" | ||
> | ||
<div | ||
className="wrapper" | ||
> | ||
<label | ||
htmlFor="field-test-theme-picker" | ||
> | ||
Test Theme Picker | ||
</label> | ||
<div | ||
className="buttons" | ||
> | ||
<button | ||
aria-label="Color 1" | ||
className="ui active circular button color1" | ||
onClick={[Function]} | ||
title="Color 1" | ||
/> | ||
<button | ||
aria-label="Color 2" | ||
className="ui circular button color2" | ||
onClick={[Function]} | ||
title="Color 2" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |