@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,220 +1,220 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
validateImage,
|
|
4
|
-
getImageAcceptAttribute,
|
|
5
|
-
getValidationMessages,
|
|
6
|
-
MAX_FILE_SIZE,
|
|
7
|
-
MAX_DIMENSION,
|
|
8
|
-
ALLOWED_IMAGE_TYPES,
|
|
9
|
-
} from './imageValidation';
|
|
10
|
-
|
|
11
|
-
describe('imageValidation', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
// Mock URL.createObjectURL and URL.revokeObjectURL
|
|
14
|
-
global.URL.createObjectURL = vi.fn(() => 'mock-object-url');
|
|
15
|
-
global.URL.revokeObjectURL = vi.fn();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('constants', () => {
|
|
19
|
-
it('MAX_FILE_SIZE is 20MB', () => {
|
|
20
|
-
expect(MAX_FILE_SIZE).toBe(20 * 1024 * 1024);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('MAX_DIMENSION is 8000', () => {
|
|
24
|
-
expect(MAX_DIMENSION).toBe(8000);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('ALLOWED_IMAGE_TYPES includes common formats', () => {
|
|
28
|
-
expect(ALLOWED_IMAGE_TYPES).toContain('image/jpeg');
|
|
29
|
-
expect(ALLOWED_IMAGE_TYPES).toContain('image/png');
|
|
30
|
-
expect(ALLOWED_IMAGE_TYPES).toContain('image/webp');
|
|
31
|
-
expect(ALLOWED_IMAGE_TYPES).toContain('image/heic');
|
|
32
|
-
expect(ALLOWED_IMAGE_TYPES).toContain('image/heif');
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('validateImage', () => {
|
|
37
|
-
it('rejects invalid file type', async () => {
|
|
38
|
-
const file = new File(['content'], 'test.gif', { type: 'image/gif' });
|
|
39
|
-
const result = await validateImage(file);
|
|
40
|
-
|
|
41
|
-
expect(result.valid).toBe(false);
|
|
42
|
-
expect(result.error).toContain('Invalid file format');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('rejects file that is too large', async () => {
|
|
46
|
-
// Create a mock file larger than 20MB
|
|
47
|
-
const largeContent = new ArrayBuffer(21 * 1024 * 1024);
|
|
48
|
-
const file = new File([largeContent], 'large.jpg', { type: 'image/jpeg' });
|
|
49
|
-
|
|
50
|
-
const result = await validateImage(file);
|
|
51
|
-
|
|
52
|
-
expect(result.valid).toBe(false);
|
|
53
|
-
expect(result.error).toContain('File too large');
|
|
54
|
-
expect(result.error).toContain('20MB');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('accepts valid JPEG file', async () => {
|
|
58
|
-
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
59
|
-
|
|
60
|
-
// Mock Image loading
|
|
61
|
-
const mockImage = {
|
|
62
|
-
width: 100,
|
|
63
|
-
height: 100,
|
|
64
|
-
onload: null,
|
|
65
|
-
onerror: null,
|
|
66
|
-
src: '',
|
|
67
|
-
};
|
|
68
|
-
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
69
|
-
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
70
|
-
return mockImage;
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const result = await validateImage(file);
|
|
74
|
-
|
|
75
|
-
expect(result.valid).toBe(true);
|
|
76
|
-
expect(result.error).toBe(null);
|
|
77
|
-
expect(result.dimensions).toEqual({ width: 100, height: 100 });
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('accepts valid PNG file', async () => {
|
|
81
|
-
const file = new File(['content'], 'test.png', { type: 'image/png' });
|
|
82
|
-
|
|
83
|
-
const mockImage = {
|
|
84
|
-
width: 500,
|
|
85
|
-
height: 500,
|
|
86
|
-
onload: null,
|
|
87
|
-
onerror: null,
|
|
88
|
-
src: '',
|
|
89
|
-
};
|
|
90
|
-
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
91
|
-
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
92
|
-
return mockImage;
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const result = await validateImage(file);
|
|
96
|
-
|
|
97
|
-
expect(result.valid).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('accepts valid WebP file', async () => {
|
|
101
|
-
const file = new File(['content'], 'test.webp', { type: 'image/webp' });
|
|
102
|
-
|
|
103
|
-
const mockImage = {
|
|
104
|
-
width: 200,
|
|
105
|
-
height: 200,
|
|
106
|
-
onload: null,
|
|
107
|
-
onerror: null,
|
|
108
|
-
src: '',
|
|
109
|
-
};
|
|
110
|
-
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
111
|
-
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
112
|
-
return mockImage;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const result = await validateImage(file);
|
|
116
|
-
|
|
117
|
-
expect(result.valid).toBe(true);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('rejects image with dimensions too large', async () => {
|
|
121
|
-
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
122
|
-
|
|
123
|
-
const mockImage = {
|
|
124
|
-
width: 9000,
|
|
125
|
-
height: 9000,
|
|
126
|
-
onload: null,
|
|
127
|
-
onerror: null,
|
|
128
|
-
src: '',
|
|
129
|
-
};
|
|
130
|
-
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
131
|
-
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
132
|
-
return mockImage;
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const result = await validateImage(file);
|
|
136
|
-
|
|
137
|
-
expect(result.valid).toBe(false);
|
|
138
|
-
expect(result.error).toContain('dimensions too large');
|
|
139
|
-
expect(result.dimensions).toEqual({ width: 9000, height: 9000 });
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('handles image load error', async () => {
|
|
143
|
-
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
144
|
-
|
|
145
|
-
const mockImage = {
|
|
146
|
-
onload: null,
|
|
147
|
-
onerror: null,
|
|
148
|
-
src: '',
|
|
149
|
-
};
|
|
150
|
-
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
151
|
-
setTimeout(() => mockImage.onerror?.(), 0);
|
|
152
|
-
return mockImage;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const result = await validateImage(file);
|
|
156
|
-
|
|
157
|
-
expect(result.valid).toBe(false);
|
|
158
|
-
expect(result.error).toContain('Failed to read image dimensions');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('handles HEIC format', async () => {
|
|
162
|
-
const file = new File(['content'], 'test.heic', { type: 'image/heic' });
|
|
163
|
-
|
|
164
|
-
const mockImage = {
|
|
165
|
-
width: 100,
|
|
166
|
-
height: 100,
|
|
167
|
-
onload: null,
|
|
168
|
-
onerror: null,
|
|
169
|
-
src: '',
|
|
170
|
-
};
|
|
171
|
-
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
172
|
-
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
173
|
-
return mockImage;
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const result = await validateImage(file);
|
|
177
|
-
|
|
178
|
-
expect(result.valid).toBe(true);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('getImageAcceptAttribute', () => {
|
|
183
|
-
it('returns accept string with all allowed types', () => {
|
|
184
|
-
const accept = getImageAcceptAttribute();
|
|
185
|
-
|
|
186
|
-
expect(accept).toContain('image/png');
|
|
187
|
-
expect(accept).toContain('image/jpeg');
|
|
188
|
-
expect(accept).toContain('image/webp');
|
|
189
|
-
expect(accept).toContain('image/heic');
|
|
190
|
-
expect(accept).toContain('image/heif');
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('returns comma-separated values', () => {
|
|
194
|
-
const accept = getImageAcceptAttribute();
|
|
195
|
-
expect(accept.split(',').length).toBeGreaterThan(1);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
describe('getValidationMessages', () => {
|
|
200
|
-
it('returns formats message', () => {
|
|
201
|
-
const messages = getValidationMessages();
|
|
202
|
-
expect(messages.formats).toBe('PNG, JPG, WebP, HEIC');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('returns maxSize message', () => {
|
|
206
|
-
const messages = getValidationMessages();
|
|
207
|
-
expect(messages.maxSize).toBe('20MB');
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('returns maxDimension message', () => {
|
|
211
|
-
const messages = getValidationMessages();
|
|
212
|
-
expect(messages.maxDimension).toBe('8000px');
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('returns aspectRatio message', () => {
|
|
216
|
-
const messages = getValidationMessages();
|
|
217
|
-
expect(messages.aspectRatio).toBe('Any');
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
validateImage,
|
|
4
|
+
getImageAcceptAttribute,
|
|
5
|
+
getValidationMessages,
|
|
6
|
+
MAX_FILE_SIZE,
|
|
7
|
+
MAX_DIMENSION,
|
|
8
|
+
ALLOWED_IMAGE_TYPES,
|
|
9
|
+
} from './imageValidation';
|
|
10
|
+
|
|
11
|
+
describe('imageValidation', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
// Mock URL.createObjectURL and URL.revokeObjectURL
|
|
14
|
+
global.URL.createObjectURL = vi.fn(() => 'mock-object-url');
|
|
15
|
+
global.URL.revokeObjectURL = vi.fn();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('constants', () => {
|
|
19
|
+
it('MAX_FILE_SIZE is 20MB', () => {
|
|
20
|
+
expect(MAX_FILE_SIZE).toBe(20 * 1024 * 1024);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('MAX_DIMENSION is 8000', () => {
|
|
24
|
+
expect(MAX_DIMENSION).toBe(8000);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('ALLOWED_IMAGE_TYPES includes common formats', () => {
|
|
28
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/jpeg');
|
|
29
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/png');
|
|
30
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/webp');
|
|
31
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/heic');
|
|
32
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/heif');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('validateImage', () => {
|
|
37
|
+
it('rejects invalid file type', async () => {
|
|
38
|
+
const file = new File(['content'], 'test.gif', { type: 'image/gif' });
|
|
39
|
+
const result = await validateImage(file);
|
|
40
|
+
|
|
41
|
+
expect(result.valid).toBe(false);
|
|
42
|
+
expect(result.error).toContain('Invalid file format');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('rejects file that is too large', async () => {
|
|
46
|
+
// Create a mock file larger than 20MB
|
|
47
|
+
const largeContent = new ArrayBuffer(21 * 1024 * 1024);
|
|
48
|
+
const file = new File([largeContent], 'large.jpg', { type: 'image/jpeg' });
|
|
49
|
+
|
|
50
|
+
const result = await validateImage(file);
|
|
51
|
+
|
|
52
|
+
expect(result.valid).toBe(false);
|
|
53
|
+
expect(result.error).toContain('File too large');
|
|
54
|
+
expect(result.error).toContain('20MB');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('accepts valid JPEG file', async () => {
|
|
58
|
+
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
59
|
+
|
|
60
|
+
// Mock Image loading
|
|
61
|
+
const mockImage = {
|
|
62
|
+
width: 100,
|
|
63
|
+
height: 100,
|
|
64
|
+
onload: null,
|
|
65
|
+
onerror: null,
|
|
66
|
+
src: '',
|
|
67
|
+
};
|
|
68
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
69
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
70
|
+
return mockImage;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const result = await validateImage(file);
|
|
74
|
+
|
|
75
|
+
expect(result.valid).toBe(true);
|
|
76
|
+
expect(result.error).toBe(null);
|
|
77
|
+
expect(result.dimensions).toEqual({ width: 100, height: 100 });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('accepts valid PNG file', async () => {
|
|
81
|
+
const file = new File(['content'], 'test.png', { type: 'image/png' });
|
|
82
|
+
|
|
83
|
+
const mockImage = {
|
|
84
|
+
width: 500,
|
|
85
|
+
height: 500,
|
|
86
|
+
onload: null,
|
|
87
|
+
onerror: null,
|
|
88
|
+
src: '',
|
|
89
|
+
};
|
|
90
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
91
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
92
|
+
return mockImage;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const result = await validateImage(file);
|
|
96
|
+
|
|
97
|
+
expect(result.valid).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('accepts valid WebP file', async () => {
|
|
101
|
+
const file = new File(['content'], 'test.webp', { type: 'image/webp' });
|
|
102
|
+
|
|
103
|
+
const mockImage = {
|
|
104
|
+
width: 200,
|
|
105
|
+
height: 200,
|
|
106
|
+
onload: null,
|
|
107
|
+
onerror: null,
|
|
108
|
+
src: '',
|
|
109
|
+
};
|
|
110
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
111
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
112
|
+
return mockImage;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const result = await validateImage(file);
|
|
116
|
+
|
|
117
|
+
expect(result.valid).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('rejects image with dimensions too large', async () => {
|
|
121
|
+
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
122
|
+
|
|
123
|
+
const mockImage = {
|
|
124
|
+
width: 9000,
|
|
125
|
+
height: 9000,
|
|
126
|
+
onload: null,
|
|
127
|
+
onerror: null,
|
|
128
|
+
src: '',
|
|
129
|
+
};
|
|
130
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
131
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
132
|
+
return mockImage;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const result = await validateImage(file);
|
|
136
|
+
|
|
137
|
+
expect(result.valid).toBe(false);
|
|
138
|
+
expect(result.error).toContain('dimensions too large');
|
|
139
|
+
expect(result.dimensions).toEqual({ width: 9000, height: 9000 });
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('handles image load error', async () => {
|
|
143
|
+
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
144
|
+
|
|
145
|
+
const mockImage = {
|
|
146
|
+
onload: null,
|
|
147
|
+
onerror: null,
|
|
148
|
+
src: '',
|
|
149
|
+
};
|
|
150
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
151
|
+
setTimeout(() => mockImage.onerror?.(), 0);
|
|
152
|
+
return mockImage;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const result = await validateImage(file);
|
|
156
|
+
|
|
157
|
+
expect(result.valid).toBe(false);
|
|
158
|
+
expect(result.error).toContain('Failed to read image dimensions');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('handles HEIC format', async () => {
|
|
162
|
+
const file = new File(['content'], 'test.heic', { type: 'image/heic' });
|
|
163
|
+
|
|
164
|
+
const mockImage = {
|
|
165
|
+
width: 100,
|
|
166
|
+
height: 100,
|
|
167
|
+
onload: null,
|
|
168
|
+
onerror: null,
|
|
169
|
+
src: '',
|
|
170
|
+
};
|
|
171
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
172
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
173
|
+
return mockImage;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const result = await validateImage(file);
|
|
177
|
+
|
|
178
|
+
expect(result.valid).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('getImageAcceptAttribute', () => {
|
|
183
|
+
it('returns accept string with all allowed types', () => {
|
|
184
|
+
const accept = getImageAcceptAttribute();
|
|
185
|
+
|
|
186
|
+
expect(accept).toContain('image/png');
|
|
187
|
+
expect(accept).toContain('image/jpeg');
|
|
188
|
+
expect(accept).toContain('image/webp');
|
|
189
|
+
expect(accept).toContain('image/heic');
|
|
190
|
+
expect(accept).toContain('image/heif');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('returns comma-separated values', () => {
|
|
194
|
+
const accept = getImageAcceptAttribute();
|
|
195
|
+
expect(accept.split(',').length).toBeGreaterThan(1);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('getValidationMessages', () => {
|
|
200
|
+
it('returns formats message', () => {
|
|
201
|
+
const messages = getValidationMessages();
|
|
202
|
+
expect(messages.formats).toBe('PNG, JPG, WebP, HEIC');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('returns maxSize message', () => {
|
|
206
|
+
const messages = getValidationMessages();
|
|
207
|
+
expect(messages.maxSize).toBe('20MB');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('returns maxDimension message', () => {
|
|
211
|
+
const messages = getValidationMessages();
|
|
212
|
+
expect(messages.maxDimension).toBe('8000px');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('returns aspectRatio message', () => {
|
|
216
|
+
const messages = getValidationMessages();
|
|
217
|
+
expect(messages.aspectRatio).toBe('Any');
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
package/dist/utils/portal.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Svelte action that portals an element to a target container (default: document.body)
|
|
3
|
-
* This moves the element outside of any stacking contexts, solving iOS z-index issues.
|
|
4
|
-
*
|
|
5
|
-
* Usage: <div use:portal>...</div>
|
|
6
|
-
* Or: <div use:portal={document.getElementById('modal-root')}>...</div>
|
|
7
|
-
*/
|
|
8
|
-
export function portal(node, target = document.body) {
|
|
9
|
-
// Move the node to the target
|
|
10
|
-
target.appendChild(node);
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
update(newTarget) {
|
|
14
|
-
// If target changes, move to new target
|
|
15
|
-
newTarget = newTarget || document.body;
|
|
16
|
-
newTarget.appendChild(node);
|
|
17
|
-
},
|
|
18
|
-
destroy() {
|
|
19
|
-
// Clean up - remove the node when component is destroyed
|
|
20
|
-
if (node.parentNode) {
|
|
21
|
-
node.parentNode.removeChild(node);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Svelte action that portals an element to a target container (default: document.body)
|
|
3
|
+
* This moves the element outside of any stacking contexts, solving iOS z-index issues.
|
|
4
|
+
*
|
|
5
|
+
* Usage: <div use:portal>...</div>
|
|
6
|
+
* Or: <div use:portal={document.getElementById('modal-root')}>...</div>
|
|
7
|
+
*/
|
|
8
|
+
export function portal(node, target = document.body) {
|
|
9
|
+
// Move the node to the target
|
|
10
|
+
target.appendChild(node);
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
update(newTarget) {
|
|
14
|
+
// If target changes, move to new target
|
|
15
|
+
newTarget = newTarget || document.body;
|
|
16
|
+
newTarget.appendChild(node);
|
|
17
|
+
},
|
|
18
|
+
destroy() {
|
|
19
|
+
// Clean up - remove the node when component is destroyed
|
|
20
|
+
if (node.parentNode) {
|
|
21
|
+
node.parentNode.removeChild(node);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|