@transferwise/components 0.0.0-experimental-11ff1ec → 0.0.0-experimental-464eb4a

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-11ff1ec",
3
+ "version": "0.0.0-experimental-464eb4a",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,21 @@
1
+ import { createRef } from 'react';
2
+
3
+ import { render, screen } from '../../test-utils';
4
+
5
+ import Option from '.';
6
+
7
+ describe('Option', () => {
8
+ it('renders the title', () => {
9
+ render(<Option title="Option title" content="" media={<span />} button={<span />} />);
10
+
11
+ expect(() => screen.getByText('Option title')).not.toThrow();
12
+ });
13
+
14
+ it('`ref` attribute is passed to Option and reference is created', () => {
15
+ const reference = createRef<HTMLElement | HTMLAnchorElement>();
16
+
17
+ expect(reference.current).toBeFalsy();
18
+ render(<Option ref={reference} title="" content="" media={<span />} button={<span />} />);
19
+ expect(reference.current).toBeTruthy();
20
+ });
21
+ });
@@ -1,129 +0,0 @@
1
- import { shallow } from 'enzyme';
2
- import { createRef } from 'react';
3
-
4
- import { render, screen } from '../../test-utils';
5
-
6
- import Option from '.';
7
-
8
- describe('Option', () => {
9
- let component;
10
- beforeEach(() => {
11
- component = shallow(<Option title="" content="" media={<span />} button={<span />} />);
12
- });
13
-
14
- it('does not have decision class when the flag is set to false', () => {
15
- expect(hasDecisonClass()).toBe(true);
16
- component.setProps({ decision: false });
17
- expect(hasDecisonClass()).toBe(false);
18
- });
19
-
20
- it('has complex class when the flag is passed', () => {
21
- expect(hasComplexClass()).toBe(false);
22
- component.setProps({ complex: true });
23
- expect(hasComplexClass()).toBe(true);
24
- });
25
-
26
- it('has disabled class when the flag is passed', () => {
27
- expect(hasDisabledClass()).toBe(false);
28
- component.setProps({ disabled: true });
29
- expect(hasDisabledClass()).toBe(true);
30
- });
31
-
32
- it('has disabled attibute when the flag is passed for a button', () => {
33
- expect(hasDisabledAttribute()).toBe(false);
34
- component.setProps({ disabled: true });
35
- expect(hasDisabledAttribute()).toBe(false);
36
- component.setProps({ disabled: false, as: 'button' });
37
- expect(hasDisabledAttribute()).toBe(false);
38
- component.setProps({ disabled: true, as: 'button' });
39
- expect(hasDisabledAttribute()).toBe(true);
40
- });
41
-
42
- it('passes the className it is given to the element it renders', () => {
43
- expect(component.hasClass('some-class')).toBe(false);
44
- component.setProps({ className: 'some-class' });
45
- expect(component.hasClass('some-class')).toBe(true);
46
- });
47
-
48
- it('calls click handler on click', () => {
49
- const onClick = jest.fn();
50
- const event = { iAmAnEvent: true };
51
- component.setProps({ onClick });
52
-
53
- expect(onClick).not.toHaveBeenCalled();
54
- component.simulate('click', event);
55
- expect(onClick).toHaveBeenCalledWith(event);
56
- });
57
-
58
- it('has for attribute to label when prop is passed', () => {
59
- expect(htmlFor()).toBeUndefined();
60
- component.setProps({ htmlFor: 'some-id' });
61
- expect(htmlFor()).toBe('some-id');
62
- });
63
-
64
- it('has passed media in the circle on the left', () => {
65
- const Icon = () => <svg />;
66
- component.setProps({ media: <Icon /> });
67
-
68
- expect(circleContentIsElement(<Icon />)).toBe(true);
69
- });
70
-
71
- it('does not render the circle content with circle-inverse class when inverseMediaCircle is set to false', () => {
72
- expect(circleContentHasInverseClass()).toBe(true);
73
- component.setProps({ inverseMediaCircle: false });
74
- expect(circleContentHasInverseClass()).toBe(false);
75
- });
76
-
77
- it('renders the title', () => {
78
- render(<Option title="Option title" content="" media={<span />} button={<span />} />);
79
-
80
- expect(() => screen.getByText('Option title')).not.toThrow();
81
- });
82
-
83
- it('has passed content', () => {
84
- component.setProps({ content: <p>A content</p> });
85
- expect(bodyHasElement(<p>A content</p>)).toBe(true);
86
- });
87
-
88
- it('renders as a label by default', () => {
89
- expect(mainComponentTag()).toBe('label');
90
- });
91
-
92
- it('renders as the tag that you pass it', () => {
93
- component.setProps({ as: 'a', href: 'https://example.com' });
94
- expect(mainComponentTag()).toBe('a');
95
- });
96
-
97
- it('does not render the circle if media not passed', () => {
98
- expect(circle().exists()).toBe(true);
99
- component.setProps({ media: null });
100
- expect(circle().exists()).toBe(false);
101
- });
102
-
103
- it('passes href to the underlying component if passed', () => {
104
- expect(component.prop('href')).toBeFalsy();
105
- component.setProps({ href: 'https://example.com' });
106
- expect(component.prop('href')).toBe('https://example.com');
107
- });
108
-
109
- it('`ref` attribute is passed to Option and reference is created', () => {
110
- const reference = createRef();
111
-
112
- expect(reference.current).toBeFalsy();
113
- render(<Option ref={reference} title="" content="" media={<span />} button={<span />} />);
114
- expect(reference.current).toBeTruthy();
115
- });
116
-
117
- const hasDecisonClass = () => component.hasClass('decision');
118
- const hasComplexClass = () => component.hasClass('decision-complex');
119
- const hasDisabledClass = () => component.hasClass('disabled');
120
- const hasDisabledAttribute = () => component.prop('disabled');
121
- const htmlFor = () => component.prop('htmlFor');
122
- const circle = () => component.find('.media-left');
123
- const circleContent = () => component.find('.media-left .circle');
124
- const circleContentHasInverseClass = () => circleContent().hasClass('circle-inverse');
125
- const circleContentIsElement = (element) => circleContent().childAt(0).matchesElement(element);
126
- const mainComponentTag = () => component.name();
127
- const bodyHasElement = (element) =>
128
- component.find('.media-body').containsMatchingElement(element);
129
- });