@transferwise/components 0.0.0-experimental-c29561b → 0.0.0-experimental-db4ed13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-c29561b",
3
+ "version": "0.0.0-experimental-db4ed13",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,73 @@
1
+ import { render, screen, userEvent } from '../test-utils';
2
+ import RadioOption, { type RadioOptionProps } from '.';
3
+
4
+ describe('Radio option', () => {
5
+ const initialProps = {
6
+ id: 'componentId',
7
+ name: 'componentName',
8
+ title: 'Component Title',
9
+ content: <img alt="contentImage" />,
10
+ onChange: jest.fn(),
11
+ };
12
+
13
+ const customRender = (overrides: Partial<RadioOptionProps> = {}) =>
14
+ render(<RadioOption {...initialProps} {...overrides} />);
15
+
16
+ it('should render `media`', () => {
17
+ const Icon = <img alt="media" />;
18
+ customRender({ media: Icon });
19
+ expect(screen.getByRole('img', { name: 'media' })).toBeInTheDocument();
20
+ });
21
+
22
+ it('passes props to radio button', () => {
23
+ customRender();
24
+ expect(screen.getByRole('radio')).toHaveAttribute('id', initialProps.id);
25
+ });
26
+
27
+ it('passes name to radio button', () => {
28
+ customRender();
29
+ expect(screen.getByRole('radio')).toHaveAttribute('name', initialProps.name);
30
+ });
31
+
32
+ describe('checked', () => {
33
+ it('should be `false` by default', () => {
34
+ customRender();
35
+ expect(screen.getByRole('radio')).not.toBeChecked();
36
+ });
37
+
38
+ it('should respect the prop', () => {
39
+ customRender({ checked: true });
40
+ expect(screen.getByRole('radio')).toBeChecked();
41
+ });
42
+ });
43
+
44
+ it('passes change handler to radio button', async () => {
45
+ customRender();
46
+ await userEvent.click(screen.getByRole('radio'));
47
+ expect(initialProps.onChange).toHaveBeenCalledTimes(1);
48
+ });
49
+
50
+ describe('disabled', () => {
51
+ it('should be `false` by default', () => {
52
+ customRender();
53
+ expect(screen.getByRole('radio')).toBeEnabled();
54
+ });
55
+
56
+ it('should respect the prop', () => {
57
+ customRender({ disabled: true });
58
+ expect(screen.getByRole('radio')).toBeDisabled();
59
+ });
60
+ });
61
+
62
+ describe('isContainerAligned', () => {
63
+ it('should not be aligned by default', () => {
64
+ const { container } = customRender();
65
+ expect(container.querySelector('.np-option')).not.toHaveClass('np-option__container-aligned');
66
+ });
67
+
68
+ it('renders aligned with container content', () => {
69
+ const { container } = customRender({ isContainerAligned: true });
70
+ expect(container.querySelector('.np-option')).toHaveClass('np-option__container-aligned');
71
+ });
72
+ });
73
+ });
@@ -1,67 +0,0 @@
1
- import { shallow } from 'enzyme';
2
-
3
- import Option from '../common/Option';
4
-
5
- import RadioOption from '.';
6
-
7
- describe('Radio option', () => {
8
- let component;
9
- beforeEach(() => {
10
- component = shallow(
11
- <RadioOption media={<span />} id="" name="" title="" content="" onChange={jest.fn()} />,
12
- );
13
- });
14
-
15
- it('passes shared props to option', () => {
16
- const Icon = () => <svg />;
17
- const sharedProps = {
18
- media: <Icon />,
19
- title: 'A title',
20
- content: 'A content',
21
- name: 'a-name',
22
- complex: true,
23
- disabled: true,
24
- };
25
- component.setProps(sharedProps);
26
-
27
- expect(option().props()).toStrictEqual(expect.objectContaining(sharedProps));
28
- });
29
-
30
- it('passes id to radio button passed as button', () => {
31
- component.setProps({ id: 'some-id' });
32
- expect(buttonProperty('id')).toBe('some-id');
33
- });
34
-
35
- it('passes name to radio button passed as button', () => {
36
- component.setProps({ name: 'a-name' });
37
- expect(buttonProperty('name')).toBe('a-name');
38
- });
39
-
40
- it('passes checked to radio button passed as button', () => {
41
- expect(buttonProperty('checked')).toBeFalsy();
42
- component.setProps({ checked: true });
43
- expect(buttonProperty('checked')).toBeTruthy();
44
- });
45
-
46
- it('passes change handler to radio button passed as button', () => {
47
- const onChange = jest.fn();
48
- component.setProps({ onChange });
49
- expect(buttonProperty('onChange')).toBe(onChange);
50
- });
51
-
52
- it('passes disabled to radio button passed as button', () => {
53
- expect(buttonProperty('disabled')).toBeFalsy();
54
- component.setProps({ disabled: true });
55
- expect(buttonProperty('disabled')).toBeTruthy();
56
- });
57
-
58
- it('renders aligned with container content', () => {
59
- component.setProps({ isContainerAligned: true });
60
- expect(component.find(Option).shallow().prop('className')).toContain(
61
- 'np-option__container-aligned',
62
- );
63
- });
64
-
65
- const option = () => component.find(Option);
66
- const buttonProperty = (name) => option().prop('button').props[name];
67
- });