@hero-design/rn 8.92.1-alpha.0 → 8.92.1-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.
package/es/index.js CHANGED
@@ -13205,13 +13205,7 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
13205
13205
  startDate = _ref2.startDate,
13206
13206
  endDate = _ref2.endDate;
13207
13207
  // If both dates are set, selecting start or end date will set the same date
13208
- if (startDate && endDate && isEqDate(date, startDate)) {
13209
- return {
13210
- startDate: date,
13211
- endDate: date
13212
- };
13213
- }
13214
- if (startDate && endDate && isEqDate(date, endDate)) {
13208
+ if (startDate && endDate && (isEqDate(date, startDate) || isEqDate(date, endDate))) {
13215
13209
  return {
13216
13210
  startDate: date,
13217
13211
  endDate: date
package/lib/index.js CHANGED
@@ -13233,13 +13233,7 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
13233
13233
  startDate = _ref2.startDate,
13234
13234
  endDate = _ref2.endDate;
13235
13235
  // If both dates are set, selecting start or end date will set the same date
13236
- if (startDate && endDate && isEqDate(date, startDate)) {
13237
- return {
13238
- startDate: date,
13239
- endDate: date
13240
- };
13241
- }
13242
- if (startDate && endDate && isEqDate(date, endDate)) {
13236
+ if (startDate && endDate && (isEqDate(date, startDate) || isEqDate(date, endDate))) {
13243
13237
  return {
13244
13238
  startDate: date,
13245
13239
  endDate: date
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.92.1-alpha.0",
3
+ "version": "8.92.1-alpha.2",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -47,17 +47,32 @@ describe('CalendarRange', () => {
47
47
  expect(queryAllByTestId('calendar-disabled-cell')).toHaveLength(0);
48
48
  expect(queryAllByTestId('calendar-date-mark')).toHaveLength(5);
49
49
 
50
- // Test range selection
51
- fireEvent.press(queryAllByText('11')[0]); // Select start date
50
+ // Select outside range
51
+ fireEvent.press(queryAllByText('11')[0]);
52
52
  expect(onChange).toHaveBeenCalledWith({
53
53
  startDate: new Date('2022-10-11'),
54
- endDate: new Date('2022-10-15'),
54
+ endDate: undefined,
55
55
  });
56
56
 
57
- fireEvent.press(queryAllByText('20')[0]); // Select end date
57
+ // Select start date
58
+ fireEvent.press(queryAllByText('12')[0]);
58
59
  expect(onChange).toHaveBeenCalledWith({
59
60
  startDate: new Date('2022-10-12'),
60
- endDate: new Date('2022-10-20'),
61
+ endDate: new Date('2022-10-12'),
62
+ });
63
+
64
+ // Select end date
65
+ fireEvent.press(queryAllByText('15')[0]);
66
+ expect(onChange).toHaveBeenCalledWith({
67
+ startDate: new Date('2022-10-15'),
68
+ endDate: new Date('2022-10-15'),
69
+ });
70
+
71
+ // Select inside range
72
+ fireEvent.press(queryAllByText('13')[0]);
73
+ expect(onChange).toHaveBeenCalledWith({
74
+ startDate: new Date('2022-10-13'),
75
+ endDate: undefined,
61
76
  });
62
77
 
63
78
  fireEvent.press(queryByTestId('previous-icon-button'));
@@ -129,14 +144,14 @@ describe('CalendarRange', () => {
129
144
  // Test range selection within constraints
130
145
  fireEvent.press(getByText('17')); // Select start date
131
146
  expect(onChange).toHaveBeenCalledWith({
132
- startDate: new Date('2022-10-12'),
133
- endDate: new Date('2022-10-17'),
147
+ startDate: new Date('2022-10-17'),
148
+ endDate: undefined,
134
149
  });
135
150
 
136
151
  fireEvent.press(getByText('11')); // Select end date
137
152
  expect(onChange).toHaveBeenCalledWith({
138
153
  startDate: new Date('2022-10-11'),
139
- endDate: new Date('2022-10-15'),
154
+ endDate: undefined,
140
155
  });
141
156
  });
142
157
 
@@ -156,14 +171,14 @@ describe('CalendarRange', () => {
156
171
  fireEvent.press(getByText('11'));
157
172
  expect(onChange).toHaveBeenCalledWith({
158
173
  startDate: new Date('2022-10-11'),
159
- endDate: new Date('2022-10-15'),
174
+ endDate: undefined,
160
175
  });
161
176
 
162
177
  // Select end date
163
178
  fireEvent.press(getByText('20'));
164
179
  expect(onChange).toHaveBeenCalledWith({
165
- startDate: new Date('2022-10-12'),
166
- endDate: new Date('2022-10-20'),
180
+ startDate: new Date('2022-10-20'),
181
+ endDate: undefined,
167
182
  });
168
183
 
169
184
  // Select new start date (should clear end date)
@@ -73,99 +73,106 @@ describe('isDateInRange', () => {
73
73
  });
74
74
 
75
75
  describe('setStartOrEndDate', () => {
76
- // Test case 1: Prevent selecting same date when both dates are set
77
- it('should not change dates when selecting same date as start date and both dates are set', () => {
78
- const date = new Date('2024-03-15');
79
- const startDate = new Date('2024-03-15');
80
- const endDate = new Date('2024-03-20');
81
-
82
- const result = setStartOrEndDate({ date, startDate, endDate });
83
- expect(result).toEqual({ startDate, endDate });
76
+ const today = new Date('2024-01-01');
77
+ const tomorrow = new Date('2024-01-02');
78
+ const nextWeek = new Date('2024-01-08');
79
+
80
+ it('should set start date when no dates are selected', () => {
81
+ const result = setStartOrEndDate({
82
+ date: today,
83
+ });
84
+
85
+ expect(result).toEqual({
86
+ startDate: today,
87
+ endDate: undefined,
88
+ });
84
89
  });
85
90
 
86
- // Test case 2: Allow selecting same date as start date when only start date is set
87
- it('should allow selecting same date as start date when only start date is set', () => {
88
- const date = new Date('2024-03-15');
89
- const startDate = new Date('2024-03-15');
91
+ it('should set end date when only start date is selected', () => {
92
+ const result = setStartOrEndDate({
93
+ date: tomorrow,
94
+ startDate: today,
95
+ });
90
96
 
91
- const result = setStartOrEndDate({ date, startDate });
92
97
  expect(result).toEqual({
93
- startDate: new Date('2024-03-15'),
94
- endDate: new Date('2024-03-15'),
98
+ startDate: today,
99
+ endDate: tomorrow,
95
100
  });
96
101
  });
97
102
 
98
- // Test case 3: Initial selection (no start date)
99
- it('should set start date when no dates are selected', () => {
100
- const date = new Date('2024-03-15');
103
+ it('should set start date when date is before current start date', () => {
104
+ const result = setStartOrEndDate({
105
+ date: today,
106
+ startDate: tomorrow,
107
+ });
101
108
 
102
- const result = setStartOrEndDate({ date });
103
109
  expect(result).toEqual({
104
- startDate: new Date('2024-03-15'),
105
- endDate: undefined,
110
+ startDate: today,
111
+ endDate: tomorrow,
106
112
  });
107
113
  });
108
114
 
109
- // Test case 4: Setting end date after start date
110
- it('should set end date when start date exists and selected date is after', () => {
111
- const date = new Date('2024-03-20');
112
- const startDate = new Date('2024-03-15');
115
+ it('should set end date when date is after current start date', () => {
116
+ const result = setStartOrEndDate({
117
+ date: tomorrow,
118
+ startDate: today,
119
+ });
113
120
 
114
- const result = setStartOrEndDate({ date, startDate });
115
121
  expect(result).toEqual({
116
- startDate: new Date('2024-03-15'),
117
- endDate: new Date('2024-03-20'),
122
+ startDate: today,
123
+ endDate: tomorrow,
118
124
  });
119
125
  });
120
126
 
121
- // Test case 5: Setting end date before start date (should reorder)
122
- it('should reorder dates when end date is selected before start date', () => {
123
- const date = new Date('2024-03-10');
124
- const startDate = new Date('2024-03-15');
127
+ it('should reset selection when clicking within range', () => {
128
+ const result = setStartOrEndDate({
129
+ date: tomorrow,
130
+ startDate: today,
131
+ endDate: nextWeek,
132
+ });
125
133
 
126
- const result = setStartOrEndDate({ date, startDate });
127
134
  expect(result).toEqual({
128
- startDate: new Date('2024-03-10'),
129
- endDate: new Date('2024-03-15'),
135
+ startDate: tomorrow,
136
+ endDate: undefined,
130
137
  });
131
138
  });
132
139
 
133
- // Test case 6: Clicking within existing range
134
- it('should start new selection when clicking within existing range', () => {
135
- const date = new Date('2024-03-17');
136
- const startDate = new Date('2024-03-15');
137
- const endDate = new Date('2024-03-20');
140
+ it('should reset selection when clicking outside range', () => {
141
+ const result = setStartOrEndDate({
142
+ date: nextWeek,
143
+ startDate: today,
144
+ endDate: tomorrow,
145
+ });
138
146
 
139
- const result = setStartOrEndDate({ date, startDate, endDate });
140
147
  expect(result).toEqual({
141
- startDate: new Date('2024-03-17'),
148
+ startDate: nextWeek,
142
149
  endDate: undefined,
143
150
  });
144
151
  });
145
152
 
146
- // Test case 7: Extending range before start date
147
- it('should extend range when clicking before start date', () => {
148
- const date = new Date('2024-03-10');
149
- const startDate = new Date('2024-03-15');
150
- const endDate = new Date('2024-03-20');
153
+ it('should set same date for both start and end when clicking start date', () => {
154
+ const result = setStartOrEndDate({
155
+ date: today,
156
+ startDate: today,
157
+ endDate: tomorrow,
158
+ });
151
159
 
152
- const result = setStartOrEndDate({ date, startDate, endDate });
153
160
  expect(result).toEqual({
154
- startDate: new Date('2024-03-10'),
155
- endDate: new Date('2024-03-20'),
161
+ startDate: today,
162
+ endDate: today,
156
163
  });
157
164
  });
158
165
 
159
- // Test case 8: Extending range after end date
160
- it('should extend range when clicking after end date', () => {
161
- const date = new Date('2024-03-25');
162
- const startDate = new Date('2024-03-15');
163
- const endDate = new Date('2024-03-20');
166
+ it('should set same date for both start and end when clicking end date', () => {
167
+ const result = setStartOrEndDate({
168
+ date: tomorrow,
169
+ startDate: today,
170
+ endDate: tomorrow,
171
+ });
164
172
 
165
- const result = setStartOrEndDate({ date, startDate, endDate });
166
173
  expect(result).toEqual({
167
- startDate: new Date('2024-03-15'),
168
- endDate: new Date('2024-03-25'),
174
+ startDate: tomorrow,
175
+ endDate: tomorrow,
169
176
  });
170
177
  });
171
178
  });
@@ -55,14 +55,11 @@ export const setStartOrEndDate = ({
55
55
  endDate?: Date;
56
56
  }) => {
57
57
  // If both dates are set, selecting start or end date will set the same date
58
- if (startDate && endDate && isEqDate(date, startDate)) {
59
- return {
60
- startDate: date,
61
- endDate: date,
62
- };
63
- }
64
-
65
- if (startDate && endDate && isEqDate(date, endDate)) {
58
+ if (
59
+ startDate &&
60
+ endDate &&
61
+ (isEqDate(date, startDate) || isEqDate(date, endDate))
62
+ ) {
66
63
  return {
67
64
  startDate: date,
68
65
  endDate: date,