@hero-design/rn 8.89.0-alpha.0 → 8.89.0-alpha.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.
Files changed (49) hide show
  1. package/es/index.js +1452 -1077
  2. package/lib/index.js +1453 -1078
  3. package/package.json +2 -3
  4. package/src/components/Calendar/CalendarRange.tsx +337 -0
  5. package/src/components/Calendar/CalendarRangeConnector.tsx +68 -0
  6. package/src/components/Calendar/CalendarRowItem.tsx +14 -3
  7. package/src/components/Calendar/StyledCalendar.tsx +23 -9
  8. package/src/components/Calendar/__tests__/CalendarRange.spec.tsx +284 -0
  9. package/src/components/Calendar/__tests__/CalendarRangeConnector.spec.tsx +73 -0
  10. package/src/components/Calendar/__tests__/__snapshots__/CalendarRangeConnector.spec.tsx.snap +632 -0
  11. package/src/components/Calendar/__tests__/__snapshots__/CalendarRowItem.spec.tsx.snap +45 -20
  12. package/src/components/Calendar/__tests__/helper.spec.ts +110 -1
  13. package/src/components/Calendar/helpers.ts +75 -0
  14. package/src/components/Calendar/index.tsx +19 -15
  15. package/src/components/RichTextEditor/RichTextEditor.tsx +14 -20
  16. package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +2 -4
  17. package/src/index.ts +2 -2
  18. package/src/theme/ThemeSwitcher.tsx +5 -1
  19. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +9 -4
  20. package/src/theme/components/calendar.ts +6 -1
  21. package/src/theme/global/colors/ehWorkDark.ts +7 -8
  22. package/src/theme/global/index.ts +2 -2
  23. package/src/theme/index.ts +2 -2
  24. package/src/types.ts +2 -0
  25. package/stats/8.88.0/rn-stats.html +0 -2
  26. package/types/components/Calendar/CalendarRowItem.d.ts +3 -1
  27. package/types/components/Calendar/StyledCalendar.d.ts +2 -1
  28. package/types/components/Calendar/helpers.d.ts +15 -0
  29. package/types/components/Calendar/index.d.ts +4 -2
  30. package/types/index.d.ts +2 -2
  31. package/types/theme/ThemeSwitcher.d.ts +1 -1
  32. package/types/theme/components/calendar.d.ts +5 -0
  33. package/types/theme/global/colors/ehWorkDark.d.ts +5 -4
  34. package/types/theme/global/index.d.ts +2 -2
  35. package/types/theme/index.d.ts +2 -2
  36. package/types/types.d.ts +2 -1
  37. package/types/components/Calendar/CalendarRangeSelectedItem.d.ts +0 -11
  38. package/types/components/Calendar/Sample.d.ts +0 -13
  39. package/types/components/Calendar/hooks/useCalendarLayout.d.ts +0 -7
  40. package/types/components/Calendar/useSetUpCalendar.d.ts +0 -0
  41. package/types/components/CompoundSearch/CompoundSearchHandler.d.ts +0 -31
  42. package/types/components/CompoundSearch/CompoundSearchTextInput.d.ts +0 -60
  43. package/types/components/CompoundSearch/StyledCompoundSearch.d.ts +0 -40
  44. package/types/components/CompoundSearch/index.d.ts +0 -8
  45. package/types/components/CompoundSearch/utils.d.ts +0 -8
  46. package/types/components/FloatingIsland/SingleLine/StyledSingleLine.d.ts +0 -15
  47. package/types/components/FloatingIsland/SingleLine/index.d.ts +0 -24
  48. package/types/test-utils.d.ts +0 -4
  49. package/types/theme/components/compoundSearch.d.ts +0 -36
@@ -0,0 +1,284 @@
1
+ import { fireEvent } from '@testing-library/react-native';
2
+ import React from 'react';
3
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
4
+ import CalendarRange from '../CalendarRange';
5
+ import { theme } from '../../..';
6
+
7
+ Date.now = jest.fn(() => new Date(2022, 10, 2).valueOf());
8
+
9
+ describe('CalendarRange', () => {
10
+ it('renders correctly', () => {
11
+ const onChange = jest.fn();
12
+ const onTitlePress = jest.fn();
13
+ const onPreviousPress = jest.fn();
14
+ const onNextPress = jest.fn();
15
+ const { getByText, queryAllByTestId, queryByTestId, queryAllByText } =
16
+ renderWithTheme(
17
+ <CalendarRange
18
+ value={{
19
+ startDate: new Date('2022-10-12'),
20
+ endDate: new Date('2022-10-15'),
21
+ }}
22
+ visibleDate={new Date('2022-10-12')}
23
+ onChange={onChange}
24
+ onTitlePress={onTitlePress}
25
+ onPreviousPress={onPreviousPress}
26
+ onNextPress={onNextPress}
27
+ markedDates={[
28
+ new Date('2022-10-11'),
29
+ new Date('2022-10-12'),
30
+ new Date('2022-10-13'),
31
+ new Date('2022-10-14'),
32
+ new Date('2022-10-15'),
33
+ ]}
34
+ />
35
+ );
36
+
37
+ expect(getByText('October 2022')).toBeTruthy();
38
+ expect(getByText('Mo')).toBeTruthy();
39
+ expect(getByText('Tu')).toBeTruthy();
40
+ expect(getByText('We')).toBeTruthy();
41
+ expect(getByText('Th')).toBeTruthy();
42
+ expect(getByText('Fr')).toBeTruthy();
43
+ expect(getByText('Sa')).toBeTruthy();
44
+ expect(getByText('Su')).toBeTruthy();
45
+
46
+ expect(queryAllByTestId('calendar-date-cell')).toHaveLength(42);
47
+ expect(queryAllByTestId('calendar-disabled-cell')).toHaveLength(0);
48
+ expect(queryAllByTestId('calendar-date-mark')).toHaveLength(5);
49
+
50
+ // Test range selection
51
+ fireEvent.press(queryAllByText('11')[0]); // Select start date
52
+ expect(onChange).toHaveBeenCalledWith({
53
+ startDate: new Date('2022-10-11'),
54
+ endDate: new Date('2022-10-15'),
55
+ });
56
+
57
+ fireEvent.press(queryAllByText('20')[0]); // Select end date
58
+ expect(onChange).toHaveBeenCalledWith({
59
+ startDate: new Date('2022-10-12'),
60
+ endDate: new Date('2022-10-20'),
61
+ });
62
+
63
+ fireEvent.press(queryByTestId('previous-icon-button'));
64
+ expect(onPreviousPress).toBeCalled();
65
+
66
+ fireEvent.press(queryByTestId('next-icon-button'));
67
+ expect(onNextPress).toBeCalled();
68
+
69
+ fireEvent.press(getByText('October 2022'));
70
+ expect(onTitlePress).toBeCalled();
71
+ });
72
+
73
+ it('renders correctly with minDate and maxDate', () => {
74
+ const onChange = jest.fn();
75
+ const onTitlePress = jest.fn();
76
+ const onPreviousPress = jest.fn();
77
+ const onNextPress = jest.fn();
78
+ const { getByText, queryByText, queryAllByTestId, queryByTestId } =
79
+ renderWithTheme(
80
+ <CalendarRange
81
+ value={{
82
+ startDate: new Date('2022-10-12'),
83
+ endDate: new Date('2022-10-15'),
84
+ }}
85
+ visibleDate={new Date('2022-10-12')}
86
+ onChange={onChange}
87
+ onTitlePress={onTitlePress}
88
+ onPreviousPress={onPreviousPress}
89
+ onNextPress={onNextPress}
90
+ minDate={new Date('2022-10-10')}
91
+ maxDate={new Date('2022-10-20')}
92
+ />
93
+ );
94
+ const startDateCell = queryAllByTestId('selected-date-cell')[0]; // 12
95
+ expect(startDateCell).toHaveStyle({
96
+ backgroundColor: theme.colors.primary,
97
+ });
98
+
99
+ const firstHighlightedCell = queryAllByTestId('calendar-date-cell')[3]; // 13
100
+ expect(firstHighlightedCell).toHaveStyle({
101
+ backgroundColor: theme.colors.highlightedSurface,
102
+ });
103
+
104
+ const secondHighlightedCell = queryAllByTestId('calendar-date-cell')[4]; // 14
105
+ expect(secondHighlightedCell).toHaveStyle({
106
+ backgroundColor: theme.colors.highlightedSurface,
107
+ });
108
+
109
+ const endDateCell = queryAllByTestId('selected-date-cell')[1]; // 15
110
+ expect(endDateCell).toHaveStyle({
111
+ backgroundColor: theme.colors.primary,
112
+ });
113
+
114
+ expect(queryAllByTestId('calendar-date-cell')).toHaveLength(11);
115
+ expect(queryAllByTestId('calendar-disabled-cell')).toHaveLength(31);
116
+
117
+ expect(queryByText('2')).toBeNull();
118
+ expect(queryByText('28')).toBeNull();
119
+
120
+ fireEvent.press(queryByTestId('previous-icon-button'));
121
+ expect(onPreviousPress).not.toBeCalled();
122
+
123
+ fireEvent.press(queryByTestId('next-icon-button'));
124
+ expect(onNextPress).not.toBeCalled();
125
+
126
+ fireEvent.press(queryAllByTestId('calendar-disabled-cell')[0]);
127
+ expect(onChange).not.toBeCalled();
128
+
129
+ // Test range selection within constraints
130
+ fireEvent.press(getByText('17')); // Select start date
131
+ expect(onChange).toHaveBeenCalledWith({
132
+ startDate: new Date('2022-10-12'),
133
+ endDate: new Date('2022-10-17'),
134
+ });
135
+
136
+ fireEvent.press(getByText('11')); // Select end date
137
+ expect(onChange).toHaveBeenCalledWith({
138
+ startDate: new Date('2022-10-11'),
139
+ endDate: new Date('2022-10-15'),
140
+ });
141
+ });
142
+
143
+ it('handles range selection correctly', () => {
144
+ const onChange = jest.fn();
145
+ const { getByText } = renderWithTheme(
146
+ <CalendarRange
147
+ value={{
148
+ startDate: new Date('2022-10-12'),
149
+ endDate: new Date('2022-10-15'),
150
+ }}
151
+ visibleDate={new Date('2022-10-12')}
152
+ onChange={onChange}
153
+ />
154
+ );
155
+ // Select start date
156
+ fireEvent.press(getByText('11'));
157
+ expect(onChange).toHaveBeenCalledWith({
158
+ startDate: new Date('2022-10-11'),
159
+ endDate: new Date('2022-10-15'),
160
+ });
161
+
162
+ // Select end date
163
+ fireEvent.press(getByText('20'));
164
+ expect(onChange).toHaveBeenCalledWith({
165
+ startDate: new Date('2022-10-12'),
166
+ endDate: new Date('2022-10-20'),
167
+ });
168
+
169
+ // Select new start date (should clear end date)
170
+ fireEvent.press(getByText('13'));
171
+ expect(onChange).toHaveBeenCalledWith({
172
+ startDate: new Date('2022-10-13'),
173
+ endDate: undefined,
174
+ });
175
+ });
176
+
177
+ it('disables onTitlePress when onMonthChange is passed', () => {
178
+ const onTitlePress = jest.fn();
179
+ const { getByTestId } = renderWithTheme(
180
+ <CalendarRange
181
+ visibleDate={new Date(2022, 10, 5)}
182
+ onTitlePress={onTitlePress}
183
+ minDate={new Date(2022, 10, 3)}
184
+ maxDate={new Date(2022, 10, 27)}
185
+ onMonthChange={jest.fn()}
186
+ />
187
+ );
188
+
189
+ fireEvent.press(getByTestId('calendar-month-picker'));
190
+ expect(onTitlePress).toHaveBeenCalledTimes(0);
191
+ });
192
+
193
+ it.each`
194
+ platform
195
+ ${'ios'}
196
+ ${'android'}
197
+ `('renders correct picker on $platform', ({ platform: mockedPlatform }) => {
198
+ jest.mock('react-native/Libraries/Utilities/Platform', () => ({
199
+ OS: mockedPlatform,
200
+ select: () => null,
201
+ }));
202
+
203
+ const { getByTestId, queryByText } = renderWithTheme(
204
+ <CalendarRange
205
+ visibleDate={new Date(2022, 10, 5)}
206
+ minDate={new Date(2022, 10, 3)}
207
+ maxDate={new Date(2022, 10, 27)}
208
+ onMonthChange={jest.fn()}
209
+ />
210
+ );
211
+
212
+ fireEvent.press(getByTestId('calendar-month-picker'));
213
+
214
+ // Pickers are mocked at packages/rn/testUtils/setup.tsx
215
+ if (mockedPlatform === 'ios') {
216
+ expect(queryByText('IOS picker')).toBeDefined();
217
+ } else {
218
+ expect(queryByText('Android picker')).toBeDefined();
219
+ }
220
+ });
221
+
222
+ it.each`
223
+ platform
224
+ ${'ios'}
225
+ ${'android'}
226
+ `(
227
+ 'onToggleMonthPicker is called when toggling month year picker on $platform',
228
+ ({ platform: mockedPlatform }) => {
229
+ jest.mock('react-native/Libraries/Utilities/Platform', () => ({
230
+ OS: mockedPlatform,
231
+ select: () => null,
232
+ }));
233
+
234
+ const onToggleMonthPicker = jest.fn();
235
+ const { getByTestId } = renderWithTheme(
236
+ <CalendarRange
237
+ visibleDate={new Date(2022, 10, 5)}
238
+ minDate={new Date(2022, 10, 3)}
239
+ maxDate={new Date(2022, 10, 27)}
240
+ onMonthChange={jest.fn()}
241
+ onToggleMonthPicker={onToggleMonthPicker}
242
+ />
243
+ );
244
+
245
+ fireEvent.press(getByTestId('calendar-month-picker'));
246
+ expect(onToggleMonthPicker).toHaveBeenCalled();
247
+ }
248
+ );
249
+
250
+ it('shows marked dates correctly', () => {
251
+ const markedDates = [
252
+ new Date(2022, 10, 5),
253
+ new Date(2022, 10, 6),
254
+ new Date(2022, 10, 7),
255
+ ];
256
+
257
+ const { queryAllByTestId } = renderWithTheme(
258
+ <CalendarRange
259
+ visibleDate={new Date(2022, 10, 5)}
260
+ markedDates={markedDates}
261
+ />
262
+ );
263
+
264
+ expect(queryAllByTestId('calendar-date-mark')).toHaveLength(3);
265
+ });
266
+
267
+ it('highlights dates in range', () => {
268
+ const { getAllByTestId } = renderWithTheme(
269
+ <CalendarRange
270
+ value={{
271
+ startDate: new Date(2022, 10, 5),
272
+ endDate: new Date(2022, 10, 10),
273
+ }}
274
+ visibleDate={new Date(2022, 10, 5)}
275
+ />
276
+ );
277
+
278
+ // Should have highlighted cells between start and end date
279
+ const highlightedCells = getAllByTestId('calendar-date-cell').filter(
280
+ (cell) => cell.props.isHighlighted
281
+ );
282
+ expect(highlightedCells.length).toBeGreaterThan(0);
283
+ });
284
+ });
@@ -0,0 +1,73 @@
1
+ import { fireEvent } from '@testing-library/react-native';
2
+ import React from 'react';
3
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
4
+ import SelectedDate from '../CalendarRangeConnector';
5
+
6
+ describe('CalendarRangeConnector', () => {
7
+ const defaultProps = {
8
+ date: new Date(2022, 10, 10),
9
+ onPress: jest.fn(),
10
+ itemWidth: 120,
11
+ };
12
+
13
+ it('renders correctly with basic props', () => {
14
+ const { toJSON } = renderWithTheme(<SelectedDate {...defaultProps} />);
15
+ expect(toJSON()).toMatchSnapshot();
16
+ });
17
+
18
+ it.each`
19
+ isStart | showConnector
20
+ ${true} | ${true}
21
+ ${false} | ${true}
22
+ ${true} | ${false}
23
+ ${false} | ${false}
24
+ `(
25
+ 'renders correctly with connector variations',
26
+ ({ isStart, showConnector }) => {
27
+ const { toJSON } = renderWithTheme(
28
+ <SelectedDate
29
+ {...defaultProps}
30
+ isStart={isStart}
31
+ showConnector={showConnector}
32
+ />
33
+ );
34
+ expect(toJSON()).toMatchSnapshot();
35
+ }
36
+ );
37
+
38
+ it('renders mark when date is marked', () => {
39
+ const { queryByTestId } = renderWithTheme(
40
+ <SelectedDate {...defaultProps} marked />
41
+ );
42
+ expect(queryByTestId('calendar-date-mark')).toBeTruthy();
43
+ });
44
+
45
+ it('does not render mark when date is not marked', () => {
46
+ const { queryByTestId } = renderWithTheme(
47
+ <SelectedDate {...defaultProps} />
48
+ );
49
+ expect(queryByTestId('calendar-date-mark')).toBeNull();
50
+ });
51
+
52
+ it('does not render connector when showConnector is false', () => {
53
+ const { queryByTestId } = renderWithTheme(
54
+ <SelectedDate {...defaultProps} isStart />
55
+ );
56
+ expect(queryByTestId('range-connector')).toBeNull();
57
+ });
58
+
59
+ it('handles press events', () => {
60
+ const onPress = jest.fn();
61
+ const { getByTestId } = renderWithTheme(
62
+ <SelectedDate {...defaultProps} onPress={onPress} />
63
+ );
64
+
65
+ fireEvent.press(getByTestId('selected-date-cell'));
66
+ expect(onPress).toHaveBeenCalled();
67
+ });
68
+
69
+ it('displays correct date number', () => {
70
+ const { getByText } = renderWithTheme(<SelectedDate {...defaultProps} />);
71
+ expect(getByText('10')).toBeTruthy();
72
+ });
73
+ });