@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.
Files changed (107) hide show
  1. package/dist/components/Alert/Alert.spec.js +170 -170
  2. package/dist/components/Badges/Badge.spec.js +103 -103
  3. package/dist/components/BottomSheet/BottomSheet.spec.js +127 -127
  4. package/dist/components/Breadcrumb/Breadcrumb.spec.js +120 -120
  5. package/dist/components/Button/Button.spec.js +211 -211
  6. package/dist/components/Button/ButtonSaveDemo.spec.js +48 -48
  7. package/dist/components/Calendar/Calendar.spec.js +131 -131
  8. package/dist/components/Calendar/QuarterView.spec.js +394 -394
  9. package/dist/components/Card.spec.js +47 -47
  10. package/dist/components/CropImage/CropImage.spec.js +216 -216
  11. package/dist/components/DarkModeToggle.spec.js +357 -357
  12. package/dist/components/ErrorDisplay.spec.js +69 -69
  13. package/dist/components/FormActions.spec.js +88 -88
  14. package/dist/components/FormValidationSummary.spec.js +203 -203
  15. package/dist/components/Icons/Icon.spec.js +175 -175
  16. package/dist/components/Icons/MoreHori.spec.js +67 -67
  17. package/dist/components/Icons/WarningIcon.spec.js +30 -30
  18. package/dist/components/Input/Input.spec.js +573 -573
  19. package/dist/components/Input/MultiSelect.spec.js +257 -257
  20. package/dist/components/Input/OTPInput.spec.js +238 -238
  21. package/dist/components/Input/Select.spec.js +218 -218
  22. package/dist/components/Layout/BottomNav.spec.js +130 -130
  23. package/dist/components/Layout/Header.spec.js +203 -203
  24. package/dist/components/Modal/ConfirmationModal.spec.js +191 -191
  25. package/dist/components/Modal/Modal.spec.js +95 -95
  26. package/dist/components/Modal/ModalStateManager.spec.js +100 -100
  27. package/dist/components/PageLoader.spec.js +54 -54
  28. package/dist/components/PasswordStrengthIndicator/PasswordStrengthIndicator.spec.js +173 -173
  29. package/dist/components/PlaceAutocomplete/PlaceAutocomplete.spec.js +300 -300
  30. package/dist/components/Spinner/Spinner.spec.js +75 -75
  31. package/dist/components/StatusIndicator/StatusIndicator.spec.js +129 -129
  32. package/dist/components/Toaster/Toaster.stories.svelte +1 -1
  33. package/dist/components/Toggle.spec.js +158 -158
  34. package/dist/components/ValidationError.spec.js +79 -79
  35. package/dist/components/pages/performers/AvailabilityCalendarModal.spec.js +606 -606
  36. package/dist/components/pages/performers/AvailabilityCalendarModal.svelte +4 -4
  37. package/dist/components/pages/performers/ModalShowInfo.spec.js +124 -124
  38. package/dist/components/pages/performers/ModalShowInfo.svelte +1 -1
  39. package/dist/components/pages/performers/PageBackButton.spec.js +89 -89
  40. package/dist/components/pages/performers/SectionHeader.spec.js +75 -75
  41. package/dist/components/pages/performers/ShowDetails.spec.js +166 -166
  42. package/dist/components/pages/performers/ShowItemCard.spec.js +793 -793
  43. package/dist/components/pages/performers/ShowItemCard.svelte +4 -4
  44. package/dist/components/pages/performers/SwitchOption.spec.js +127 -127
  45. package/dist/components/pages/performers/VenueInfo.spec.js +167 -167
  46. package/dist/components/pages/performers/VenueInfo.svelte +1 -1
  47. package/dist/components/pages/performers/VenueItemCard.spec.js +763 -763
  48. package/dist/components/pages/performers/VenueItemCard.svelte +4 -4
  49. package/dist/components/pages/profile/profile-form.spec.js +9 -9
  50. package/dist/components/pages/settings/tabs/CustomImageDropzone.svelte +3 -3
  51. package/dist/components/pages/shows/ShowList.spec.js +33 -33
  52. package/dist/components/pages/shows/TabContent.spec.js +90 -90
  53. package/dist/components/pages/shows/TabNavigation.spec.js +143 -143
  54. package/dist/config.js +5 -5
  55. package/dist/config.spec.js +29 -29
  56. package/dist/constants/formOptions.js +25 -25
  57. package/dist/constants/formOptions.spec.js +88 -88
  58. package/dist/index.js +111 -111
  59. package/dist/stores/auth.d.ts +9 -0
  60. package/dist/stores/auth.d.ts.map +1 -0
  61. package/dist/stores/auth.js +36 -0
  62. package/dist/stores/auth.spec.d.ts +2 -0
  63. package/dist/stores/auth.spec.d.ts.map +1 -0
  64. package/dist/stores/auth.spec.js +139 -0
  65. package/dist/stores/formDataStore.d.ts +17 -0
  66. package/dist/stores/formDataStore.d.ts.map +1 -0
  67. package/dist/stores/formDataStore.js +25 -0
  68. package/dist/stores/formDataStore.spec.d.ts +2 -0
  69. package/dist/stores/formDataStore.spec.d.ts.map +1 -0
  70. package/dist/stores/formDataStore.spec.js +257 -0
  71. package/dist/stores/formSave.d.ts +24 -0
  72. package/dist/stores/formSave.d.ts.map +1 -0
  73. package/dist/stores/formSave.js +132 -0
  74. package/dist/stores/formSave.spec.d.ts +2 -0
  75. package/dist/stores/formSave.spec.d.ts.map +1 -0
  76. package/dist/stores/formSave.spec.js +296 -0
  77. package/dist/stores/index.d.ts +1 -0
  78. package/dist/stores/index.d.ts.map +1 -0
  79. package/dist/stores/index.js +0 -0
  80. package/dist/stores/navigation.d.ts +5 -0
  81. package/dist/stores/navigation.d.ts.map +1 -0
  82. package/dist/stores/navigation.js +12 -0
  83. package/dist/stores/navigation.spec.d.ts +2 -0
  84. package/dist/stores/navigation.spec.d.ts.map +1 -0
  85. package/dist/stores/navigation.spec.js +136 -0
  86. package/dist/stores/toaster.d.ts +4 -0
  87. package/dist/stores/toaster.d.ts.map +1 -0
  88. package/dist/stores/toaster.js +13 -0
  89. package/dist/stores/toaster.spec.d.ts +2 -0
  90. package/dist/stores/toaster.spec.d.ts.map +1 -0
  91. package/dist/stores/toaster.spec.js +59 -0
  92. package/dist/telemetry.js +357 -357
  93. package/dist/telemetry.server.js +211 -211
  94. package/dist/telemetry.server.spec.js +434 -434
  95. package/dist/telemetry.spec.js +660 -660
  96. package/dist/utils/apiConfig.js +49 -49
  97. package/dist/utils/apiConfig.spec.js +118 -118
  98. package/dist/utils/greetings.js +187 -187
  99. package/dist/utils/greetings.spec.js +337 -337
  100. package/dist/utils/imageValidation.js +121 -121
  101. package/dist/utils/imageValidation.spec.js +220 -220
  102. package/dist/utils/portal.js +25 -25
  103. package/dist/utils/portal.spec.js +143 -143
  104. package/dist/utils/utils/utils.js +323 -323
  105. package/dist/utils/utils/utils.spec.js +698 -698
  106. package/dist/utils/utils.spec.js +643 -643
  107. package/package.json +1 -1
@@ -1,337 +1,337 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import { getGreeting, getFirstName, clearGreetingCache } from './greetings';
3
-
4
- describe('greetings', () => {
5
- beforeEach(() => {
6
- // Mock localStorage
7
- const localStorageMock = {
8
- store: {},
9
- getItem: vi.fn((key) => localStorageMock.store[key] || null),
10
- setItem: vi.fn((key, value) => {
11
- localStorageMock.store[key] = value;
12
- }),
13
- removeItem: vi.fn((key) => {
14
- delete localStorageMock.store[key];
15
- }),
16
- clear: vi.fn(() => {
17
- localStorageMock.store = {};
18
- }),
19
- };
20
- Object.defineProperty(window, 'localStorage', {
21
- value: localStorageMock,
22
- writable: true,
23
- });
24
-
25
- // Clear cache before each test
26
- clearGreetingCache();
27
- });
28
-
29
- afterEach(() => {
30
- vi.restoreAllMocks();
31
- });
32
-
33
- describe('getFirstName', () => {
34
- it('returns first name from full name', () => {
35
- expect(getFirstName('John Doe')).toBe('John');
36
- });
37
-
38
- it('handles single name', () => {
39
- expect(getFirstName('John')).toBe('John');
40
- });
41
-
42
- it('handles multiple names', () => {
43
- expect(getFirstName('John Michael Doe')).toBe('John');
44
- });
45
-
46
- it('returns empty string for empty input', () => {
47
- expect(getFirstName('')).toBe('');
48
- });
49
-
50
- it('returns empty string for null', () => {
51
- expect(getFirstName(null)).toBe('');
52
- });
53
-
54
- it('returns empty string for undefined', () => {
55
- expect(getFirstName(undefined)).toBe('');
56
- });
57
- });
58
-
59
- describe('getGreeting', () => {
60
- it('returns a string containing the name', () => {
61
- const greeting = getGreeting('Alex');
62
- expect(greeting).toContain('Alex');
63
- });
64
-
65
- it('returns different greetings for different time periods', () => {
66
- // Run multiple times to increase chance of getting different greetings
67
- const greetings = new Set();
68
- for (let i = 0; i < 20; i++) {
69
- clearGreetingCache();
70
- greetings.add(getGreeting('Test'));
71
- }
72
- // Should have at least one greeting (randomness means we might get the same one)
73
- expect(greetings.size).toBeGreaterThanOrEqual(1);
74
- });
75
-
76
- it('caches greeting in localStorage', () => {
77
- getGreeting('Alex');
78
- expect(window.localStorage.setItem).toHaveBeenCalled();
79
- });
80
-
81
- it('returns cached greeting for same user', () => {
82
- const greeting1 = getGreeting('Alex');
83
- const greeting2 = getGreeting('Alex');
84
- expect(greeting1).toBe(greeting2);
85
- });
86
-
87
- it('generates new greeting for different user', () => {
88
- const greeting1 = getGreeting('Alex');
89
- clearGreetingCache();
90
- const greeting2 = getGreeting('Beth');
91
- expect(greeting2).toContain('Beth');
92
- });
93
-
94
- it('handles localStorage errors gracefully', () => {
95
- window.localStorage.getItem.mockImplementation(() => {
96
- throw new Error('localStorage error');
97
- });
98
-
99
- // Should not throw
100
- expect(() => getGreeting('Alex')).not.toThrow();
101
- const greeting = getGreeting('Alex');
102
- expect(greeting).toContain('Alex');
103
- });
104
-
105
- it('handles invalid cached JSON gracefully', () => {
106
- window.localStorage.getItem.mockReturnValue('invalid json');
107
-
108
- // Should not throw and should generate new greeting
109
- expect(() => getGreeting('Alex')).not.toThrow();
110
- });
111
- });
112
-
113
- describe('clearGreetingCache', () => {
114
- it('removes greeting from localStorage', () => {
115
- getGreeting('Alex');
116
- clearGreetingCache();
117
- expect(window.localStorage.removeItem).toHaveBeenCalledWith('micdrop_greeting');
118
- });
119
-
120
- it('handles localStorage errors gracefully', () => {
121
- window.localStorage.removeItem.mockImplementation(() => {
122
- throw new Error('localStorage error');
123
- });
124
-
125
- // Should not throw
126
- expect(() => clearGreetingCache()).not.toThrow();
127
- });
128
- });
129
-
130
- describe('greeting content', () => {
131
- it('greeting always includes user name', () => {
132
- for (let i = 0; i < 10; i++) {
133
- clearGreetingCache();
134
- const greeting = getGreeting('TestUser');
135
- expect(greeting).toContain('TestUser');
136
- }
137
- });
138
-
139
- it('handles names with special characters', () => {
140
- const greeting = getGreeting("O'Brien");
141
- expect(greeting).toContain("O'Brien");
142
- });
143
-
144
- it('handles names with numbers', () => {
145
- const greeting = getGreeting('User123');
146
- expect(greeting).toContain('User123');
147
- });
148
- });
149
-
150
- describe('localStorage setItem error handling', () => {
151
- it('handles localStorage setItem error gracefully', () => {
152
- window.localStorage.setItem.mockImplementation(() => {
153
- throw new Error('localStorage setItem error');
154
- });
155
-
156
- // Should not throw even when setItem fails
157
- expect(() => getGreeting('Alex')).not.toThrow();
158
- const greeting = getGreeting('Alex');
159
- expect(greeting).toContain('Alex');
160
- });
161
- });
162
-
163
- describe('SSR behavior', () => {
164
- it('works without window (SSR simulation)', () => {
165
- // The module checks typeof window === 'undefined' for SSR
166
- // In JSDOM window exists, but we can test by checking that function works
167
- const greeting = getGreeting('TestUser');
168
- expect(typeof greeting).toBe('string');
169
- expect(greeting).toContain('TestUser');
170
- });
171
- });
172
-
173
- describe('time period coverage', () => {
174
- // Test all time period branches by mocking Date
175
- const RealDate = Date;
176
-
177
- afterEach(() => {
178
- global.Date = RealDate;
179
- });
180
-
181
- it('generates greeting for night period (21-24)', () => {
182
- // Mock Date to return 22:00
183
- global.Date = class extends RealDate {
184
- constructor() {
185
- super();
186
- return new RealDate('2025-06-15T22:00:00');
187
- }
188
- getHours() { return 22; }
189
- getDay() { return 0; }
190
- };
191
-
192
- clearGreetingCache();
193
- const greeting = getGreeting('NightUser');
194
- expect(greeting).toContain('NightUser');
195
- });
196
-
197
- it('generates greeting for late night period (0-5 AM)', () => {
198
- // Mock Date to return 03:00
199
- global.Date = class extends RealDate {
200
- constructor() {
201
- super();
202
- return new RealDate('2025-06-15T03:00:00');
203
- }
204
- getHours() { return 3; }
205
- getDay() { return 0; }
206
- };
207
-
208
- clearGreetingCache();
209
- const greeting = getGreeting('LateNightUser');
210
- expect(greeting).toContain('LateNightUser');
211
- });
212
-
213
- it('generates greeting for early morning period (5-7)', () => {
214
- global.Date = class extends RealDate {
215
- constructor() {
216
- super();
217
- return new RealDate('2025-06-15T06:00:00');
218
- }
219
- getHours() { return 6; }
220
- getDay() { return 1; }
221
- };
222
-
223
- clearGreetingCache();
224
- const greeting = getGreeting('EarlyUser');
225
- expect(greeting).toContain('EarlyUser');
226
- });
227
-
228
- it('generates greeting for morning period (7-12)', () => {
229
- global.Date = class extends RealDate {
230
- constructor() {
231
- super();
232
- return new RealDate('2025-06-15T09:00:00');
233
- }
234
- getHours() { return 9; }
235
- getDay() { return 2; }
236
- };
237
-
238
- clearGreetingCache();
239
- const greeting = getGreeting('MorningUser');
240
- expect(greeting).toContain('MorningUser');
241
- });
242
-
243
- it('generates greeting for afternoon period (12-17)', () => {
244
- global.Date = class extends RealDate {
245
- constructor() {
246
- super();
247
- return new RealDate('2025-06-15T14:00:00');
248
- }
249
- getHours() { return 14; }
250
- getDay() { return 3; }
251
- };
252
-
253
- clearGreetingCache();
254
- const greeting = getGreeting('AfternoonUser');
255
- expect(greeting).toContain('AfternoonUser');
256
- });
257
-
258
- it('generates greeting for evening period (17-21)', () => {
259
- global.Date = class extends RealDate {
260
- constructor() {
261
- super();
262
- return new RealDate('2025-06-15T19:00:00');
263
- }
264
- getHours() { return 19; }
265
- getDay() { return 4; }
266
- };
267
-
268
- clearGreetingCache();
269
- const greeting = getGreeting('EveningUser');
270
- expect(greeting).toContain('EveningUser');
271
- });
272
- });
273
-
274
- describe('time-based greeting generation', () => {
275
- it('generates consistent greeting with cached data for same period and day', () => {
276
- // First call generates and caches
277
- const greeting1 = getGreeting('Alex');
278
-
279
- // Second call should return cached
280
- const greeting2 = getGreeting('Alex');
281
-
282
- expect(greeting1).toBe(greeting2);
283
- });
284
-
285
- it('generates greeting containing name for various scenarios', () => {
286
- // Test with longer names
287
- clearGreetingCache();
288
- const longNameGreeting = getGreeting('AlexanderTheGreat');
289
- expect(longNameGreeting).toContain('AlexanderTheGreat');
290
-
291
- // Test with short names
292
- clearGreetingCache();
293
- const shortNameGreeting = getGreeting('Jo');
294
- expect(shortNameGreeting).toContain('Jo');
295
- });
296
-
297
- it('respects cache when period and day match', () => {
298
- const greeting1 = getGreeting('TestUser');
299
-
300
- // Mock getting a valid cached value
301
- const cachedValue = window.localStorage.store['micdrop_greeting'];
302
- expect(cachedValue).toBeDefined();
303
-
304
- // Parse to verify structure
305
- const parsed = JSON.parse(cachedValue);
306
- expect(parsed).toHaveProperty('greeting');
307
- expect(parsed).toHaveProperty('period');
308
- expect(parsed).toHaveProperty('day');
309
- expect(parsed).toHaveProperty('cachedName');
310
- expect(parsed.cachedName).toBe('TestUser');
311
- });
312
- });
313
-
314
- describe('SSR mode', () => {
315
- it('generates greeting without caching when window is undefined', async () => {
316
- vi.resetModules();
317
-
318
- // Save original window
319
- const originalWindow = global.window;
320
-
321
- // Delete window to simulate SSR
322
- delete global.window;
323
-
324
- // Re-import module in SSR context
325
- const { getGreeting: ssrGetGreeting } = await import('./greetings.js');
326
-
327
- // Should still generate a greeting
328
- const greeting = ssrGetGreeting('TestUser');
329
- expect(greeting).toBeDefined();
330
- expect(typeof greeting).toBe('string');
331
- expect(greeting).toContain('TestUser');
332
-
333
- // Restore window
334
- global.window = originalWindow;
335
- });
336
- });
337
- });
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { getGreeting, getFirstName, clearGreetingCache } from './greetings';
3
+
4
+ describe('greetings', () => {
5
+ beforeEach(() => {
6
+ // Mock localStorage
7
+ const localStorageMock = {
8
+ store: {},
9
+ getItem: vi.fn((key) => localStorageMock.store[key] || null),
10
+ setItem: vi.fn((key, value) => {
11
+ localStorageMock.store[key] = value;
12
+ }),
13
+ removeItem: vi.fn((key) => {
14
+ delete localStorageMock.store[key];
15
+ }),
16
+ clear: vi.fn(() => {
17
+ localStorageMock.store = {};
18
+ }),
19
+ };
20
+ Object.defineProperty(window, 'localStorage', {
21
+ value: localStorageMock,
22
+ writable: true,
23
+ });
24
+
25
+ // Clear cache before each test
26
+ clearGreetingCache();
27
+ });
28
+
29
+ afterEach(() => {
30
+ vi.restoreAllMocks();
31
+ });
32
+
33
+ describe('getFirstName', () => {
34
+ it('returns first name from full name', () => {
35
+ expect(getFirstName('John Doe')).toBe('John');
36
+ });
37
+
38
+ it('handles single name', () => {
39
+ expect(getFirstName('John')).toBe('John');
40
+ });
41
+
42
+ it('handles multiple names', () => {
43
+ expect(getFirstName('John Michael Doe')).toBe('John');
44
+ });
45
+
46
+ it('returns empty string for empty input', () => {
47
+ expect(getFirstName('')).toBe('');
48
+ });
49
+
50
+ it('returns empty string for null', () => {
51
+ expect(getFirstName(null)).toBe('');
52
+ });
53
+
54
+ it('returns empty string for undefined', () => {
55
+ expect(getFirstName(undefined)).toBe('');
56
+ });
57
+ });
58
+
59
+ describe('getGreeting', () => {
60
+ it('returns a string containing the name', () => {
61
+ const greeting = getGreeting('Alex');
62
+ expect(greeting).toContain('Alex');
63
+ });
64
+
65
+ it('returns different greetings for different time periods', () => {
66
+ // Run multiple times to increase chance of getting different greetings
67
+ const greetings = new Set();
68
+ for (let i = 0; i < 20; i++) {
69
+ clearGreetingCache();
70
+ greetings.add(getGreeting('Test'));
71
+ }
72
+ // Should have at least one greeting (randomness means we might get the same one)
73
+ expect(greetings.size).toBeGreaterThanOrEqual(1);
74
+ });
75
+
76
+ it('caches greeting in localStorage', () => {
77
+ getGreeting('Alex');
78
+ expect(window.localStorage.setItem).toHaveBeenCalled();
79
+ });
80
+
81
+ it('returns cached greeting for same user', () => {
82
+ const greeting1 = getGreeting('Alex');
83
+ const greeting2 = getGreeting('Alex');
84
+ expect(greeting1).toBe(greeting2);
85
+ });
86
+
87
+ it('generates new greeting for different user', () => {
88
+ const greeting1 = getGreeting('Alex');
89
+ clearGreetingCache();
90
+ const greeting2 = getGreeting('Beth');
91
+ expect(greeting2).toContain('Beth');
92
+ });
93
+
94
+ it('handles localStorage errors gracefully', () => {
95
+ window.localStorage.getItem.mockImplementation(() => {
96
+ throw new Error('localStorage error');
97
+ });
98
+
99
+ // Should not throw
100
+ expect(() => getGreeting('Alex')).not.toThrow();
101
+ const greeting = getGreeting('Alex');
102
+ expect(greeting).toContain('Alex');
103
+ });
104
+
105
+ it('handles invalid cached JSON gracefully', () => {
106
+ window.localStorage.getItem.mockReturnValue('invalid json');
107
+
108
+ // Should not throw and should generate new greeting
109
+ expect(() => getGreeting('Alex')).not.toThrow();
110
+ });
111
+ });
112
+
113
+ describe('clearGreetingCache', () => {
114
+ it('removes greeting from localStorage', () => {
115
+ getGreeting('Alex');
116
+ clearGreetingCache();
117
+ expect(window.localStorage.removeItem).toHaveBeenCalledWith('micdrop_greeting');
118
+ });
119
+
120
+ it('handles localStorage errors gracefully', () => {
121
+ window.localStorage.removeItem.mockImplementation(() => {
122
+ throw new Error('localStorage error');
123
+ });
124
+
125
+ // Should not throw
126
+ expect(() => clearGreetingCache()).not.toThrow();
127
+ });
128
+ });
129
+
130
+ describe('greeting content', () => {
131
+ it('greeting always includes user name', () => {
132
+ for (let i = 0; i < 10; i++) {
133
+ clearGreetingCache();
134
+ const greeting = getGreeting('TestUser');
135
+ expect(greeting).toContain('TestUser');
136
+ }
137
+ });
138
+
139
+ it('handles names with special characters', () => {
140
+ const greeting = getGreeting("O'Brien");
141
+ expect(greeting).toContain("O'Brien");
142
+ });
143
+
144
+ it('handles names with numbers', () => {
145
+ const greeting = getGreeting('User123');
146
+ expect(greeting).toContain('User123');
147
+ });
148
+ });
149
+
150
+ describe('localStorage setItem error handling', () => {
151
+ it('handles localStorage setItem error gracefully', () => {
152
+ window.localStorage.setItem.mockImplementation(() => {
153
+ throw new Error('localStorage setItem error');
154
+ });
155
+
156
+ // Should not throw even when setItem fails
157
+ expect(() => getGreeting('Alex')).not.toThrow();
158
+ const greeting = getGreeting('Alex');
159
+ expect(greeting).toContain('Alex');
160
+ });
161
+ });
162
+
163
+ describe('SSR behavior', () => {
164
+ it('works without window (SSR simulation)', () => {
165
+ // The module checks typeof window === 'undefined' for SSR
166
+ // In JSDOM window exists, but we can test by checking that function works
167
+ const greeting = getGreeting('TestUser');
168
+ expect(typeof greeting).toBe('string');
169
+ expect(greeting).toContain('TestUser');
170
+ });
171
+ });
172
+
173
+ describe('time period coverage', () => {
174
+ // Test all time period branches by mocking Date
175
+ const RealDate = Date;
176
+
177
+ afterEach(() => {
178
+ global.Date = RealDate;
179
+ });
180
+
181
+ it('generates greeting for night period (21-24)', () => {
182
+ // Mock Date to return 22:00
183
+ global.Date = class extends RealDate {
184
+ constructor() {
185
+ super();
186
+ return new RealDate('2025-06-15T22:00:00');
187
+ }
188
+ getHours() { return 22; }
189
+ getDay() { return 0; }
190
+ };
191
+
192
+ clearGreetingCache();
193
+ const greeting = getGreeting('NightUser');
194
+ expect(greeting).toContain('NightUser');
195
+ });
196
+
197
+ it('generates greeting for late night period (0-5 AM)', () => {
198
+ // Mock Date to return 03:00
199
+ global.Date = class extends RealDate {
200
+ constructor() {
201
+ super();
202
+ return new RealDate('2025-06-15T03:00:00');
203
+ }
204
+ getHours() { return 3; }
205
+ getDay() { return 0; }
206
+ };
207
+
208
+ clearGreetingCache();
209
+ const greeting = getGreeting('LateNightUser');
210
+ expect(greeting).toContain('LateNightUser');
211
+ });
212
+
213
+ it('generates greeting for early morning period (5-7)', () => {
214
+ global.Date = class extends RealDate {
215
+ constructor() {
216
+ super();
217
+ return new RealDate('2025-06-15T06:00:00');
218
+ }
219
+ getHours() { return 6; }
220
+ getDay() { return 1; }
221
+ };
222
+
223
+ clearGreetingCache();
224
+ const greeting = getGreeting('EarlyUser');
225
+ expect(greeting).toContain('EarlyUser');
226
+ });
227
+
228
+ it('generates greeting for morning period (7-12)', () => {
229
+ global.Date = class extends RealDate {
230
+ constructor() {
231
+ super();
232
+ return new RealDate('2025-06-15T09:00:00');
233
+ }
234
+ getHours() { return 9; }
235
+ getDay() { return 2; }
236
+ };
237
+
238
+ clearGreetingCache();
239
+ const greeting = getGreeting('MorningUser');
240
+ expect(greeting).toContain('MorningUser');
241
+ });
242
+
243
+ it('generates greeting for afternoon period (12-17)', () => {
244
+ global.Date = class extends RealDate {
245
+ constructor() {
246
+ super();
247
+ return new RealDate('2025-06-15T14:00:00');
248
+ }
249
+ getHours() { return 14; }
250
+ getDay() { return 3; }
251
+ };
252
+
253
+ clearGreetingCache();
254
+ const greeting = getGreeting('AfternoonUser');
255
+ expect(greeting).toContain('AfternoonUser');
256
+ });
257
+
258
+ it('generates greeting for evening period (17-21)', () => {
259
+ global.Date = class extends RealDate {
260
+ constructor() {
261
+ super();
262
+ return new RealDate('2025-06-15T19:00:00');
263
+ }
264
+ getHours() { return 19; }
265
+ getDay() { return 4; }
266
+ };
267
+
268
+ clearGreetingCache();
269
+ const greeting = getGreeting('EveningUser');
270
+ expect(greeting).toContain('EveningUser');
271
+ });
272
+ });
273
+
274
+ describe('time-based greeting generation', () => {
275
+ it('generates consistent greeting with cached data for same period and day', () => {
276
+ // First call generates and caches
277
+ const greeting1 = getGreeting('Alex');
278
+
279
+ // Second call should return cached
280
+ const greeting2 = getGreeting('Alex');
281
+
282
+ expect(greeting1).toBe(greeting2);
283
+ });
284
+
285
+ it('generates greeting containing name for various scenarios', () => {
286
+ // Test with longer names
287
+ clearGreetingCache();
288
+ const longNameGreeting = getGreeting('AlexanderTheGreat');
289
+ expect(longNameGreeting).toContain('AlexanderTheGreat');
290
+
291
+ // Test with short names
292
+ clearGreetingCache();
293
+ const shortNameGreeting = getGreeting('Jo');
294
+ expect(shortNameGreeting).toContain('Jo');
295
+ });
296
+
297
+ it('respects cache when period and day match', () => {
298
+ const greeting1 = getGreeting('TestUser');
299
+
300
+ // Mock getting a valid cached value
301
+ const cachedValue = window.localStorage.store['micdrop_greeting'];
302
+ expect(cachedValue).toBeDefined();
303
+
304
+ // Parse to verify structure
305
+ const parsed = JSON.parse(cachedValue);
306
+ expect(parsed).toHaveProperty('greeting');
307
+ expect(parsed).toHaveProperty('period');
308
+ expect(parsed).toHaveProperty('day');
309
+ expect(parsed).toHaveProperty('cachedName');
310
+ expect(parsed.cachedName).toBe('TestUser');
311
+ });
312
+ });
313
+
314
+ describe('SSR mode', () => {
315
+ it('generates greeting without caching when window is undefined', async () => {
316
+ vi.resetModules();
317
+
318
+ // Save original window
319
+ const originalWindow = global.window;
320
+
321
+ // Delete window to simulate SSR
322
+ delete global.window;
323
+
324
+ // Re-import module in SSR context
325
+ const { getGreeting: ssrGetGreeting } = await import('./greetings.js');
326
+
327
+ // Should still generate a greeting
328
+ const greeting = ssrGetGreeting('TestUser');
329
+ expect(greeting).toBeDefined();
330
+ expect(typeof greeting).toBe('string');
331
+ expect(greeting).toContain('TestUser');
332
+
333
+ // Restore window
334
+ global.window = originalWindow;
335
+ });
336
+ });
337
+ });