@transferwise/components 46.91.0 → 46.93.0
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/build/actionOption/ActionOption.js +11 -5
- package/build/actionOption/ActionOption.js.map +1 -1
- package/build/actionOption/ActionOption.mjs +11 -5
- package/build/actionOption/ActionOption.mjs.map +1 -1
- package/build/common/Option/Option.js +9 -4
- package/build/common/Option/Option.js.map +1 -1
- package/build/common/Option/Option.mjs +10 -5
- package/build/common/Option/Option.mjs.map +1 -1
- package/build/dateLookup/dateTrigger/DateTrigger.js +11 -6
- package/build/dateLookup/dateTrigger/DateTrigger.js.map +1 -1
- package/build/dateLookup/dateTrigger/DateTrigger.mjs +11 -6
- package/build/dateLookup/dateTrigger/DateTrigger.mjs.map +1 -1
- package/build/definitionList/DefinitionList.js +5 -3
- package/build/definitionList/DefinitionList.js.map +1 -1
- package/build/definitionList/DefinitionList.mjs +5 -3
- package/build/definitionList/DefinitionList.mjs.map +1 -1
- package/build/main.css +23 -32
- package/build/snackbar/Snackbar.js +4 -2
- package/build/snackbar/Snackbar.js.map +1 -1
- package/build/snackbar/Snackbar.mjs +4 -2
- package/build/snackbar/Snackbar.mjs.map +1 -1
- package/build/styles/common/Option/Option.css +22 -0
- package/build/styles/dateLookup/dateTrigger/DateTrigger.css +1 -32
- package/build/styles/main.css +23 -32
- package/build/types/actionOption/ActionOption.d.ts +4 -3
- package/build/types/actionOption/ActionOption.d.ts.map +1 -1
- package/build/types/common/Option/Option.d.ts +1 -0
- package/build/types/common/Option/Option.d.ts.map +1 -1
- package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts.map +1 -1
- package/build/types/definitionList/DefinitionList.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/actionOption/ActionOption.spec.tsx +20 -0
- package/src/actionOption/ActionOption.story.tsx +2 -0
- package/src/actionOption/ActionOption.tsx +15 -5
- package/src/button/Button.story.tsx +8 -0
- package/src/common/Option/Option.css +22 -0
- package/src/common/Option/Option.less +21 -0
- package/src/common/Option/Option.spec.tsx +21 -0
- package/src/common/Option/Option.tsx +7 -1
- package/src/dateLookup/DateLookup.spec.tsx +445 -0
- package/src/dateLookup/dateTrigger/DateTrigger.css +1 -32
- package/src/dateLookup/dateTrigger/DateTrigger.less +4 -28
- package/src/dateLookup/dateTrigger/DateTrigger.tsx +9 -5
- package/src/definitionList/DefinitionList.tsx +3 -3
- package/src/inputs/InputGroup.story.tsx +5 -3
- package/src/listItem/ListItem.spec.tsx +10 -2
- package/src/listItem/ListItem.story.tsx +11 -3
- package/src/main.css +23 -32
- package/src/snackbar/Snackbar.tsx +3 -3
- package/src/withNextPortal/withNextPortal.spec.tsx +24 -0
- package/src/common/Option/Option.spec.js +0 -129
- package/src/dateLookup/DateLookup.proptypes.spec.js +0 -28
- package/src/dateLookup/DateLookup.rtl.spec.tsx +0 -199
- package/src/dateLookup/DateLookup.state.spec.js +0 -76
- package/src/dateLookup/DateLookup.testingLibrary.spec.js +0 -256
- package/src/dateLookup/DateLookup.view.spec.js +0 -151
- package/src/dateLookup/dateHeader/DateHeader.spec.js +0 -95
- package/src/dateLookup/dateTrigger/DateTrigger.spec.js +0 -123
- package/src/dateLookup/dayCalendar/DayCalendar.spec.js +0 -122
- package/src/dateLookup/dayCalendar/table/DayCalendarTable.spec.js +0 -147
- package/src/dateLookup/monthCalendar/MonthCalendar.spec.js +0 -105
- package/src/dateLookup/monthCalendar/table/MonthCalendarTable.spec.js +0 -120
- package/src/dateLookup/tableLink/TableLink.spec.js +0 -109
- package/src/dateLookup/yearCalendar/YearCalendar.spec.js +0 -88
- package/src/dateLookup/yearCalendar/table/YearCalendarTable.spec.js +0 -121
- package/src/modal/Modal.spec.js +0 -197
- package/src/withNextPortal/withNextPortal.spec.js +0 -22
- /package/src/modal/{Modal.rtl.spec.tsx → Modal.spec.tsx} +0 -0
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import * as formatting from '@transferwise/formatting';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import { useIntl } from 'react-intl';
|
|
4
|
-
|
|
5
|
-
import YearCalendarTable from '.';
|
|
6
|
-
|
|
7
|
-
jest.mock('react-intl');
|
|
8
|
-
jest.mock('@transferwise/formatting', () => ({
|
|
9
|
-
formatDate: jest.fn().mockReturnValue('XXXX'),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
describe('YearCalendarTable', () => {
|
|
13
|
-
const locale = 'en-GB';
|
|
14
|
-
let component;
|
|
15
|
-
let props;
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
props = {
|
|
19
|
-
viewYear: 2018,
|
|
20
|
-
placeholder: 'Enter date..',
|
|
21
|
-
onSelect: jest.fn(),
|
|
22
|
-
};
|
|
23
|
-
useIntl.mockReturnValue({ locale });
|
|
24
|
-
component = shallow(<YearCalendarTable {...props} />);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('generates 5x4 table', () => {
|
|
28
|
-
expect(component.find('tbody tr')).toHaveLength(5);
|
|
29
|
-
expect(component.find('tbody td')).toHaveLength(20);
|
|
30
|
-
expect(getTableLink()).toHaveLength(20);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('starts with year 2000, 2020, 2040 etc', () => {
|
|
34
|
-
expect(getTableLinkAt(0).prop('item')).toBe(2000);
|
|
35
|
-
component.setProps({ viewYear: 2020 });
|
|
36
|
-
expect(getTableLinkAt(0).prop('item')).toBe(2020);
|
|
37
|
-
component.setProps({ viewYear: 2021 });
|
|
38
|
-
expect(getTableLinkAt(0).prop('item')).toBe(2020);
|
|
39
|
-
component.setProps({ viewYear: 2039 });
|
|
40
|
-
expect(getTableLinkAt(0).prop('item')).toBe(2020);
|
|
41
|
-
component.setProps({ viewYear: 2040 });
|
|
42
|
-
expect(getTableLinkAt(0).prop('item')).toBe(2040);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('passes year value and type to TableLink', () => {
|
|
46
|
-
expect(getTableLinkAt(0).prop('item')).toBe(2000);
|
|
47
|
-
expect(getTableLinkAt(0).prop('type')).toBe('year');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('shows formatted years', () => {
|
|
51
|
-
expect(getTableLinkAt(0).prop('title')).toBe('XXXX');
|
|
52
|
-
expect(formatting.formatDate).toHaveBeenCalledWith(new Date(2018, 0), locale, {
|
|
53
|
-
year: 'numeric',
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('show selectedDate as active', () => {
|
|
58
|
-
component.setProps({ selectedDate: new Date(2018, 11, 27) });
|
|
59
|
-
expect(getTableLinkAt(17).prop('active')).toBe(false);
|
|
60
|
-
expect(getTableLinkAt(18).prop('active')).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('disables dates outside of min and max range', () => {
|
|
64
|
-
component.setProps({
|
|
65
|
-
selectedDate: new Date(2017, 11, 27),
|
|
66
|
-
min: new Date(2016, 1),
|
|
67
|
-
max: new Date(2018, 11),
|
|
68
|
-
});
|
|
69
|
-
expect(getTableLinkAt(15).prop('disabled')).toBe(true);
|
|
70
|
-
expect(getTableLinkAt(16).prop('disabled')).toBe(false);
|
|
71
|
-
expect(getTableLinkAt(17).prop('disabled')).toBe(false);
|
|
72
|
-
expect(getTableLinkAt(18).prop('disabled')).toBe(false);
|
|
73
|
-
expect(getTableLinkAt(19).prop('disabled')).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('highlights today', () => {
|
|
77
|
-
const today = new Date();
|
|
78
|
-
component.setProps({
|
|
79
|
-
selectedDate: today,
|
|
80
|
-
viewYear: today.getFullYear(),
|
|
81
|
-
});
|
|
82
|
-
expect(getTableLink().find({ today: true }).prop('item')).toBe(today.getFullYear());
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('passes onSelect to TableLink', () => {
|
|
86
|
-
expect(getTableLinkAt(0).prop('onClick')).toBe(props.onSelect);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('shows placeholder for screen-readers', () => {
|
|
90
|
-
expect(component.find('.sr-only').text()).toBe('Enter date..');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('sets autofocus to true when 2002 is the selected year', () => {
|
|
94
|
-
component.setProps({ selectedDate: new Date(2002, 5, 1) });
|
|
95
|
-
expect(getTableLinkAt(2).prop('autofocus')).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('sets autofocus to true when selected year is null and current year is visible', () => {
|
|
99
|
-
const today = new Date();
|
|
100
|
-
component.setProps({
|
|
101
|
-
selectedDate: null,
|
|
102
|
-
viewYear: today.getFullYear(),
|
|
103
|
-
});
|
|
104
|
-
expect(getTableLink().find({ today: true }).prop('autofocus')).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('sets autofocus to true on the second year when the first year is disabled', () => {
|
|
108
|
-
component.setProps({
|
|
109
|
-
selectedDate: null,
|
|
110
|
-
viewYear: 2000,
|
|
111
|
-
min: new Date(2001, 1, 1),
|
|
112
|
-
isDisabled: (month) => month === 0,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(getTableLinkAt(0).prop('autofocus')).toBe(false);
|
|
116
|
-
expect(getTableLinkAt(1).prop('autofocus')).toBe(true);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const getTableLinkAt = (i) => component.find('[type="year"]').at(i);
|
|
120
|
-
const getTableLink = () => component.find('[type="year"]');
|
|
121
|
-
});
|
package/src/modal/Modal.spec.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { mount } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import { Title } from '..';
|
|
4
|
-
import { mockMatchMedia } from '../test-utils';
|
|
5
|
-
|
|
6
|
-
import Modal from './Modal';
|
|
7
|
-
|
|
8
|
-
jest.useFakeTimers();
|
|
9
|
-
mockMatchMedia();
|
|
10
|
-
jest.mock('../common');
|
|
11
|
-
|
|
12
|
-
const defaultLocale = 'en-GB';
|
|
13
|
-
|
|
14
|
-
jest.mock('react-intl', () => ({
|
|
15
|
-
injectIntl: (Component) =>
|
|
16
|
-
function (props) {
|
|
17
|
-
return <Component {...props} intl={{ locale: defaultLocale }} />;
|
|
18
|
-
},
|
|
19
|
-
useIntl: () => ({ locale: defaultLocale, formatMessage: (id) => String(id) }),
|
|
20
|
-
defineMessages: (translations) => translations,
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
describe('Modal', () => {
|
|
24
|
-
let component;
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
component = mount(<Modal body="Some body" open onClose={jest.fn()} />);
|
|
27
|
-
|
|
28
|
-
jest.clearAllMocks();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('has Dimmer with prop open set correctly', () => {
|
|
32
|
-
component.setProps({ open: false });
|
|
33
|
-
expect(dimmer().prop('open')).toBe(false);
|
|
34
|
-
component.setProps({ open: true });
|
|
35
|
-
expect(dimmer().prop('open')).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('renders', () => {
|
|
39
|
-
it('default dialog', () => {
|
|
40
|
-
expect(modal()).toHaveLength(1);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('with right size when passed down the props', () => {
|
|
44
|
-
component.setProps({ size: 'sm' });
|
|
45
|
-
expect(modalDialog().hasClass('tw-modal-sm')).toBe(true);
|
|
46
|
-
component.setProps({ size: 'md' });
|
|
47
|
-
expect(modalDialog().hasClass('tw-modal-md')).toBe(true);
|
|
48
|
-
component.setProps({ size: 'lg' });
|
|
49
|
-
expect(modalDialog().hasClass('tw-modal-lg')).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('with title when title is provided', () => {
|
|
53
|
-
expect(modalTitle().text()).toBe('');
|
|
54
|
-
component.setProps({ title: 'A title' });
|
|
55
|
-
|
|
56
|
-
expect(modalTitle()).toHaveLength(1);
|
|
57
|
-
expect(modalTitle().text()).toBe('A title');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('with a custom class if classname is provided', () => {
|
|
61
|
-
component.setProps({ className: 'a-custom-className' });
|
|
62
|
-
expect(modal().hasClass('a-custom-className')).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('with some random other props', () => {
|
|
66
|
-
component.setProps({ somerandomprop: 'thing', someotherrandomprop: 'other thing' });
|
|
67
|
-
|
|
68
|
-
expect(modal().prop('somerandomprop')).toBe('thing');
|
|
69
|
-
expect(modal().prop('someotherrandomprop')).toBe('other thing');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('with body content', () => {
|
|
73
|
-
component.setProps({ body: <p>Some paragraph text</p> });
|
|
74
|
-
|
|
75
|
-
expect(modalBody().text()).toBe('Some paragraph text');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('with scroll classes set', () => {
|
|
79
|
-
component.setProps({ body: <p>Some paragraph text</p>, scroll: 'content' });
|
|
80
|
-
|
|
81
|
-
expect(modal().hasClass('tw-modal--scrollable')).toBe(true);
|
|
82
|
-
expect(modalBody().hasClass('tw-modal-body--scrollable')).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('with no footer when `footer` not specified as prop', () => {
|
|
86
|
-
component.setProps({ footer: null });
|
|
87
|
-
expect(modalFooter()).toHaveLength(0);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('with footer content when `footer` specified as prop', () => {
|
|
91
|
-
component.setProps({ footer: <button type="button">Some button</button> });
|
|
92
|
-
|
|
93
|
-
expect(modalFooter()).toHaveLength(1);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('header', () => {
|
|
97
|
-
it('with divider if title is provided', () => {
|
|
98
|
-
expect(modalHeader().hasClass('modal--withoutborder')).toBe(true);
|
|
99
|
-
component.setProps({ title: 'Some title' });
|
|
100
|
-
expect(modalHeader().hasClass('modal--withoutborder')).toBe(false);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('with divider if no-Divider class is provided', () => {
|
|
104
|
-
component.setProps({ title: 'Some title' });
|
|
105
|
-
expect(modalHeader().hasClass('modal--withoutborder')).toBe(false);
|
|
106
|
-
component.setProps({ className: 'no-divider' });
|
|
107
|
-
expect(modalHeader().hasClass('modal--withoutborder')).toBe(true);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('content', () => {
|
|
112
|
-
it('with compact class if compact class is provided', () => {
|
|
113
|
-
component.setProps({ className: '' });
|
|
114
|
-
expect(modalContent().hasClass('tw-modal-compact')).toBe(false);
|
|
115
|
-
component.setProps({ className: 'compact' });
|
|
116
|
-
expect(modalContent().hasClass('tw-modal-compact')).toBe(true);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('with no title class if title is not provided', () => {
|
|
120
|
-
component.setProps({ title: 'a title' });
|
|
121
|
-
expect(modalContent().hasClass('tw-modal-no-title')).toBe(false);
|
|
122
|
-
component.setProps({ title: '' });
|
|
123
|
-
expect(modalContent().hasClass('tw-modal-no-title')).toBe(true);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('behaviourally', () => {
|
|
129
|
-
let originalAddEventListener;
|
|
130
|
-
let documentEventCallbacks;
|
|
131
|
-
|
|
132
|
-
beforeEach(() => {
|
|
133
|
-
originalAddEventListener = global.document.addEventListener;
|
|
134
|
-
documentEventCallbacks = {};
|
|
135
|
-
jest.spyOn(global.document, 'addEventListener').mockImplementation((name, callback) => {
|
|
136
|
-
documentEventCallbacks[name] = callback;
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
afterEach(() => {
|
|
141
|
-
global.document.addEventListener = originalAddEventListener;
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('calls close handler on close button click', () => {
|
|
145
|
-
const onClose = jest.fn();
|
|
146
|
-
component.setProps({ onClose });
|
|
147
|
-
|
|
148
|
-
expect(onClose).not.toHaveBeenCalled();
|
|
149
|
-
clickCloseButton();
|
|
150
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('only calls close handler once when setting open to false in onClose handler', () => {
|
|
154
|
-
const onClose = jest.fn(() => {
|
|
155
|
-
component.setProps({ open: false });
|
|
156
|
-
});
|
|
157
|
-
component.setProps({ onClose });
|
|
158
|
-
expect(onClose).not.toHaveBeenCalled();
|
|
159
|
-
clickCloseButton();
|
|
160
|
-
jest.runAllTimers();
|
|
161
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('passes onUnmount to Dimmer onExited prop', () => {
|
|
165
|
-
const onUnmount = jest.fn();
|
|
166
|
-
component.setProps({ onUnmount });
|
|
167
|
-
component.setProps({ open: true });
|
|
168
|
-
expect(component.find('Dimmer').prop('onExited')).toBe(onUnmount);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('calls onUnmount when the component unmounts', () => {
|
|
172
|
-
const onUnmount = jest.fn();
|
|
173
|
-
component.setProps({ onUnmount });
|
|
174
|
-
component.setProps({ open: true });
|
|
175
|
-
expect(onUnmount).not.toHaveBeenCalled();
|
|
176
|
-
jest.runAllTimers();
|
|
177
|
-
component.setProps({ open: false });
|
|
178
|
-
component.find('Dimmer').prop('onExited')();
|
|
179
|
-
expect(onUnmount).toHaveBeenCalledTimes(1);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
const clickCloseButton = () => {
|
|
183
|
-
component.find('.close').simulate('click');
|
|
184
|
-
};
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
const modal = () => component.find('.tw-modal');
|
|
188
|
-
const modalDialog = () => component.find('.tw-modal-dialog');
|
|
189
|
-
const modalHeader = () => component.find('.tw-modal-header');
|
|
190
|
-
const modalTitle = () => component.find(Title);
|
|
191
|
-
const modalContent = () => component.find('.tw-modal-content');
|
|
192
|
-
const modalBody = () => component.find('.tw-modal-body');
|
|
193
|
-
const modalFooter = () => component.find('.tw-modal-footer');
|
|
194
|
-
|
|
195
|
-
// For some reason Dimmer gets rendered as Component so this is the best way I found to access it.
|
|
196
|
-
const dimmer = () => component.at(0);
|
|
197
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { mount } from 'enzyme';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
|
-
|
|
4
|
-
import withNextPortal from './withNextPortal';
|
|
5
|
-
|
|
6
|
-
jest.mock('react-dom');
|
|
7
|
-
|
|
8
|
-
describe('withNextPortal', () => {
|
|
9
|
-
it('should return a function', () => {
|
|
10
|
-
expect(typeof withNextPortal()).toBe('function');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should create a portal with the component', () => {
|
|
14
|
-
ReactDOM.createPortal.mockImplementation(() => null);
|
|
15
|
-
const props = {};
|
|
16
|
-
const Component = withNextPortal(AnyComponent);
|
|
17
|
-
mount(<Component {...props} />);
|
|
18
|
-
expect(ReactDOM.createPortal).toHaveBeenCalledTimes(1);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const AnyComponent = () => <div>Test div</div>;
|
|
22
|
-
});
|
|
File without changes
|