@transferwise/components 46.92.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.
Files changed (66) hide show
  1. package/build/actionOption/ActionOption.js +2 -0
  2. package/build/actionOption/ActionOption.js.map +1 -1
  3. package/build/actionOption/ActionOption.mjs +2 -0
  4. package/build/actionOption/ActionOption.mjs.map +1 -1
  5. package/build/common/Option/Option.js +9 -4
  6. package/build/common/Option/Option.js.map +1 -1
  7. package/build/common/Option/Option.mjs +10 -5
  8. package/build/common/Option/Option.mjs.map +1 -1
  9. package/build/dateLookup/dateTrigger/DateTrigger.js +11 -6
  10. package/build/dateLookup/dateTrigger/DateTrigger.js.map +1 -1
  11. package/build/dateLookup/dateTrigger/DateTrigger.mjs +11 -6
  12. package/build/dateLookup/dateTrigger/DateTrigger.mjs.map +1 -1
  13. package/build/definitionList/DefinitionList.js +5 -3
  14. package/build/definitionList/DefinitionList.js.map +1 -1
  15. package/build/definitionList/DefinitionList.mjs +5 -3
  16. package/build/definitionList/DefinitionList.mjs.map +1 -1
  17. package/build/main.css +23 -32
  18. package/build/snackbar/Snackbar.js +4 -2
  19. package/build/snackbar/Snackbar.js.map +1 -1
  20. package/build/snackbar/Snackbar.mjs +4 -2
  21. package/build/snackbar/Snackbar.mjs.map +1 -1
  22. package/build/styles/common/Option/Option.css +22 -0
  23. package/build/styles/dateLookup/dateTrigger/DateTrigger.css +1 -32
  24. package/build/styles/main.css +23 -32
  25. package/build/types/actionOption/ActionOption.d.ts +2 -1
  26. package/build/types/actionOption/ActionOption.d.ts.map +1 -1
  27. package/build/types/common/Option/Option.d.ts +1 -0
  28. package/build/types/common/Option/Option.d.ts.map +1 -1
  29. package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts.map +1 -1
  30. package/build/types/definitionList/DefinitionList.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/src/actionOption/ActionOption.story.tsx +2 -0
  33. package/src/actionOption/ActionOption.tsx +3 -0
  34. package/src/common/Option/Option.css +22 -0
  35. package/src/common/Option/Option.less +21 -0
  36. package/src/common/Option/Option.spec.tsx +21 -0
  37. package/src/common/Option/Option.tsx +7 -1
  38. package/src/dateLookup/DateLookup.spec.tsx +445 -0
  39. package/src/dateLookup/dateTrigger/DateTrigger.css +1 -32
  40. package/src/dateLookup/dateTrigger/DateTrigger.less +4 -28
  41. package/src/dateLookup/dateTrigger/DateTrigger.tsx +9 -5
  42. package/src/definitionList/DefinitionList.tsx +3 -3
  43. package/src/inputs/InputGroup.story.tsx +5 -3
  44. package/src/listItem/ListItem.spec.tsx +10 -2
  45. package/src/listItem/ListItem.story.tsx +11 -3
  46. package/src/main.css +23 -32
  47. package/src/snackbar/Snackbar.tsx +3 -3
  48. package/src/withNextPortal/withNextPortal.spec.tsx +24 -0
  49. package/src/common/Option/Option.spec.js +0 -129
  50. package/src/dateLookup/DateLookup.proptypes.spec.js +0 -28
  51. package/src/dateLookup/DateLookup.rtl.spec.tsx +0 -199
  52. package/src/dateLookup/DateLookup.state.spec.js +0 -76
  53. package/src/dateLookup/DateLookup.testingLibrary.spec.js +0 -256
  54. package/src/dateLookup/DateLookup.view.spec.js +0 -151
  55. package/src/dateLookup/dateHeader/DateHeader.spec.js +0 -95
  56. package/src/dateLookup/dateTrigger/DateTrigger.spec.js +0 -123
  57. package/src/dateLookup/dayCalendar/DayCalendar.spec.js +0 -122
  58. package/src/dateLookup/dayCalendar/table/DayCalendarTable.spec.js +0 -147
  59. package/src/dateLookup/monthCalendar/MonthCalendar.spec.js +0 -105
  60. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.spec.js +0 -120
  61. package/src/dateLookup/tableLink/TableLink.spec.js +0 -109
  62. package/src/dateLookup/yearCalendar/YearCalendar.spec.js +0 -88
  63. package/src/dateLookup/yearCalendar/table/YearCalendarTable.spec.js +0 -121
  64. package/src/modal/Modal.spec.js +0 -197
  65. package/src/withNextPortal/withNextPortal.spec.js +0 -22
  66. /package/src/modal/{Modal.rtl.spec.tsx → Modal.spec.tsx} +0 -0
@@ -1,122 +0,0 @@
1
- import * as formatting from '@transferwise/formatting';
2
- import { shallow } from 'enzyme';
3
-
4
- import DateHeader from '../dateHeader';
5
-
6
- import DayCalendarTable from './table';
7
-
8
- import DayCalendar from '.';
9
-
10
- const locale = 'en-GB';
11
- const formatMessage = (id) => `${id}`;
12
- jest.mock('react-intl', () => ({
13
- injectIntl: (Component) =>
14
- function (props) {
15
- return <Component {...props} intl={{ locale, formatMessage }} />;
16
- },
17
- defineMessages: (translations) => translations,
18
- }));
19
- jest.mock('@transferwise/formatting', () => ({
20
- formatDate: jest.fn().mockReturnValue('MonthName XXXX'),
21
- }));
22
-
23
- describe('DayCalendar', () => {
24
- const selectedDate = new Date(2018, 10, 27);
25
- const min = new Date(1990, 10, 27);
26
- const max = new Date(2020, 10, 27);
27
- let component;
28
- let props;
29
-
30
- beforeEach(() => {
31
- props = {
32
- selectedDate,
33
- min,
34
- max,
35
- viewMonth: 10,
36
- viewYear: 2018,
37
- monthFormat: 'long',
38
- onSelect: jest.fn(),
39
- onLabelClick: jest.fn(),
40
- onViewDateUpdate: jest.fn(),
41
- };
42
- component = shallow(<DayCalendar {...props} />).dive();
43
- });
44
-
45
- it('shows the header', () => {
46
- expect(header()).toHaveLength(1);
47
- });
48
-
49
- it('shows formatted date as header label in long format', () => {
50
- expect(header().prop('label')).toBe('MonthName XXXX');
51
- expect(formatting.formatDate).toHaveBeenCalledWith(new Date(2018, 10), locale, {
52
- month: 'long',
53
- year: 'numeric',
54
- });
55
- });
56
-
57
- it('shows formatted date as header label in short format', () => {
58
- component.setProps({ monthFormat: 'short' });
59
- expect(header().prop('label')).toBe('MonthName XXXX');
60
- expect(formatting.formatDate).toHaveBeenCalledWith(new Date(2018, 10), locale, {
61
- month: 'short',
62
- year: 'numeric',
63
- });
64
- });
65
-
66
- it('passes onLabelClick to header component', () => {
67
- expect(header().prop('onLabelClick')).toBe(props.onLabelClick);
68
- });
69
-
70
- it('passes selectPreviousMonth to header component', () => {
71
- expect(header().prop('onPreviousClick')).toBe(component.instance().selectPreviousMonth);
72
- });
73
-
74
- it('passes selectNextMonth header component', () => {
75
- expect(header().prop('onNextClick')).toBe(component.instance().selectNextMonth);
76
- });
77
-
78
- it('passes dateMode header component', () => {
79
- expect(header().prop('dateMode')).toBeDefined();
80
- });
81
-
82
- it('calls onViewDateUpdate on previous month select', () => {
83
- component.instance().selectPreviousMonth();
84
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 2018, month: 9 });
85
- });
86
-
87
- it('calls onViewDateUpdate on previous month select (year before)', () => {
88
- component.setProps({ viewMonth: 0 });
89
- component.instance().selectPreviousMonth();
90
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 2017, month: 11 });
91
- });
92
-
93
- it('calls onViewDateUpdate on next year select', () => {
94
- component.instance().selectNextMonth();
95
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 2018, month: 11 });
96
- });
97
-
98
- it('calls onViewDateUpdate on next year select (year after)', () => {
99
- component.setProps({ viewMonth: 11 });
100
- component.instance().selectNextMonth();
101
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 2019, month: 0 });
102
- });
103
-
104
- it('shows month calendar table', () => {
105
- expect(table()).toHaveLength(1);
106
- });
107
-
108
- it('passes props forward to table component', () => {
109
- expect(table().prop('selectedDate')).toBe(selectedDate);
110
- expect(table().prop('min')).toBe(min);
111
- expect(table().prop('max')).toBe(max);
112
- expect(table().prop('viewMonth')).toBe(10);
113
- expect(table().prop('viewYear')).toBe(2018);
114
- });
115
-
116
- it('passes onSelect to table component', () => {
117
- expect(table().prop('onSelect')).toBe(props.onSelect);
118
- });
119
-
120
- const header = () => component.find(DateHeader);
121
- const table = () => component.find(DayCalendarTable);
122
- });
@@ -1,147 +0,0 @@
1
- import * as formatting from '@transferwise/formatting';
2
- import { shallow } from 'enzyme';
3
-
4
- import * as dateUtils from '../../../common/dateUtils';
5
- import TableLink from '../../tableLink';
6
-
7
- import DayCalendarTable from '.';
8
-
9
- const locale = 'en-GB';
10
- jest.mock('react-intl', () => ({
11
- injectIntl: (Component) =>
12
- function (props) {
13
- return <Component {...props} intl={{ locale }} />;
14
- },
15
- defineMessages: (translations) => translations,
16
- }));
17
-
18
- jest.mock('@transferwise/formatting', () => ({
19
- formatDate: jest.fn().mockReturnValue('XXXX'),
20
- }));
21
-
22
- jest.mock('../../../common/dateUtils', () => ({
23
- getDayNames: () => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
24
- isWithinRange: jest.fn().mockReturnValue(true),
25
- }));
26
-
27
- jest.mock('../../getStartOfDay', () => ({
28
- getStartOfDay: (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate()),
29
- }));
30
-
31
- describe('DayCalendarTable', () => {
32
- let component;
33
- let props;
34
-
35
- beforeEach(() => {
36
- props = {
37
- viewMonth: 11,
38
- viewYear: 2018,
39
- onSelect: jest.fn(),
40
- };
41
- component = shallow(<DayCalendarTable {...props} />).dive();
42
- });
43
-
44
- it('shows weekday names in table header', () => {
45
- const ths = component.find('thead th');
46
- expect(ths).toHaveLength(7);
47
- expect(ths.at(0).text()).toContain('Mon');
48
- expect(ths.at(6).text()).toContain('Sun');
49
- });
50
-
51
- it('shows all days of month (2018 December)', () => {
52
- expect(component.find('tbody tr')).toHaveLength(6);
53
- expect(component.find('tbody td')).toHaveLength(42);
54
- expect(component.find(TableLink)).toHaveLength(31);
55
- });
56
-
57
- it('shows empty items before first day of month (Sat, 1st December 2018)', () => {
58
- expect(getTableDataAt(0).children()).toHaveLength(0);
59
- expect(getTableDataAt(4).children()).toHaveLength(0);
60
- expect(getTableDataAt(5).children()).toHaveLength(1);
61
- expect(getTableDataAt(6).children()).toHaveLength(1);
62
- });
63
-
64
- it('display empty cells after the last day (Mon, 31st 2018 December)', () => {
65
- expect(getTableDataAt(35).children()).toHaveLength(1);
66
- expect(getTableDataAt(36).children()).toHaveLength(0);
67
- expect(getTableDataAt(37).children()).toHaveLength(0);
68
- });
69
-
70
- it('passes day value and type to TableLink', () => {
71
- expect(getTableLinkAt(0).prop('item')).toBe(1);
72
- expect(getTableLinkAt(0).prop('type')).toBe('day');
73
- });
74
-
75
- it('shows formatted days', () => {
76
- expect(getTableLinkAt(0).prop('title')).toBe('XXXX');
77
- expect(formatting.formatDate).toHaveBeenCalledWith(new Date(2018, 11, 1), locale, {
78
- day: 'numeric',
79
- });
80
- });
81
-
82
- it('shows full date as link title', () => {
83
- expect(getTableLinkAt(0).prop('longTitle')).toBe('XXXX');
84
- expect(formatting.formatDate).toHaveBeenCalledWith(new Date(2018, 11, 1), locale);
85
- });
86
-
87
- it('show selectedDate as active', () => {
88
- component.setProps({ selectedDate: new Date(2018, 11, 27) });
89
- expect(component.find(TableLink).find({ active: true }).prop('item')).toBe(27);
90
- });
91
-
92
- it('sets property "disabled" for table links (calls isWithinRange)', () => {
93
- const selectedDate = new Date(2018, 11, 26);
94
- const min = new Date(2018, 11, 26);
95
- const max = new Date(2018, 11, 27);
96
- component.setProps({ selectedDate, min, max });
97
- expect(dateUtils.isWithinRange).toHaveBeenCalledWith(selectedDate, min, max);
98
- expect(getTableLinkAt(0).prop('disabled')).toBe(false);
99
- });
100
-
101
- it('highlights today', () => {
102
- const today = new Date();
103
- component.setProps({
104
- selectedDate: today,
105
- viewMonth: today.getMonth(),
106
- viewYear: today.getFullYear(),
107
- });
108
- expect(component.find(TableLink).find({ today: true }).prop('item')).toBe(today.getDate());
109
- });
110
-
111
- it('passes selectDay to TableLink', () => {
112
- expect(getTableLinkAt(0).prop('onClick')).toBe(component.instance().selectDay);
113
- });
114
-
115
- it('calls onSelect when day gets selected', () => {
116
- component.instance().selectDay(1);
117
- expect(props.onSelect).toHaveBeenCalledWith(new Date(2018, 11, 1));
118
- });
119
-
120
- it('sets autofocus to true when 5 is the selected day', () => {
121
- component.setProps({ selectedDate: new Date(2018, 11, 5) });
122
- expect(getTableLinkAt(4).prop('autofocus')).toBe(true);
123
- });
124
-
125
- it('does not set autofocus to true when 5 is the selected day but not the right month', () => {
126
- component.setProps({ selectedDate: new Date(2018, 10, 5) });
127
- expect(getTableLinkAt(4).prop('autofocus')).toBe(false);
128
- });
129
-
130
- it('does not set autofocus to true when 5 is the selected day but not the right year', () => {
131
- component.setProps({ selectedDate: new Date(2017, 11, 5) });
132
- expect(getTableLinkAt(4).prop('autofocus')).toBe(false);
133
- });
134
-
135
- it('sets autofocus to true when selected date is null and current day is visible', () => {
136
- const today = new Date();
137
- component.setProps({
138
- selectedDate: today,
139
- viewMonth: today.getMonth(),
140
- viewYear: today.getFullYear(),
141
- });
142
- expect(component.find(TableLink).find({ today: true }).prop('autofocus')).toBe(true);
143
- });
144
-
145
- const getTableLinkAt = (i) => component.find(TableLink).at(i);
146
- const getTableDataAt = (i) => component.find('tbody td').at(i);
147
- });
@@ -1,105 +0,0 @@
1
- import * as formatting from '@transferwise/formatting';
2
- import { shallow } from 'enzyme';
3
-
4
- import DateHeader from '../dateHeader';
5
-
6
- import MonthCalendarTable from './table';
7
-
8
- import MonthCalendar from '.';
9
-
10
- const defaultLocale = 'en-GB';
11
- const formatMessage = (id) => `${id}`;
12
- jest.mock('react-intl', () => ({
13
- injectIntl: (Component) =>
14
- function (props) {
15
- return <Component {...props} intl={{ locale: defaultLocale, formatMessage }} />;
16
- },
17
- defineMessages: (translations) => translations,
18
- }));
19
- jest.mock('@transferwise/formatting', () => ({
20
- formatDate: jest.fn().mockReturnValue('XXXX'),
21
- }));
22
-
23
- describe('MonthCalendar', () => {
24
- const selectedDate = new Date(2018, 11, 27);
25
- const min = new Date(1990, 11, 27);
26
- const max = new Date(2020, 11, 27);
27
- let component;
28
- let props;
29
-
30
- beforeEach(() => {
31
- props = {
32
- selectedDate,
33
- min,
34
- max,
35
- viewYear: 2018,
36
- placeholder: 'Enter date..',
37
- onSelect: jest.fn(),
38
- onLabelClick: jest.fn(),
39
- onViewDateUpdate: jest.fn(),
40
- };
41
- component = shallow(<MonthCalendar {...props} />).dive();
42
- });
43
-
44
- it('shows the header', () => {
45
- expect(header()).toHaveLength(1);
46
- });
47
-
48
- it('shows formatted date as header label', () => {
49
- expect(header().prop('label')).toBe('XXXX');
50
- expect(formatting.formatDate).toHaveBeenCalledWith(new Date(2018, 0), defaultLocale, {
51
- year: 'numeric',
52
- });
53
- });
54
-
55
- it('passes onLabelClick to header component', () => {
56
- expect(header().prop('onLabelClick')).toBe(props.onLabelClick);
57
- });
58
-
59
- it('passes selectPreviousYear to header component', () => {
60
- expect(header().prop('onPreviousClick')).toBe(component.instance().selectPreviousYear);
61
- });
62
-
63
- it('passes selectNextYear header component', () => {
64
- expect(header().prop('onNextClick')).toBe(component.instance().selectNextYear);
65
- });
66
-
67
- it('passes dateMode header component', () => {
68
- expect(header().prop('dateMode')).toBeDefined();
69
- });
70
-
71
- it('calls onViewDateUpdate on previous year select', () => {
72
- component.instance().selectPreviousYear();
73
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 2017 });
74
- });
75
-
76
- it('calls onViewDateUpdate on next year select', () => {
77
- component.instance().selectNextYear();
78
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 2019 });
79
- });
80
-
81
- it('shows month calendar table', () => {
82
- expect(table()).toHaveLength(1);
83
- });
84
-
85
- it('passes props forward to table component', () => {
86
- expect(table().prop('selectedDate')).toBe(selectedDate);
87
- expect(table().prop('min')).toBe(min);
88
- expect(table().prop('max')).toBe(max);
89
- expect(table().prop('viewYear')).toBe(2018);
90
- expect(table().prop('placeholder')).toBe('Enter date..');
91
- });
92
-
93
- it('passes onMonthSelect to table component', () => {
94
- expect(table().prop('onSelect')).toBe(component.instance().onMonthSelect);
95
- });
96
-
97
- it('calls onViewDateUpdate and onSelect on month select', () => {
98
- component.instance().onMonthSelect(1);
99
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ month: 1 });
100
- expect(props.onSelect).toHaveBeenCalledTimes(1);
101
- });
102
-
103
- const header = () => component.find(DateHeader);
104
- const table = () => component.find(MonthCalendarTable);
105
- });
@@ -1,120 +0,0 @@
1
- import * as formatting from '@transferwise/formatting';
2
- import { shallow } from 'enzyme';
3
- import { useIntl } from 'react-intl';
4
-
5
- import MonthCalendarTable from '.';
6
-
7
- jest.mock('react-intl');
8
- jest.mock('@transferwise/formatting', () => ({
9
- formatDate: jest.fn().mockReturnValue('MonthName'),
10
- }));
11
-
12
- describe('MonthCalendarTable', () => {
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(<MonthCalendarTable {...props} />);
25
- });
26
-
27
- it('generates 3x4 table', () => {
28
- expect(component.find('tbody tr')).toHaveLength(3);
29
- expect(component.find('tbody td')).toHaveLength(12);
30
- expect(getTableLink()).toHaveLength(12);
31
- });
32
-
33
- it('starts with month 0 and end with 11', () => {
34
- expect(getTableLinkAt(0).prop('item')).toBe(0);
35
- expect(getTableLinkAt(11).prop('item')).toBe(11);
36
- });
37
-
38
- it('passes month value and type to TableLink', () => {
39
- expect(getTableLinkAt(0).prop('item')).toBe(0);
40
- expect(getTableLinkAt(0).prop('type')).toBe('month');
41
- });
42
-
43
- it('shows formatted months', () => {
44
- expect(getTableLinkAt(0).prop('title')).toBe('MonthName');
45
- expect(formatting.formatDate).toHaveBeenCalledWith(new Date(2018, 0), locale, {
46
- month: 'short',
47
- });
48
- });
49
-
50
- it('show selectedDate as active', () => {
51
- component.setProps({ selectedDate: new Date(2018, 11, 27) });
52
- expect(getTableLinkAt(10).prop('active')).toBe(false);
53
- expect(getTableLinkAt(11).prop('active')).toBe(true);
54
- });
55
-
56
- it('disables dates outside of min and max range', () => {
57
- component.setProps({
58
- selectedDate: new Date(2018, 6, 1),
59
- min: new Date(2018, 6, 1),
60
- max: new Date(2018, 7, 31),
61
- });
62
- expect(getTableLinkAt(5).prop('disabled')).toBe(true);
63
- expect(getTableLinkAt(6).prop('disabled')).toBe(false);
64
- expect(getTableLinkAt(7).prop('disabled')).toBe(false);
65
- expect(getTableLinkAt(8).prop('disabled')).toBe(true);
66
- });
67
-
68
- it('highlights today', () => {
69
- const today = new Date();
70
- component.setProps({
71
- selectedDate: today,
72
- viewYear: today.getFullYear(),
73
- });
74
- expect(getTableLink().find({ today: true }).prop('item')).toBe(today.getMonth());
75
- });
76
-
77
- it('passes onSelect to TableLink', () => {
78
- expect(getTableLinkAt(0).prop('onClick')).toBe(props.onSelect);
79
- });
80
-
81
- it('shows placeholder for screen-readers', () => {
82
- expect(component.find('.sr-only').text()).toBe('Enter date..');
83
- });
84
-
85
- it('sets autofocus to true when June is the selected month', () => {
86
- component.setProps({ selectedDate: new Date(2018, 5, 1) });
87
- expect(getTableLinkAt(5).prop('autofocus')).toBe(true);
88
- });
89
-
90
- it('does not set autofocus to true when June is the selected month but not the right year', () => {
91
- component.setProps({ selectedDate: new Date(2017, 5, 1) });
92
- expect(getTableLinkAt(5).prop('autofocus')).toBe(false);
93
- });
94
-
95
- it('sets autofocus to true when selected date is null and current month is visible', () => {
96
- const today = new Date();
97
- component.setProps({
98
- selectedDate: null,
99
- viewYear: today.getFullYear(),
100
- viewMonth: today.getMonth(),
101
- });
102
- expect(getTableLink().find({ today: true }).prop('autofocus')).toBe(true);
103
- });
104
-
105
- it('sets autofocus to true on the second month when the first month is disabled', () => {
106
- component.setProps({
107
- selectedDate: null,
108
- viewYear: 2022,
109
- min: new Date(2022, 1, 28),
110
- viewMonth: 0,
111
- isDisabled: (month) => month === 0,
112
- });
113
-
114
- expect(getTableLinkAt(0).prop('autofocus')).toBe(false);
115
- expect(getTableLinkAt(1).prop('autofocus')).toBe(true);
116
- });
117
-
118
- const getTableLinkAt = (i) => component.find('[title="MonthName"]').at(i);
119
- const getTableLink = () => component.find('[title="MonthName"]');
120
- });
@@ -1,109 +0,0 @@
1
- import { shallow } from 'enzyme';
2
- import { useIntl } from 'react-intl';
3
-
4
- import TableLink from '.';
5
-
6
- jest.mock('react-intl');
7
-
8
- jest.mock('../DateLookup.messages', () => ({
9
- selected: {
10
- id: 'neptune.DateLookup.selected',
11
- defaultMessage: 'selected',
12
- },
13
- day: {
14
- id: 'neptune.DateLookup.day',
15
- defaultMessage: 'day',
16
- },
17
- month: {
18
- id: 'neptune.DateLookup.month',
19
- defaultMessage: 'month',
20
- },
21
- year: {
22
- id: 'neptune.DateLookup.year',
23
- defaultMessage: 'year',
24
- },
25
- }));
26
-
27
- describe('TableLink', () => {
28
- let component;
29
- let props;
30
-
31
- beforeEach(() => {
32
- useIntl.mockReturnValue({
33
- formatMessage: (message) => message.defaultMessage,
34
- });
35
- props = {
36
- item: 12,
37
- type: 'day',
38
- active: false,
39
- disabled: false,
40
- today: false,
41
- onClick: jest.fn(),
42
- title: '12',
43
- longTitle: '12/12/1212',
44
- };
45
- component = shallow(<TableLink {...props} />);
46
- });
47
-
48
- it('shows item value', () => {
49
- expect(button().text()).toBe('12');
50
- });
51
-
52
- it('shows title when provided (instead of item value)', () => {
53
- component.setProps({ title: 'five' });
54
- expect(button().text()).toBe('five');
55
- });
56
-
57
- it('disables the link', () => {
58
- component.setProps({ disabled: true });
59
- expect(button().prop('disabled')).toBe(true);
60
- expect(props.onClick).not.toHaveBeenCalled();
61
- button().simulate('click', { preventDefault: () => {} });
62
- expect(props.onClick).not.toHaveBeenCalled();
63
- });
64
-
65
- it('highlights active link', () => {
66
- expect(button().hasClass('active')).toBe(false);
67
- component.setProps({ active: true });
68
- expect(button().hasClass('active')).toBe(true);
69
- });
70
-
71
- it('highlights today', () => {
72
- expect(button().hasClass('today')).toBe(false);
73
- component.setProps({ today: true });
74
- expect(button().hasClass('today')).toBe(true);
75
- });
76
-
77
- it('calls click handler on click', () => {
78
- button().simulate('click', { preventDefault: () => {} });
79
- expect(props.onClick).toHaveBeenCalledWith(12);
80
- });
81
-
82
- it('adds aria label to selected day', () => {
83
- expect(button().hasClass('active')).toBe(false);
84
- component.setProps({ active: true });
85
- expect(button().prop('aria-label')).toBe('12/12/1212, selected day');
86
- });
87
-
88
- it('adds aria pressed to selected day', () => {
89
- expect(button().hasClass('active')).toBe(false);
90
- component.setProps({ active: true });
91
- expect(button().prop('aria-pressed')).toBe(true);
92
- });
93
-
94
- it('adds aria label to selected month', () => {
95
- component.setProps({ type: 'month' });
96
- expect(button().hasClass('active')).toBe(false);
97
- component.setProps({ active: true });
98
- expect(button().prop('aria-label')).toBe('12/12/1212, selected month');
99
- });
100
-
101
- it('adds aria label to selected year', () => {
102
- component.setProps({ type: 'year' });
103
- expect(button().hasClass('active')).toBe(false);
104
- component.setProps({ active: true });
105
- expect(button().prop('aria-label')).toBe('12/12/1212, selected year');
106
- });
107
-
108
- const button = () => component.find('button');
109
- });
@@ -1,88 +0,0 @@
1
- import { shallow } from 'enzyme';
2
-
3
- import DateHeader from '../dateHeader';
4
-
5
- import YearCalendarTable from './table';
6
-
7
- import YearCalendar from '.';
8
-
9
- const formatMessage = (id) => `${id}`;
10
- jest.mock('react-intl', () => ({
11
- injectIntl: (Component) =>
12
- function (props) {
13
- return <Component {...props} intl={{ formatMessage }} />;
14
- },
15
- defineMessages: (translations) => translations,
16
- }));
17
-
18
- describe('YearCalendar', () => {
19
- const selectedDate = new Date(2018, 11, 27);
20
- const min = new Date(1990, 11, 27);
21
- const max = new Date(2020, 11, 27);
22
- let component;
23
- let props;
24
-
25
- beforeEach(() => {
26
- props = {
27
- selectedDate,
28
- min,
29
- max,
30
- viewYear: 2018,
31
- placeholder: 'Enter date..',
32
- onSelect: jest.fn(),
33
- onViewDateUpdate: jest.fn(),
34
- };
35
- component = shallow(<YearCalendar {...props} />).dive();
36
- });
37
-
38
- it('shows the header', () => {
39
- expect(header()).toHaveLength(1);
40
- });
41
-
42
- it('passes selectPreviousYears to header component', () => {
43
- expect(header().prop('onPreviousClick')).toBe(component.instance().selectPreviousYears);
44
- });
45
-
46
- it('passes selectNextYears header component', () => {
47
- expect(header().prop('onNextClick')).toBe(component.instance().selectNextYears);
48
- });
49
-
50
- it('passes dateMode header component', () => {
51
- expect(header().prop('dateMode')).toBeDefined();
52
- });
53
-
54
- it('calls onViewDateUpdate on previous years select', () => {
55
- component.instance().selectPreviousYears();
56
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 1998 });
57
- });
58
-
59
- it('calls onViewDateUpdate on next years select', () => {
60
- component.instance().selectNextYears();
61
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 2038 });
62
- });
63
-
64
- it('shows year calendar table', () => {
65
- expect(table()).toHaveLength(1);
66
- });
67
-
68
- it('passes props forward to table component', () => {
69
- expect(table().prop('selectedDate')).toBe(selectedDate);
70
- expect(table().prop('min')).toBe(min);
71
- expect(table().prop('max')).toBe(max);
72
- expect(table().prop('viewYear')).toBe(2018);
73
- expect(table().prop('placeholder')).toBe('Enter date..');
74
- });
75
-
76
- it('passes onYearSelect to table component', () => {
77
- expect(table().prop('onSelect')).toBe(component.instance().onYearSelect);
78
- });
79
-
80
- it('calls onViewDateUpdate and onSelect on year select', () => {
81
- component.instance().onYearSelect(1990);
82
- expect(props.onViewDateUpdate).toHaveBeenCalledWith({ year: 1990 });
83
- expect(props.onSelect).toHaveBeenCalledTimes(1);
84
- });
85
-
86
- const header = () => component.find(DateHeader);
87
- const table = () => component.find(YearCalendarTable);
88
- });