@getmicdrop/svelte-components 5.7.2 → 5.8.0
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/primitives/Checkbox/Checkbox.svelte +3 -3
- package/dist/stores/auth.js +8 -0
- package/dist/stores/auth.svelte.d.ts +39 -0
- package/dist/stores/auth.svelte.d.ts.map +1 -0
- package/dist/stores/auth.svelte.js +60 -0
- package/dist/stores/formDataStore.d.ts.map +1 -1
- package/dist/stores/formDataStore.js +8 -0
- package/dist/stores/formDataStore.svelte.d.ts +47 -0
- package/dist/stores/formDataStore.svelte.d.ts.map +1 -0
- package/dist/stores/formDataStore.svelte.js +84 -0
- package/dist/stores/formSave.d.ts.map +1 -1
- package/dist/stores/formSave.js +8 -0
- package/dist/stores/formSave.svelte.d.ts +33 -0
- package/dist/stores/formSave.svelte.d.ts.map +1 -0
- package/dist/stores/formSave.svelte.js +113 -0
- package/dist/stores/navigation.d.ts.map +1 -1
- package/dist/stores/navigation.js +8 -0
- package/dist/stores/navigation.svelte.d.ts +35 -0
- package/dist/stores/navigation.svelte.d.ts.map +1 -0
- package/dist/stores/navigation.svelte.js +69 -0
- package/package.json +8 -9
- package/dist/stores/auth.spec.d.ts +0 -2
- package/dist/stores/auth.spec.d.ts.map +0 -1
- package/dist/stores/auth.spec.js +0 -139
- package/dist/stores/createFormStore.spec.d.ts +0 -2
- package/dist/stores/createFormStore.spec.d.ts.map +0 -1
- package/dist/stores/createFormStore.spec.js +0 -540
- package/dist/stores/formDataStore.spec.d.ts +0 -2
- package/dist/stores/formDataStore.spec.d.ts.map +0 -1
- package/dist/stores/formDataStore.spec.js +0 -257
- package/dist/stores/formSave.spec.d.ts +0 -2
- package/dist/stores/formSave.spec.d.ts.map +0 -1
- package/dist/stores/formSave.spec.js +0 -296
- package/dist/stores/navigation.spec.d.ts +0 -2
- package/dist/stores/navigation.spec.d.ts.map +0 -1
- package/dist/stores/navigation.spec.js +0 -136
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { get } from 'svelte/store';
|
|
3
|
-
import { profileFormData, initialFormData, hasChanges } from './formDataStore';
|
|
4
|
-
|
|
5
|
-
describe('formDataStore', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
// Reset stores to initial state
|
|
8
|
-
profileFormData.set({
|
|
9
|
-
basicInfo: {
|
|
10
|
-
firstName: '',
|
|
11
|
-
lastName: '',
|
|
12
|
-
email: '',
|
|
13
|
-
phone: '',
|
|
14
|
-
stageName: '',
|
|
15
|
-
location: '',
|
|
16
|
-
},
|
|
17
|
-
socialMedia: {
|
|
18
|
-
videoLink: '',
|
|
19
|
-
},
|
|
20
|
-
extraDetails: {},
|
|
21
|
-
});
|
|
22
|
-
initialFormData.set(null);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('profileFormData', () => {
|
|
26
|
-
it('has initial structure with basicInfo', () => {
|
|
27
|
-
const data = get(profileFormData);
|
|
28
|
-
expect(data.basicInfo).toBeDefined();
|
|
29
|
-
expect(data.basicInfo.firstName).toBe('');
|
|
30
|
-
expect(data.basicInfo.lastName).toBe('');
|
|
31
|
-
expect(data.basicInfo.email).toBe('');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('has initial structure with socialMedia', () => {
|
|
35
|
-
const data = get(profileFormData);
|
|
36
|
-
expect(data.socialMedia).toBeDefined();
|
|
37
|
-
expect(data.socialMedia.videoLink).toBe('');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('has initial structure with extraDetails', () => {
|
|
41
|
-
const data = get(profileFormData);
|
|
42
|
-
expect(data.extraDetails).toBeDefined();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('can be updated', () => {
|
|
46
|
-
profileFormData.update((data) => ({
|
|
47
|
-
...data,
|
|
48
|
-
basicInfo: {
|
|
49
|
-
...data.basicInfo,
|
|
50
|
-
firstName: 'John',
|
|
51
|
-
lastName: 'Doe',
|
|
52
|
-
},
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
const data = get(profileFormData);
|
|
56
|
-
expect(data.basicInfo.firstName).toBe('John');
|
|
57
|
-
expect(data.basicInfo.lastName).toBe('Doe');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('can be set completely', () => {
|
|
61
|
-
profileFormData.set({
|
|
62
|
-
basicInfo: {
|
|
63
|
-
firstName: 'Jane',
|
|
64
|
-
lastName: 'Smith',
|
|
65
|
-
email: 'jane@example.com',
|
|
66
|
-
phone: '555-1234',
|
|
67
|
-
stageName: 'JSmith',
|
|
68
|
-
location: 'LA',
|
|
69
|
-
},
|
|
70
|
-
socialMedia: {
|
|
71
|
-
videoLink: 'https://youtube.com/watch',
|
|
72
|
-
},
|
|
73
|
-
extraDetails: { bio: 'Test bio' },
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const data = get(profileFormData);
|
|
77
|
-
expect(data.basicInfo.firstName).toBe('Jane');
|
|
78
|
-
expect(data.socialMedia.videoLink).toBe('https://youtube.com/watch');
|
|
79
|
-
expect(data.extraDetails.bio).toBe('Test bio');
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('initialFormData', () => {
|
|
84
|
-
it('starts as null', () => {
|
|
85
|
-
expect(get(initialFormData)).toBe(null);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('can store form data snapshot', () => {
|
|
89
|
-
const snapshot = {
|
|
90
|
-
basicInfo: {
|
|
91
|
-
firstName: 'Original',
|
|
92
|
-
lastName: 'Name',
|
|
93
|
-
email: '',
|
|
94
|
-
phone: '',
|
|
95
|
-
stageName: '',
|
|
96
|
-
location: '',
|
|
97
|
-
},
|
|
98
|
-
socialMedia: { videoLink: '' },
|
|
99
|
-
extraDetails: {},
|
|
100
|
-
};
|
|
101
|
-
initialFormData.set(snapshot);
|
|
102
|
-
|
|
103
|
-
expect(get(initialFormData)).toEqual(snapshot);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe('hasChanges (derived store)', () => {
|
|
108
|
-
it('is false when both are null/empty', () => {
|
|
109
|
-
profileFormData.set({
|
|
110
|
-
basicInfo: {
|
|
111
|
-
firstName: '',
|
|
112
|
-
lastName: '',
|
|
113
|
-
email: '',
|
|
114
|
-
phone: '',
|
|
115
|
-
stageName: '',
|
|
116
|
-
location: '',
|
|
117
|
-
},
|
|
118
|
-
socialMedia: { videoLink: '' },
|
|
119
|
-
extraDetails: {},
|
|
120
|
-
});
|
|
121
|
-
initialFormData.set(null);
|
|
122
|
-
|
|
123
|
-
// The comparison will be false because null !== stringified object
|
|
124
|
-
expect(get(hasChanges)).toBe(true);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('is false when form data matches initial', () => {
|
|
128
|
-
const data = {
|
|
129
|
-
basicInfo: {
|
|
130
|
-
firstName: 'John',
|
|
131
|
-
lastName: 'Doe',
|
|
132
|
-
email: 'john@example.com',
|
|
133
|
-
phone: '',
|
|
134
|
-
stageName: '',
|
|
135
|
-
location: '',
|
|
136
|
-
},
|
|
137
|
-
socialMedia: { videoLink: '' },
|
|
138
|
-
extraDetails: {},
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
profileFormData.set(data);
|
|
142
|
-
initialFormData.set(data);
|
|
143
|
-
|
|
144
|
-
expect(get(hasChanges)).toBe(false);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('is true when form data differs from initial', () => {
|
|
148
|
-
const initial = {
|
|
149
|
-
basicInfo: {
|
|
150
|
-
firstName: 'John',
|
|
151
|
-
lastName: 'Doe',
|
|
152
|
-
email: 'john@example.com',
|
|
153
|
-
phone: '',
|
|
154
|
-
stageName: '',
|
|
155
|
-
location: '',
|
|
156
|
-
},
|
|
157
|
-
socialMedia: { videoLink: '' },
|
|
158
|
-
extraDetails: {},
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const changed = {
|
|
162
|
-
...initial,
|
|
163
|
-
basicInfo: { ...initial.basicInfo, firstName: 'Jane' },
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
initialFormData.set(initial);
|
|
167
|
-
profileFormData.set(changed);
|
|
168
|
-
|
|
169
|
-
expect(get(hasChanges)).toBe(true);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('detects changes in socialMedia', () => {
|
|
173
|
-
const initial = {
|
|
174
|
-
basicInfo: {
|
|
175
|
-
firstName: '',
|
|
176
|
-
lastName: '',
|
|
177
|
-
email: '',
|
|
178
|
-
phone: '',
|
|
179
|
-
stageName: '',
|
|
180
|
-
location: '',
|
|
181
|
-
},
|
|
182
|
-
socialMedia: { videoLink: '' },
|
|
183
|
-
extraDetails: {},
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
initialFormData.set(initial);
|
|
187
|
-
profileFormData.set({
|
|
188
|
-
...initial,
|
|
189
|
-
socialMedia: { videoLink: 'https://youtube.com/new' },
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
expect(get(hasChanges)).toBe(true);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('detects changes in extraDetails', () => {
|
|
196
|
-
const initial = {
|
|
197
|
-
basicInfo: {
|
|
198
|
-
firstName: '',
|
|
199
|
-
lastName: '',
|
|
200
|
-
email: '',
|
|
201
|
-
phone: '',
|
|
202
|
-
stageName: '',
|
|
203
|
-
location: '',
|
|
204
|
-
},
|
|
205
|
-
socialMedia: { videoLink: '' },
|
|
206
|
-
extraDetails: {},
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
initialFormData.set(initial);
|
|
210
|
-
profileFormData.set({
|
|
211
|
-
...initial,
|
|
212
|
-
extraDetails: { bio: 'New bio' },
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
expect(get(hasChanges)).toBe(true);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('updates reactively when form changes', () => {
|
|
219
|
-
const initial = {
|
|
220
|
-
basicInfo: {
|
|
221
|
-
firstName: 'John',
|
|
222
|
-
lastName: 'Doe',
|
|
223
|
-
email: '',
|
|
224
|
-
phone: '',
|
|
225
|
-
stageName: '',
|
|
226
|
-
location: '',
|
|
227
|
-
},
|
|
228
|
-
socialMedia: { videoLink: '' },
|
|
229
|
-
extraDetails: {},
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
profileFormData.set(initial);
|
|
233
|
-
initialFormData.set(initial);
|
|
234
|
-
|
|
235
|
-
// No changes initially
|
|
236
|
-
expect(get(hasChanges)).toBe(false);
|
|
237
|
-
|
|
238
|
-
// Make a change
|
|
239
|
-
profileFormData.update((data) => ({
|
|
240
|
-
...data,
|
|
241
|
-
basicInfo: { ...data.basicInfo, firstName: 'Jane' },
|
|
242
|
-
}));
|
|
243
|
-
|
|
244
|
-
// Now has changes
|
|
245
|
-
expect(get(hasChanges)).toBe(true);
|
|
246
|
-
|
|
247
|
-
// Revert the change
|
|
248
|
-
profileFormData.update((data) => ({
|
|
249
|
-
...data,
|
|
250
|
-
basicInfo: { ...data.basicInfo, firstName: 'John' },
|
|
251
|
-
}));
|
|
252
|
-
|
|
253
|
-
// Back to no changes
|
|
254
|
-
expect(get(hasChanges)).toBe(false);
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formSave.spec.d.ts","sourceRoot":"","sources":["../../src/lib/stores/formSave.spec.js"],"names":[],"mappings":""}
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { get } from 'svelte/store';
|
|
3
|
-
|
|
4
|
-
// Mock toaster
|
|
5
|
-
vi.mock('./toaster', () => ({
|
|
6
|
-
showToast: vi.fn(),
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
import { createFormSave, createDirtyTracker } from './formSave';
|
|
10
|
-
import { showToast } from './toaster';
|
|
11
|
-
|
|
12
|
-
describe('formSave store', () => {
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
vi.clearAllMocks();
|
|
15
|
-
global.fetch = vi.fn();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('createFormSave', () => {
|
|
19
|
-
it('creates a form save instance with default options', () => {
|
|
20
|
-
const formSave = createFormSave();
|
|
21
|
-
expect(formSave.isLoading).toBeDefined();
|
|
22
|
-
expect(formSave.isSuccess).toBeDefined();
|
|
23
|
-
expect(formSave.error).toBeDefined();
|
|
24
|
-
expect(formSave.save).toBeDefined();
|
|
25
|
-
expect(formSave.resetSuccess).toBeDefined();
|
|
26
|
-
expect(formSave.reset).toBeDefined();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('has initial loading state as false', () => {
|
|
30
|
-
const formSave = createFormSave();
|
|
31
|
-
expect(get(formSave.isLoading)).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('has initial success state as false', () => {
|
|
35
|
-
const formSave = createFormSave();
|
|
36
|
-
expect(get(formSave.isSuccess)).toBe(false);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('has initial error state as null', () => {
|
|
40
|
-
const formSave = createFormSave();
|
|
41
|
-
expect(get(formSave.error)).toBe(null);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('save()', () => {
|
|
45
|
-
it('returns false when no endpoint is specified', async () => {
|
|
46
|
-
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
47
|
-
const formSave = createFormSave();
|
|
48
|
-
const result = await formSave.save({ data: 'test' });
|
|
49
|
-
expect(result).toBe(false);
|
|
50
|
-
consoleSpy.mockRestore();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('sets loading state during save', async () => {
|
|
54
|
-
global.fetch.mockImplementation(() =>
|
|
55
|
-
new Promise((resolve) => {
|
|
56
|
-
setTimeout(() => resolve({ ok: true, json: () => Promise.resolve({}) }), 100);
|
|
57
|
-
})
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const formSave = createFormSave({ endpoint: '/api/test' });
|
|
61
|
-
const savePromise = formSave.save({ data: 'test' });
|
|
62
|
-
|
|
63
|
-
// Loading should be true while saving
|
|
64
|
-
expect(get(formSave.isLoading)).toBe(true);
|
|
65
|
-
|
|
66
|
-
await savePromise;
|
|
67
|
-
expect(get(formSave.isLoading)).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('returns true on successful save', async () => {
|
|
71
|
-
global.fetch.mockResolvedValue({
|
|
72
|
-
ok: true,
|
|
73
|
-
json: () => Promise.resolve({ success: true }),
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const formSave = createFormSave({ endpoint: '/api/test' });
|
|
77
|
-
const result = await formSave.save({ data: 'test' });
|
|
78
|
-
|
|
79
|
-
expect(result).toBe(true);
|
|
80
|
-
expect(get(formSave.isSuccess)).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('shows success toast on successful save', async () => {
|
|
84
|
-
global.fetch.mockResolvedValue({
|
|
85
|
-
ok: true,
|
|
86
|
-
json: () => Promise.resolve({}),
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const formSave = createFormSave({
|
|
90
|
-
endpoint: '/api/test',
|
|
91
|
-
successMessage: 'Saved!',
|
|
92
|
-
});
|
|
93
|
-
await formSave.save({ data: 'test' });
|
|
94
|
-
|
|
95
|
-
expect(showToast).toHaveBeenCalledWith('Saved!', 'success');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('calls onSuccess callback on successful save', async () => {
|
|
99
|
-
const onSuccess = vi.fn();
|
|
100
|
-
global.fetch.mockResolvedValue({
|
|
101
|
-
ok: true,
|
|
102
|
-
json: () => Promise.resolve({}),
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const formSave = createFormSave({
|
|
106
|
-
endpoint: '/api/test',
|
|
107
|
-
onSuccess,
|
|
108
|
-
});
|
|
109
|
-
await formSave.save({ data: 'test' });
|
|
110
|
-
|
|
111
|
-
expect(onSuccess).toHaveBeenCalled();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('returns false on failed save', async () => {
|
|
115
|
-
global.fetch.mockResolvedValue({
|
|
116
|
-
ok: false,
|
|
117
|
-
json: () => Promise.resolve({ message: 'Error' }),
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const formSave = createFormSave({ endpoint: '/api/test' });
|
|
121
|
-
const result = await formSave.save({ data: 'test' });
|
|
122
|
-
|
|
123
|
-
expect(result).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('shows error toast on failed save', async () => {
|
|
127
|
-
global.fetch.mockResolvedValue({
|
|
128
|
-
ok: false,
|
|
129
|
-
json: () => Promise.resolve({ message: 'Custom error' }),
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const formSave = createFormSave({ endpoint: '/api/test' });
|
|
133
|
-
await formSave.save({ data: 'test' });
|
|
134
|
-
|
|
135
|
-
expect(showToast).toHaveBeenCalledWith('Custom error', 'error');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('calls onError callback on failed save', async () => {
|
|
139
|
-
const onError = vi.fn();
|
|
140
|
-
global.fetch.mockResolvedValue({
|
|
141
|
-
ok: false,
|
|
142
|
-
json: () => Promise.resolve({ message: 'Error' }),
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const formSave = createFormSave({
|
|
146
|
-
endpoint: '/api/test',
|
|
147
|
-
onError,
|
|
148
|
-
});
|
|
149
|
-
await formSave.save({ data: 'test' });
|
|
150
|
-
|
|
151
|
-
expect(onError).toHaveBeenCalledWith('Error');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('handles network errors', async () => {
|
|
155
|
-
global.fetch.mockRejectedValue(new Error('Network error'));
|
|
156
|
-
|
|
157
|
-
const formSave = createFormSave({ endpoint: '/api/test' });
|
|
158
|
-
const result = await formSave.save({ data: 'test' });
|
|
159
|
-
|
|
160
|
-
expect(result).toBe(false);
|
|
161
|
-
expect(get(formSave.error)).toBe('Network error');
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('uses custom endpoint when provided to save()', async () => {
|
|
165
|
-
global.fetch.mockResolvedValue({
|
|
166
|
-
ok: true,
|
|
167
|
-
json: () => Promise.resolve({}),
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const formSave = createFormSave({ endpoint: '/api/default' });
|
|
171
|
-
await formSave.save({ data: 'test' }, '/api/custom');
|
|
172
|
-
|
|
173
|
-
expect(global.fetch).toHaveBeenCalledWith('/api/custom', expect.any(Object));
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('uses default error message when response has no message', async () => {
|
|
177
|
-
global.fetch.mockResolvedValue({
|
|
178
|
-
ok: false,
|
|
179
|
-
json: () => Promise.reject(new Error('Parse error')),
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
const formSave = createFormSave({
|
|
183
|
-
endpoint: '/api/test',
|
|
184
|
-
errorMessage: 'Default error',
|
|
185
|
-
});
|
|
186
|
-
await formSave.save({ data: 'test' });
|
|
187
|
-
|
|
188
|
-
expect(showToast).toHaveBeenCalledWith('Default error', 'error');
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
describe('resetSuccess()', () => {
|
|
193
|
-
it('resets success state to false', async () => {
|
|
194
|
-
global.fetch.mockResolvedValue({
|
|
195
|
-
ok: true,
|
|
196
|
-
json: () => Promise.resolve({}),
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
const formSave = createFormSave({ endpoint: '/api/test' });
|
|
200
|
-
await formSave.save({ data: 'test' });
|
|
201
|
-
expect(get(formSave.isSuccess)).toBe(true);
|
|
202
|
-
|
|
203
|
-
formSave.resetSuccess();
|
|
204
|
-
expect(get(formSave.isSuccess)).toBe(false);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
describe('reset()', () => {
|
|
209
|
-
it('resets all states', async () => {
|
|
210
|
-
global.fetch.mockRejectedValue(new Error('Error'));
|
|
211
|
-
|
|
212
|
-
const formSave = createFormSave({ endpoint: '/api/test' });
|
|
213
|
-
await formSave.save({ data: 'test' });
|
|
214
|
-
|
|
215
|
-
formSave.reset();
|
|
216
|
-
|
|
217
|
-
expect(get(formSave.isLoading)).toBe(false);
|
|
218
|
-
expect(get(formSave.isSuccess)).toBe(false);
|
|
219
|
-
expect(get(formSave.error)).toBe(null);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
describe('convenience getters', () => {
|
|
224
|
-
it('loading getter returns current loading state', () => {
|
|
225
|
-
const formSave = createFormSave();
|
|
226
|
-
expect(formSave.loading).toBe(false);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('success getter returns current success state', () => {
|
|
230
|
-
const formSave = createFormSave();
|
|
231
|
-
expect(formSave.success).toBe(false);
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe('createDirtyTracker', () => {
|
|
237
|
-
it('creates a dirty tracker with initial data', () => {
|
|
238
|
-
const tracker = createDirtyTracker({ name: 'test' });
|
|
239
|
-
expect(tracker.isDirty).toBeDefined();
|
|
240
|
-
expect(tracker.check).toBeDefined();
|
|
241
|
-
expect(tracker.reset).toBeDefined();
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('initially not dirty', () => {
|
|
245
|
-
const tracker = createDirtyTracker({ name: 'test' });
|
|
246
|
-
expect(get(tracker.isDirty)).toBe(false);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
describe('check()', () => {
|
|
250
|
-
it('returns false when data has not changed', () => {
|
|
251
|
-
const tracker = createDirtyTracker({ name: 'test' });
|
|
252
|
-
const result = tracker.check({ name: 'test' });
|
|
253
|
-
expect(result).toBe(false);
|
|
254
|
-
expect(get(tracker.isDirty)).toBe(false);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('returns true when data has changed', () => {
|
|
258
|
-
const tracker = createDirtyTracker({ name: 'test' });
|
|
259
|
-
const result = tracker.check({ name: 'changed' });
|
|
260
|
-
expect(result).toBe(true);
|
|
261
|
-
expect(get(tracker.isDirty)).toBe(true);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('detects changes in nested objects', () => {
|
|
265
|
-
const tracker = createDirtyTracker({ user: { name: 'test' } });
|
|
266
|
-
const result = tracker.check({ user: { name: 'changed' } });
|
|
267
|
-
expect(result).toBe(true);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('detects changes in arrays', () => {
|
|
271
|
-
const tracker = createDirtyTracker({ items: [1, 2, 3] });
|
|
272
|
-
const result = tracker.check({ items: [1, 2, 3, 4] });
|
|
273
|
-
expect(result).toBe(true);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
describe('reset()', () => {
|
|
278
|
-
it('resets dirty state with new initial data', () => {
|
|
279
|
-
const tracker = createDirtyTracker({ name: 'test' });
|
|
280
|
-
tracker.check({ name: 'changed' });
|
|
281
|
-
expect(get(tracker.isDirty)).toBe(true);
|
|
282
|
-
|
|
283
|
-
tracker.reset({ name: 'new' });
|
|
284
|
-
expect(get(tracker.isDirty)).toBe(false);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('uses new initial data for subsequent checks', () => {
|
|
288
|
-
const tracker = createDirtyTracker({ name: 'test' });
|
|
289
|
-
tracker.reset({ name: 'new' });
|
|
290
|
-
|
|
291
|
-
const result = tracker.check({ name: 'test' });
|
|
292
|
-
expect(result).toBe(true);
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.spec.d.ts","sourceRoot":"","sources":["../../src/lib/stores/navigation.spec.js"],"names":[],"mappings":""}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { get } from 'svelte/store';
|
|
3
|
-
import {
|
|
4
|
-
isSubPage,
|
|
5
|
-
hideHeaderBackButton,
|
|
6
|
-
selectedVenueData,
|
|
7
|
-
isAnimatedNavigation,
|
|
8
|
-
} from './navigation';
|
|
9
|
-
|
|
10
|
-
describe('navigation store', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
// Reset all stores to default values
|
|
13
|
-
isSubPage.set(false);
|
|
14
|
-
hideHeaderBackButton.set(false);
|
|
15
|
-
selectedVenueData.set(null);
|
|
16
|
-
isAnimatedNavigation.set(false);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('isSubPage', () => {
|
|
20
|
-
it('defaults to false', () => {
|
|
21
|
-
expect(get(isSubPage)).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('can be set to true', () => {
|
|
25
|
-
isSubPage.set(true);
|
|
26
|
-
expect(get(isSubPage)).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('can toggle between values', () => {
|
|
30
|
-
isSubPage.set(true);
|
|
31
|
-
expect(get(isSubPage)).toBe(true);
|
|
32
|
-
isSubPage.set(false);
|
|
33
|
-
expect(get(isSubPage)).toBe(false);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('hideHeaderBackButton', () => {
|
|
38
|
-
it('defaults to false', () => {
|
|
39
|
-
expect(get(hideHeaderBackButton)).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('can be set to true', () => {
|
|
43
|
-
hideHeaderBackButton.set(true);
|
|
44
|
-
expect(get(hideHeaderBackButton)).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('allows pages to hide the back button', () => {
|
|
48
|
-
// Simulate a page setting this
|
|
49
|
-
hideHeaderBackButton.set(true);
|
|
50
|
-
expect(get(hideHeaderBackButton)).toBe(true);
|
|
51
|
-
|
|
52
|
-
// And resetting it when leaving
|
|
53
|
-
hideHeaderBackButton.set(false);
|
|
54
|
-
expect(get(hideHeaderBackButton)).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('selectedVenueData', () => {
|
|
59
|
-
it('defaults to null', () => {
|
|
60
|
-
expect(get(selectedVenueData)).toBe(null);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('can store venue data', () => {
|
|
64
|
-
const venueData = {
|
|
65
|
-
id: 123,
|
|
66
|
-
name: 'Comedy Club',
|
|
67
|
-
address: '123 Main St',
|
|
68
|
-
};
|
|
69
|
-
selectedVenueData.set(venueData);
|
|
70
|
-
expect(get(selectedVenueData)).toEqual(venueData);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('can be cleared', () => {
|
|
74
|
-
selectedVenueData.set({ id: 123 });
|
|
75
|
-
selectedVenueData.set(null);
|
|
76
|
-
expect(get(selectedVenueData)).toBe(null);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('can update venue data', () => {
|
|
80
|
-
selectedVenueData.set({ id: 123, name: 'Club A' });
|
|
81
|
-
selectedVenueData.update((data) => ({ ...data, name: 'Club B' }));
|
|
82
|
-
expect(get(selectedVenueData).name).toBe('Club B');
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('isAnimatedNavigation', () => {
|
|
87
|
-
it('defaults to false', () => {
|
|
88
|
-
expect(get(isAnimatedNavigation)).toBe(false);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('can be set to true for animated transitions', () => {
|
|
92
|
-
isAnimatedNavigation.set(true);
|
|
93
|
-
expect(get(isAnimatedNavigation)).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('distinguishes between refresh and navigation', () => {
|
|
97
|
-
// On direct load/refresh, this should be false
|
|
98
|
-
expect(get(isAnimatedNavigation)).toBe(false);
|
|
99
|
-
|
|
100
|
-
// When navigating via JS, set to true before navigation
|
|
101
|
-
isAnimatedNavigation.set(true);
|
|
102
|
-
expect(get(isAnimatedNavigation)).toBe(true);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe('store subscriptions', () => {
|
|
107
|
-
it('notifies subscribers of isSubPage changes', () => {
|
|
108
|
-
const values = [];
|
|
109
|
-
const unsubscribe = isSubPage.subscribe((value) => values.push(value));
|
|
110
|
-
|
|
111
|
-
isSubPage.set(true);
|
|
112
|
-
isSubPage.set(false);
|
|
113
|
-
|
|
114
|
-
unsubscribe();
|
|
115
|
-
|
|
116
|
-
expect(values).toEqual([false, true, false]);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('notifies subscribers of selectedVenueData changes', () => {
|
|
120
|
-
const values = [];
|
|
121
|
-
const unsubscribe = selectedVenueData.subscribe((value) => values.push(value));
|
|
122
|
-
|
|
123
|
-
selectedVenueData.set({ id: 1 });
|
|
124
|
-
selectedVenueData.set({ id: 2 });
|
|
125
|
-
selectedVenueData.set(null);
|
|
126
|
-
|
|
127
|
-
unsubscribe();
|
|
128
|
-
|
|
129
|
-
expect(values.length).toBe(4);
|
|
130
|
-
expect(values[0]).toBe(null);
|
|
131
|
-
expect(values[1]).toEqual({ id: 1 });
|
|
132
|
-
expect(values[2]).toEqual({ id: 2 });
|
|
133
|
-
expect(values[3]).toBe(null);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|