@eeacms/volto-widget-toggle 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
### [3.1.2](https://github.com/eea/volto-widget-toggle/compare/3.1.1...3.1.2) - 24 July 2023
|
|
8
|
+
|
|
9
|
+
#### :hammer_and_wrench: Others
|
|
10
|
+
|
|
11
|
+
- test: add unit tests for CheckboxWidget - refs #253277 [ana-oprea - [`7eb7622`](https://github.com/eea/volto-widget-toggle/commit/7eb7622ab02f7a429ad300c0795798aa7301e918)]
|
|
7
12
|
### [3.1.1](https://github.com/eea/volto-widget-toggle/compare/3.1.0...3.1.1) - 12 June 2023
|
|
8
13
|
|
|
9
14
|
#### :hammer_and_wrench: Others
|
package/package.json
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { Provider } from 'react-intl-redux';
|
|
4
|
+
import CheckboxWidget from './CheckboxWidget';
|
|
5
|
+
import configureStore from 'redux-mock-store';
|
|
6
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
7
|
+
|
|
8
|
+
const mockStore = configureStore([]);
|
|
9
|
+
const store = mockStore({
|
|
10
|
+
intl: {
|
|
11
|
+
locale: 'en',
|
|
12
|
+
messages: {},
|
|
13
|
+
formatMessage: jest.fn(),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const mockOnChange = jest.fn();
|
|
18
|
+
|
|
19
|
+
describe('CheckboxWidget', () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('renders a checkbox', () => {
|
|
25
|
+
const { getByText } = render(
|
|
26
|
+
<Provider store={store} locale="en">
|
|
27
|
+
<CheckboxWidget
|
|
28
|
+
id="test"
|
|
29
|
+
title="Test Checkbox"
|
|
30
|
+
onChange={mockOnChange}
|
|
31
|
+
/>
|
|
32
|
+
</Provider>,
|
|
33
|
+
);
|
|
34
|
+
expect(getByText('Test Checkbox')).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('sets a default value if given', () => {
|
|
38
|
+
render(
|
|
39
|
+
<Provider store={store} locale="en">
|
|
40
|
+
<CheckboxWidget
|
|
41
|
+
id="test"
|
|
42
|
+
title="Test Checkbox"
|
|
43
|
+
onChange={mockOnChange}
|
|
44
|
+
defaultValue={true}
|
|
45
|
+
/>
|
|
46
|
+
</Provider>,
|
|
47
|
+
);
|
|
48
|
+
expect(mockOnChange).toHaveBeenCalledWith('test', true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('does not set a default value if already having a value', () => {
|
|
52
|
+
render(
|
|
53
|
+
<Provider store={store} locale="en">
|
|
54
|
+
<CheckboxWidget
|
|
55
|
+
id="test"
|
|
56
|
+
title="Test Checkbox"
|
|
57
|
+
onChange={mockOnChange}
|
|
58
|
+
value={false}
|
|
59
|
+
defaultValue={true}
|
|
60
|
+
/>
|
|
61
|
+
</Provider>,
|
|
62
|
+
);
|
|
63
|
+
expect(mockOnChange).not.toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
});
|