@getmicdrop/svelte-components 2.0.4 → 2.0.6
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/dist/components/Alert/Alert.spec.js +170 -170
- package/dist/components/Badges/Badge.spec.js +103 -103
- package/dist/components/BottomSheet/BottomSheet.spec.js +127 -127
- package/dist/components/Breadcrumb/Breadcrumb.spec.js +120 -120
- package/dist/components/Button/Button.spec.js +211 -211
- package/dist/components/Button/ButtonSaveDemo.spec.js +48 -48
- package/dist/components/Calendar/Calendar.spec.js +131 -131
- package/dist/components/Calendar/QuarterView.spec.js +394 -394
- package/dist/components/Card.spec.js +47 -47
- package/dist/components/CropImage/CropImage.spec.js +216 -216
- package/dist/components/DarkModeToggle.spec.js +357 -357
- package/dist/components/ErrorDisplay.spec.js +69 -69
- package/dist/components/FormActions.spec.js +88 -88
- package/dist/components/FormValidationSummary.spec.js +203 -203
- package/dist/components/Icons/Icon.spec.js +175 -175
- package/dist/components/Icons/MoreHori.spec.js +67 -67
- package/dist/components/Icons/WarningIcon.spec.js +30 -30
- package/dist/components/Input/Input.spec.js +573 -573
- package/dist/components/Input/MultiSelect.spec.js +257 -257
- package/dist/components/Input/OTPInput.spec.js +238 -238
- package/dist/components/Input/Select.spec.js +218 -218
- package/dist/components/Layout/BottomNav.spec.js +130 -130
- package/dist/components/Layout/Header.spec.js +203 -203
- package/dist/components/Modal/ConfirmationModal.spec.js +191 -191
- package/dist/components/Modal/Modal.spec.js +95 -95
- package/dist/components/Modal/ModalStateManager.spec.js +100 -100
- package/dist/components/PageLoader.spec.js +54 -54
- package/dist/components/PasswordStrengthIndicator/PasswordStrengthIndicator.spec.js +173 -173
- package/dist/components/PlaceAutocomplete/PlaceAutocomplete.spec.js +300 -300
- package/dist/components/Spinner/Spinner.spec.js +75 -75
- package/dist/components/StatusIndicator/StatusIndicator.spec.js +129 -129
- package/dist/components/Toaster/Toaster.stories.svelte +1 -1
- package/dist/components/Toggle.spec.js +158 -158
- package/dist/components/ValidationError.spec.js +79 -79
- package/dist/components/pages/performers/AvailabilityCalendarModal.spec.js +606 -606
- package/dist/components/pages/performers/AvailabilityCalendarModal.svelte +4 -4
- package/dist/components/pages/performers/ModalShowInfo.spec.js +124 -124
- package/dist/components/pages/performers/ModalShowInfo.svelte +1 -1
- package/dist/components/pages/performers/PageBackButton.spec.js +89 -89
- package/dist/components/pages/performers/SectionHeader.spec.js +75 -75
- package/dist/components/pages/performers/ShowDetails.spec.js +166 -166
- package/dist/components/pages/performers/ShowItemCard.spec.js +793 -793
- package/dist/components/pages/performers/ShowItemCard.svelte +4 -4
- package/dist/components/pages/performers/SwitchOption.spec.js +127 -127
- package/dist/components/pages/performers/VenueInfo.spec.js +167 -167
- package/dist/components/pages/performers/VenueInfo.svelte +1 -1
- package/dist/components/pages/performers/VenueItemCard.spec.js +763 -763
- package/dist/components/pages/performers/VenueItemCard.svelte +4 -4
- package/dist/components/pages/profile/profile-form.spec.js +9 -9
- package/dist/components/pages/settings/tabs/CustomImageDropzone.svelte +3 -3
- package/dist/components/pages/shows/ShowList.spec.js +33 -33
- package/dist/components/pages/shows/TabContent.spec.js +90 -90
- package/dist/components/pages/shows/TabNavigation.spec.js +143 -143
- package/dist/config.js +5 -5
- package/dist/config.spec.js +29 -29
- package/dist/constants/formOptions.js +25 -25
- package/dist/constants/formOptions.spec.js +88 -88
- package/dist/index.js +111 -111
- package/dist/stores/auth.d.ts +9 -0
- package/dist/stores/auth.d.ts.map +1 -0
- package/dist/stores/auth.js +36 -0
- package/dist/stores/auth.spec.d.ts +2 -0
- package/dist/stores/auth.spec.d.ts.map +1 -0
- package/dist/stores/auth.spec.js +139 -0
- package/dist/stores/formDataStore.d.ts +17 -0
- package/dist/stores/formDataStore.d.ts.map +1 -0
- package/dist/stores/formDataStore.js +25 -0
- package/dist/stores/formDataStore.spec.d.ts +2 -0
- package/dist/stores/formDataStore.spec.d.ts.map +1 -0
- package/dist/stores/formDataStore.spec.js +257 -0
- package/dist/stores/formSave.d.ts +24 -0
- package/dist/stores/formSave.d.ts.map +1 -0
- package/dist/stores/formSave.js +132 -0
- package/dist/stores/formSave.spec.d.ts +2 -0
- package/dist/stores/formSave.spec.d.ts.map +1 -0
- package/dist/stores/formSave.spec.js +296 -0
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/index.js +0 -0
- package/dist/stores/navigation.d.ts +5 -0
- package/dist/stores/navigation.d.ts.map +1 -0
- package/dist/stores/navigation.js +12 -0
- package/dist/stores/navigation.spec.d.ts +2 -0
- package/dist/stores/navigation.spec.d.ts.map +1 -0
- package/dist/stores/navigation.spec.js +136 -0
- package/dist/stores/toaster.d.ts +4 -0
- package/dist/stores/toaster.d.ts.map +1 -0
- package/dist/stores/toaster.js +13 -0
- package/dist/stores/toaster.spec.d.ts +2 -0
- package/dist/stores/toaster.spec.d.ts.map +1 -0
- package/dist/stores/toaster.spec.js +59 -0
- package/dist/telemetry.js +357 -357
- package/dist/telemetry.server.js +211 -211
- package/dist/telemetry.server.spec.js +434 -434
- package/dist/telemetry.spec.js +660 -660
- package/dist/utils/apiConfig.js +49 -49
- package/dist/utils/apiConfig.spec.js +118 -118
- package/dist/utils/greetings.js +187 -187
- package/dist/utils/greetings.spec.js +337 -337
- package/dist/utils/imageValidation.js +121 -121
- package/dist/utils/imageValidation.spec.js +220 -220
- package/dist/utils/portal.js +25 -25
- package/dist/utils/portal.spec.js +143 -143
- package/dist/utils/utils/utils.js +323 -323
- package/dist/utils/utils/utils.spec.js +698 -698
- package/dist/utils/utils.spec.js +643 -643
- package/package.json +1 -1
|
@@ -1,394 +1,394 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { render, fireEvent } from '@testing-library/svelte';
|
|
3
|
-
import { writable, get } from 'svelte/store';
|
|
4
|
-
import QuarterView from './QuarterView.svelte';
|
|
5
|
-
|
|
6
|
-
// Mock date-fns functions
|
|
7
|
-
vi.mock('date-fns', () => ({
|
|
8
|
-
getDay: vi.fn((date) => date.getDay()),
|
|
9
|
-
getDaysInMonth: vi.fn((date) => {
|
|
10
|
-
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
11
|
-
}),
|
|
12
|
-
startOfMonth: vi.fn((date) => new Date(date.getFullYear(), date.getMonth(), 1)),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
describe('QuarterView Component', () => {
|
|
16
|
-
let selectedDates;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
vi.useFakeTimers();
|
|
20
|
-
vi.setSystemTime(new Date(2024, 5, 15)); // June 15, 2024
|
|
21
|
-
|
|
22
|
-
selectedDates = writable([]);
|
|
23
|
-
|
|
24
|
-
// Mock navigator.vibrate for haptic feedback tests
|
|
25
|
-
Object.defineProperty(navigator, 'vibrate', {
|
|
26
|
-
value: vi.fn(),
|
|
27
|
-
writable: true,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
vi.useRealTimers();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('renders calendar container', () => {
|
|
36
|
-
const { container } = render(QuarterView, {
|
|
37
|
-
props: {
|
|
38
|
-
currentevents: [],
|
|
39
|
-
selectedDates,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
const calendarContainer = container.querySelector('.calendar-container');
|
|
43
|
-
expect(calendarContainer).toBeTruthy();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('renders day headers', () => {
|
|
47
|
-
const { getByText } = render(QuarterView, {
|
|
48
|
-
props: {
|
|
49
|
-
currentevents: [],
|
|
50
|
-
selectedDates,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
expect(getByText('Sun')).toBeTruthy();
|
|
54
|
-
expect(getByText('Mon')).toBeTruthy();
|
|
55
|
-
expect(getByText('Tue')).toBeTruthy();
|
|
56
|
-
expect(getByText('Wed')).toBeTruthy();
|
|
57
|
-
expect(getByText('Thu')).toBeTruthy();
|
|
58
|
-
expect(getByText('Fri')).toBeTruthy();
|
|
59
|
-
expect(getByText('Sat')).toBeTruthy();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('renders current month name', () => {
|
|
63
|
-
const { getByText } = render(QuarterView, {
|
|
64
|
-
props: {
|
|
65
|
-
currentevents: [],
|
|
66
|
-
selectedDates,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
expect(getByText('June')).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('renders current year', () => {
|
|
73
|
-
const { getByText } = render(QuarterView, {
|
|
74
|
-
props: {
|
|
75
|
-
currentevents: [],
|
|
76
|
-
selectedDates,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
expect(getByText('2024')).toBeTruthy();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('renders navigation buttons', () => {
|
|
83
|
-
const { container } = render(QuarterView, {
|
|
84
|
-
props: {
|
|
85
|
-
currentevents: [],
|
|
86
|
-
selectedDates,
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
const navButtons = container.querySelectorAll('.nav-btn');
|
|
90
|
-
expect(navButtons.length).toBe(2);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('renders Today button', () => {
|
|
94
|
-
const { getByText } = render(QuarterView, {
|
|
95
|
-
props: {
|
|
96
|
-
currentevents: [],
|
|
97
|
-
selectedDates,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
expect(getByText('Today')).toBeTruthy();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('renders day cells', () => {
|
|
104
|
-
const { container } = render(QuarterView, {
|
|
105
|
-
props: {
|
|
106
|
-
currentevents: [],
|
|
107
|
-
selectedDates,
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
const dayCells = container.querySelectorAll('.day-cell');
|
|
111
|
-
// June 2024 has 30 days
|
|
112
|
-
expect(dayCells.length).toBe(30);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('previous button has aria-label', () => {
|
|
116
|
-
const { container } = render(QuarterView, {
|
|
117
|
-
props: {
|
|
118
|
-
currentevents: [],
|
|
119
|
-
selectedDates,
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
const prevButton = container.querySelector('[aria-label="Previous month"]');
|
|
123
|
-
expect(prevButton).toBeTruthy();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('next button has aria-label', () => {
|
|
127
|
-
const { container } = render(QuarterView, {
|
|
128
|
-
props: {
|
|
129
|
-
currentevents: [],
|
|
130
|
-
selectedDates,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
const nextButton = container.querySelector('[aria-label="Next month"]');
|
|
134
|
-
expect(nextButton).toBeTruthy();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('clicking next navigates to next month', async () => {
|
|
138
|
-
const { container, getByText } = render(QuarterView, {
|
|
139
|
-
props: {
|
|
140
|
-
currentevents: [],
|
|
141
|
-
selectedDates,
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const nextButton = container.querySelector('[aria-label="Next month"]');
|
|
146
|
-
await fireEvent.click(nextButton);
|
|
147
|
-
|
|
148
|
-
vi.advanceTimersByTime(300);
|
|
149
|
-
|
|
150
|
-
expect(getByText('July')).toBeTruthy();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('clicking previous navigates to previous month', async () => {
|
|
154
|
-
const { container, getByText } = render(QuarterView, {
|
|
155
|
-
props: {
|
|
156
|
-
currentevents: [],
|
|
157
|
-
selectedDates,
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const prevButton = container.querySelector('[aria-label="Previous month"]');
|
|
162
|
-
await fireEvent.click(prevButton);
|
|
163
|
-
|
|
164
|
-
vi.advanceTimersByTime(300);
|
|
165
|
-
|
|
166
|
-
expect(getByText('May')).toBeTruthy();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('shows save status when provided', () => {
|
|
170
|
-
const { container } = render(QuarterView, {
|
|
171
|
-
props: {
|
|
172
|
-
currentevents: [],
|
|
173
|
-
selectedDates,
|
|
174
|
-
saveStatus: 'saving',
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
const saveIndicator = container.querySelector('.save-indicator-overlay');
|
|
178
|
-
expect(saveIndicator).toBeTruthy();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('shows saved indicator', () => {
|
|
182
|
-
const { container } = render(QuarterView, {
|
|
183
|
-
props: {
|
|
184
|
-
currentevents: [],
|
|
185
|
-
selectedDates,
|
|
186
|
-
saveStatus: 'saved',
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
const saveIndicator = container.querySelector('.save-indicator-overlay');
|
|
190
|
-
expect(saveIndicator).toBeTruthy();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('disables non-event days', () => {
|
|
194
|
-
const { container } = render(QuarterView, {
|
|
195
|
-
props: {
|
|
196
|
-
currentevents: [],
|
|
197
|
-
selectedDates,
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
const disabledCells = container.querySelectorAll('.day-cell.disabled');
|
|
201
|
-
// All days should be disabled when no events
|
|
202
|
-
expect(disabledCells.length).toBe(30);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('enables event days', () => {
|
|
206
|
-
const { container } = render(QuarterView, {
|
|
207
|
-
props: {
|
|
208
|
-
currentevents: [{ date: '2024-06-20' }],
|
|
209
|
-
selectedDates,
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
const dayCells = container.querySelectorAll('.day-cell');
|
|
214
|
-
// Find the cell for day 20
|
|
215
|
-
const day20Cell = Array.from(dayCells).find(
|
|
216
|
-
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
// Day 20 (future event) should not be disabled
|
|
220
|
-
expect(day20Cell.classList.contains('disabled')).toBe(false);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('marks selected dates', async () => {
|
|
224
|
-
selectedDates.set(['2024-06-20']);
|
|
225
|
-
|
|
226
|
-
const { container } = render(QuarterView, {
|
|
227
|
-
props: {
|
|
228
|
-
currentevents: [{ date: '2024-06-20' }],
|
|
229
|
-
selectedDates,
|
|
230
|
-
},
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const dayCells = container.querySelectorAll('.day-cell');
|
|
234
|
-
const day20Cell = Array.from(dayCells).find(
|
|
235
|
-
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
expect(day20Cell.classList.contains('selected')).toBe(true);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('toggles date selection on click', async () => {
|
|
242
|
-
const { container } = render(QuarterView, {
|
|
243
|
-
props: {
|
|
244
|
-
currentevents: [{ date: '2024-06-20' }],
|
|
245
|
-
selectedDates,
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
const dayCells = container.querySelectorAll('.day-cell');
|
|
250
|
-
const day20Cell = Array.from(dayCells).find(
|
|
251
|
-
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
await fireEvent.click(day20Cell);
|
|
255
|
-
|
|
256
|
-
// Check that selectedDates store was updated
|
|
257
|
-
const dates = get(selectedDates);
|
|
258
|
-
expect(dates).toContain('2024-06-20');
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('removes date from selection on second click', async () => {
|
|
262
|
-
selectedDates.set(['2024-06-20']);
|
|
263
|
-
|
|
264
|
-
const { container } = render(QuarterView, {
|
|
265
|
-
props: {
|
|
266
|
-
currentevents: [{ date: '2024-06-20' }],
|
|
267
|
-
selectedDates,
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
const dayCells = container.querySelectorAll('.day-cell');
|
|
272
|
-
const day20Cell = Array.from(dayCells).find(
|
|
273
|
-
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
await fireEvent.click(day20Cell);
|
|
277
|
-
|
|
278
|
-
const dates = get(selectedDates);
|
|
279
|
-
expect(dates).not.toContain('2024-06-20');
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it('has aria-pressed attribute on day buttons', () => {
|
|
283
|
-
const { container } = render(QuarterView, {
|
|
284
|
-
props: {
|
|
285
|
-
currentevents: [],
|
|
286
|
-
selectedDates,
|
|
287
|
-
},
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
const dayCell = container.querySelector('.day-cell');
|
|
291
|
-
expect(dayCell.hasAttribute('aria-pressed')).toBe(true);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('has aria-label for day buttons', () => {
|
|
295
|
-
const { container } = render(QuarterView, {
|
|
296
|
-
props: {
|
|
297
|
-
currentevents: [],
|
|
298
|
-
selectedDates,
|
|
299
|
-
},
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
const dayCell = container.querySelector('.day-cell');
|
|
303
|
-
expect(dayCell.getAttribute('aria-label')).toMatch(/Day \d+/);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('handles touch swipe events', async () => {
|
|
307
|
-
const { container } = render(QuarterView, {
|
|
308
|
-
props: {
|
|
309
|
-
currentevents: [],
|
|
310
|
-
selectedDates,
|
|
311
|
-
},
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
const grid = container.querySelector('.calendar-grid');
|
|
315
|
-
|
|
316
|
-
// Simulate touch swipe
|
|
317
|
-
await fireEvent.touchStart(grid, {
|
|
318
|
-
touches: [{ clientX: 200, clientY: 100 }],
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
await fireEvent.touchMove(grid, {
|
|
322
|
-
touches: [{ clientX: 100, clientY: 100 }],
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
await fireEvent.touchEnd(grid, {
|
|
326
|
-
changedTouches: [{ clientX: 50, clientY: 100 }],
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
vi.advanceTimersByTime(300);
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it('calls haptic feedback via vibration API', async () => {
|
|
333
|
-
const { container } = render(QuarterView, {
|
|
334
|
-
props: {
|
|
335
|
-
currentevents: [{ date: '2024-06-20' }],
|
|
336
|
-
selectedDates,
|
|
337
|
-
},
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
const dayCells = container.querySelectorAll('.day-cell');
|
|
341
|
-
const day20Cell = Array.from(dayCells).find(
|
|
342
|
-
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
await fireEvent.click(day20Cell);
|
|
346
|
-
|
|
347
|
-
// vibrate should have been called
|
|
348
|
-
expect(navigator.vibrate).toHaveBeenCalled();
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
it('navigates months correctly across year boundary (December to January)', async () => {
|
|
352
|
-
vi.setSystemTime(new Date(2024, 11, 15)); // December 15, 2024
|
|
353
|
-
|
|
354
|
-
const { container, getByText } = render(QuarterView, {
|
|
355
|
-
props: {
|
|
356
|
-
currentevents: [],
|
|
357
|
-
selectedDates,
|
|
358
|
-
},
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
expect(getByText('December')).toBeTruthy();
|
|
362
|
-
expect(getByText('2024')).toBeTruthy();
|
|
363
|
-
|
|
364
|
-
const nextButton = container.querySelector('[aria-label="Next month"]');
|
|
365
|
-
await fireEvent.click(nextButton);
|
|
366
|
-
|
|
367
|
-
vi.advanceTimersByTime(300);
|
|
368
|
-
|
|
369
|
-
expect(getByText('January')).toBeTruthy();
|
|
370
|
-
expect(getByText('2025')).toBeTruthy();
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it('navigates months correctly across year boundary (January to December)', async () => {
|
|
374
|
-
vi.setSystemTime(new Date(2024, 0, 15)); // January 15, 2024
|
|
375
|
-
|
|
376
|
-
const { container, getByText } = render(QuarterView, {
|
|
377
|
-
props: {
|
|
378
|
-
currentevents: [],
|
|
379
|
-
selectedDates,
|
|
380
|
-
},
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
expect(getByText('January')).toBeTruthy();
|
|
384
|
-
expect(getByText('2024')).toBeTruthy();
|
|
385
|
-
|
|
386
|
-
const prevButton = container.querySelector('[aria-label="Previous month"]');
|
|
387
|
-
await fireEvent.click(prevButton);
|
|
388
|
-
|
|
389
|
-
vi.advanceTimersByTime(300);
|
|
390
|
-
|
|
391
|
-
expect(getByText('December')).toBeTruthy();
|
|
392
|
-
expect(getByText('2023')).toBeTruthy();
|
|
393
|
-
});
|
|
394
|
-
});
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/svelte';
|
|
3
|
+
import { writable, get } from 'svelte/store';
|
|
4
|
+
import QuarterView from './QuarterView.svelte';
|
|
5
|
+
|
|
6
|
+
// Mock date-fns functions
|
|
7
|
+
vi.mock('date-fns', () => ({
|
|
8
|
+
getDay: vi.fn((date) => date.getDay()),
|
|
9
|
+
getDaysInMonth: vi.fn((date) => {
|
|
10
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
11
|
+
}),
|
|
12
|
+
startOfMonth: vi.fn((date) => new Date(date.getFullYear(), date.getMonth(), 1)),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
describe('QuarterView Component', () => {
|
|
16
|
+
let selectedDates;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.useFakeTimers();
|
|
20
|
+
vi.setSystemTime(new Date(2024, 5, 15)); // June 15, 2024
|
|
21
|
+
|
|
22
|
+
selectedDates = writable([]);
|
|
23
|
+
|
|
24
|
+
// Mock navigator.vibrate for haptic feedback tests
|
|
25
|
+
Object.defineProperty(navigator, 'vibrate', {
|
|
26
|
+
value: vi.fn(),
|
|
27
|
+
writable: true,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
vi.useRealTimers();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('renders calendar container', () => {
|
|
36
|
+
const { container } = render(QuarterView, {
|
|
37
|
+
props: {
|
|
38
|
+
currentevents: [],
|
|
39
|
+
selectedDates,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const calendarContainer = container.querySelector('.calendar-container');
|
|
43
|
+
expect(calendarContainer).toBeTruthy();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('renders day headers', () => {
|
|
47
|
+
const { getByText } = render(QuarterView, {
|
|
48
|
+
props: {
|
|
49
|
+
currentevents: [],
|
|
50
|
+
selectedDates,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
expect(getByText('Sun')).toBeTruthy();
|
|
54
|
+
expect(getByText('Mon')).toBeTruthy();
|
|
55
|
+
expect(getByText('Tue')).toBeTruthy();
|
|
56
|
+
expect(getByText('Wed')).toBeTruthy();
|
|
57
|
+
expect(getByText('Thu')).toBeTruthy();
|
|
58
|
+
expect(getByText('Fri')).toBeTruthy();
|
|
59
|
+
expect(getByText('Sat')).toBeTruthy();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders current month name', () => {
|
|
63
|
+
const { getByText } = render(QuarterView, {
|
|
64
|
+
props: {
|
|
65
|
+
currentevents: [],
|
|
66
|
+
selectedDates,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
expect(getByText('June')).toBeTruthy();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('renders current year', () => {
|
|
73
|
+
const { getByText } = render(QuarterView, {
|
|
74
|
+
props: {
|
|
75
|
+
currentevents: [],
|
|
76
|
+
selectedDates,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
expect(getByText('2024')).toBeTruthy();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('renders navigation buttons', () => {
|
|
83
|
+
const { container } = render(QuarterView, {
|
|
84
|
+
props: {
|
|
85
|
+
currentevents: [],
|
|
86
|
+
selectedDates,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const navButtons = container.querySelectorAll('.nav-btn');
|
|
90
|
+
expect(navButtons.length).toBe(2);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('renders Today button', () => {
|
|
94
|
+
const { getByText } = render(QuarterView, {
|
|
95
|
+
props: {
|
|
96
|
+
currentevents: [],
|
|
97
|
+
selectedDates,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
expect(getByText('Today')).toBeTruthy();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('renders day cells', () => {
|
|
104
|
+
const { container } = render(QuarterView, {
|
|
105
|
+
props: {
|
|
106
|
+
currentevents: [],
|
|
107
|
+
selectedDates,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
const dayCells = container.querySelectorAll('.day-cell');
|
|
111
|
+
// June 2024 has 30 days
|
|
112
|
+
expect(dayCells.length).toBe(30);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('previous button has aria-label', () => {
|
|
116
|
+
const { container } = render(QuarterView, {
|
|
117
|
+
props: {
|
|
118
|
+
currentevents: [],
|
|
119
|
+
selectedDates,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
const prevButton = container.querySelector('[aria-label="Previous month"]');
|
|
123
|
+
expect(prevButton).toBeTruthy();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('next button has aria-label', () => {
|
|
127
|
+
const { container } = render(QuarterView, {
|
|
128
|
+
props: {
|
|
129
|
+
currentevents: [],
|
|
130
|
+
selectedDates,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
const nextButton = container.querySelector('[aria-label="Next month"]');
|
|
134
|
+
expect(nextButton).toBeTruthy();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('clicking next navigates to next month', async () => {
|
|
138
|
+
const { container, getByText } = render(QuarterView, {
|
|
139
|
+
props: {
|
|
140
|
+
currentevents: [],
|
|
141
|
+
selectedDates,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const nextButton = container.querySelector('[aria-label="Next month"]');
|
|
146
|
+
await fireEvent.click(nextButton);
|
|
147
|
+
|
|
148
|
+
vi.advanceTimersByTime(300);
|
|
149
|
+
|
|
150
|
+
expect(getByText('July')).toBeTruthy();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('clicking previous navigates to previous month', async () => {
|
|
154
|
+
const { container, getByText } = render(QuarterView, {
|
|
155
|
+
props: {
|
|
156
|
+
currentevents: [],
|
|
157
|
+
selectedDates,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const prevButton = container.querySelector('[aria-label="Previous month"]');
|
|
162
|
+
await fireEvent.click(prevButton);
|
|
163
|
+
|
|
164
|
+
vi.advanceTimersByTime(300);
|
|
165
|
+
|
|
166
|
+
expect(getByText('May')).toBeTruthy();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('shows save status when provided', () => {
|
|
170
|
+
const { container } = render(QuarterView, {
|
|
171
|
+
props: {
|
|
172
|
+
currentevents: [],
|
|
173
|
+
selectedDates,
|
|
174
|
+
saveStatus: 'saving',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
const saveIndicator = container.querySelector('.save-indicator-overlay');
|
|
178
|
+
expect(saveIndicator).toBeTruthy();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('shows saved indicator', () => {
|
|
182
|
+
const { container } = render(QuarterView, {
|
|
183
|
+
props: {
|
|
184
|
+
currentevents: [],
|
|
185
|
+
selectedDates,
|
|
186
|
+
saveStatus: 'saved',
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
const saveIndicator = container.querySelector('.save-indicator-overlay');
|
|
190
|
+
expect(saveIndicator).toBeTruthy();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('disables non-event days', () => {
|
|
194
|
+
const { container } = render(QuarterView, {
|
|
195
|
+
props: {
|
|
196
|
+
currentevents: [],
|
|
197
|
+
selectedDates,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
const disabledCells = container.querySelectorAll('.day-cell.disabled');
|
|
201
|
+
// All days should be disabled when no events
|
|
202
|
+
expect(disabledCells.length).toBe(30);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('enables event days', () => {
|
|
206
|
+
const { container } = render(QuarterView, {
|
|
207
|
+
props: {
|
|
208
|
+
currentevents: [{ date: '2024-06-20' }],
|
|
209
|
+
selectedDates,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const dayCells = container.querySelectorAll('.day-cell');
|
|
214
|
+
// Find the cell for day 20
|
|
215
|
+
const day20Cell = Array.from(dayCells).find(
|
|
216
|
+
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// Day 20 (future event) should not be disabled
|
|
220
|
+
expect(day20Cell.classList.contains('disabled')).toBe(false);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('marks selected dates', async () => {
|
|
224
|
+
selectedDates.set(['2024-06-20']);
|
|
225
|
+
|
|
226
|
+
const { container } = render(QuarterView, {
|
|
227
|
+
props: {
|
|
228
|
+
currentevents: [{ date: '2024-06-20' }],
|
|
229
|
+
selectedDates,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const dayCells = container.querySelectorAll('.day-cell');
|
|
234
|
+
const day20Cell = Array.from(dayCells).find(
|
|
235
|
+
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
expect(day20Cell.classList.contains('selected')).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('toggles date selection on click', async () => {
|
|
242
|
+
const { container } = render(QuarterView, {
|
|
243
|
+
props: {
|
|
244
|
+
currentevents: [{ date: '2024-06-20' }],
|
|
245
|
+
selectedDates,
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const dayCells = container.querySelectorAll('.day-cell');
|
|
250
|
+
const day20Cell = Array.from(dayCells).find(
|
|
251
|
+
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
await fireEvent.click(day20Cell);
|
|
255
|
+
|
|
256
|
+
// Check that selectedDates store was updated
|
|
257
|
+
const dates = get(selectedDates);
|
|
258
|
+
expect(dates).toContain('2024-06-20');
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('removes date from selection on second click', async () => {
|
|
262
|
+
selectedDates.set(['2024-06-20']);
|
|
263
|
+
|
|
264
|
+
const { container } = render(QuarterView, {
|
|
265
|
+
props: {
|
|
266
|
+
currentevents: [{ date: '2024-06-20' }],
|
|
267
|
+
selectedDates,
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const dayCells = container.querySelectorAll('.day-cell');
|
|
272
|
+
const day20Cell = Array.from(dayCells).find(
|
|
273
|
+
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
await fireEvent.click(day20Cell);
|
|
277
|
+
|
|
278
|
+
const dates = get(selectedDates);
|
|
279
|
+
expect(dates).not.toContain('2024-06-20');
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('has aria-pressed attribute on day buttons', () => {
|
|
283
|
+
const { container } = render(QuarterView, {
|
|
284
|
+
props: {
|
|
285
|
+
currentevents: [],
|
|
286
|
+
selectedDates,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const dayCell = container.querySelector('.day-cell');
|
|
291
|
+
expect(dayCell.hasAttribute('aria-pressed')).toBe(true);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('has aria-label for day buttons', () => {
|
|
295
|
+
const { container } = render(QuarterView, {
|
|
296
|
+
props: {
|
|
297
|
+
currentevents: [],
|
|
298
|
+
selectedDates,
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const dayCell = container.querySelector('.day-cell');
|
|
303
|
+
expect(dayCell.getAttribute('aria-label')).toMatch(/Day \d+/);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('handles touch swipe events', async () => {
|
|
307
|
+
const { container } = render(QuarterView, {
|
|
308
|
+
props: {
|
|
309
|
+
currentevents: [],
|
|
310
|
+
selectedDates,
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const grid = container.querySelector('.calendar-grid');
|
|
315
|
+
|
|
316
|
+
// Simulate touch swipe
|
|
317
|
+
await fireEvent.touchStart(grid, {
|
|
318
|
+
touches: [{ clientX: 200, clientY: 100 }],
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
await fireEvent.touchMove(grid, {
|
|
322
|
+
touches: [{ clientX: 100, clientY: 100 }],
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
await fireEvent.touchEnd(grid, {
|
|
326
|
+
changedTouches: [{ clientX: 50, clientY: 100 }],
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
vi.advanceTimersByTime(300);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('calls haptic feedback via vibration API', async () => {
|
|
333
|
+
const { container } = render(QuarterView, {
|
|
334
|
+
props: {
|
|
335
|
+
currentevents: [{ date: '2024-06-20' }],
|
|
336
|
+
selectedDates,
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const dayCells = container.querySelectorAll('.day-cell');
|
|
341
|
+
const day20Cell = Array.from(dayCells).find(
|
|
342
|
+
(cell) => cell.querySelector('.day-number')?.textContent === '20'
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
await fireEvent.click(day20Cell);
|
|
346
|
+
|
|
347
|
+
// vibrate should have been called
|
|
348
|
+
expect(navigator.vibrate).toHaveBeenCalled();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('navigates months correctly across year boundary (December to January)', async () => {
|
|
352
|
+
vi.setSystemTime(new Date(2024, 11, 15)); // December 15, 2024
|
|
353
|
+
|
|
354
|
+
const { container, getByText } = render(QuarterView, {
|
|
355
|
+
props: {
|
|
356
|
+
currentevents: [],
|
|
357
|
+
selectedDates,
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
expect(getByText('December')).toBeTruthy();
|
|
362
|
+
expect(getByText('2024')).toBeTruthy();
|
|
363
|
+
|
|
364
|
+
const nextButton = container.querySelector('[aria-label="Next month"]');
|
|
365
|
+
await fireEvent.click(nextButton);
|
|
366
|
+
|
|
367
|
+
vi.advanceTimersByTime(300);
|
|
368
|
+
|
|
369
|
+
expect(getByText('January')).toBeTruthy();
|
|
370
|
+
expect(getByText('2025')).toBeTruthy();
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('navigates months correctly across year boundary (January to December)', async () => {
|
|
374
|
+
vi.setSystemTime(new Date(2024, 0, 15)); // January 15, 2024
|
|
375
|
+
|
|
376
|
+
const { container, getByText } = render(QuarterView, {
|
|
377
|
+
props: {
|
|
378
|
+
currentevents: [],
|
|
379
|
+
selectedDates,
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
expect(getByText('January')).toBeTruthy();
|
|
384
|
+
expect(getByText('2024')).toBeTruthy();
|
|
385
|
+
|
|
386
|
+
const prevButton = container.querySelector('[aria-label="Previous month"]');
|
|
387
|
+
await fireEvent.click(prevButton);
|
|
388
|
+
|
|
389
|
+
vi.advanceTimersByTime(300);
|
|
390
|
+
|
|
391
|
+
expect(getByText('December')).toBeTruthy();
|
|
392
|
+
expect(getByText('2023')).toBeTruthy();
|
|
393
|
+
});
|
|
394
|
+
});
|