@shellui/core 0.3.0 → 0.4.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/package.json +2 -2
- package/src/app.tsx +31 -3
- package/src/components/ui/dialog.tsx +26 -6
- package/src/components/ui/sonner.tsx +9 -5
- package/src/features/admin/AdminView.tsx +5 -49
- package/src/features/admin/config.ts +15 -0
- package/src/features/admin/index.ts +4 -0
- package/src/features/admin/routes.tsx +14 -0
- package/src/features/admin/utils.ts +79 -0
- package/src/features/auth/AuthProvider.tsx +68 -13
- package/src/features/auth/backends/shellui.ts +8 -1
- package/src/features/auth/components/AccessPendingView.tsx +112 -0
- package/src/features/auth/components/LoginButton.tsx +5 -10
- package/src/features/auth/components/LoginView.tsx +20 -2
- package/src/features/auth/components/OAuthCallbackView.tsx +211 -50
- package/src/features/auth/hooks/useAuth.tsx +8 -1
- package/src/features/auth/utils/authRequestError.spec.ts +52 -0
- package/src/features/auth/utils/authRequestError.ts +45 -0
- package/src/features/auth/utils/buildAuthUrlWithNext.spec.ts +18 -0
- package/src/features/auth/utils/buildAuthUrlWithNext.ts +12 -0
- package/src/features/auth/utils/index.ts +8 -0
- package/src/features/auth/utils/isTokenAutoRefreshDisabled.spec.ts +71 -0
- package/src/features/auth/utils/isTokenAutoRefreshDisabled.ts +18 -0
- package/src/features/config/ConfigProvider.ts +1 -1
- package/src/features/config/types.ts +46 -5
- package/src/features/layouts/AppLayout.tsx +3 -3
- package/src/features/layouts/OverlayShell.tsx +17 -28
- package/src/features/layouts/resolveSdkNavigatePath.spec.ts +55 -0
- package/src/features/layouts/resolveSdkNavigatePath.ts +68 -0
- package/src/features/settings/SettingsIcons.tsx +35 -0
- package/src/features/settings/SettingsProvider.tsx +79 -10
- package/src/features/settings/SettingsRoutes.tsx +14 -6
- package/src/features/settings/SettingsView.tsx +11 -5
- package/src/features/settings/components/Advanced.tsx +117 -44
- package/src/features/settings/components/Develop.tsx +38 -0
- package/src/features/settings/components/ServiceWorker.tsx +52 -25
- package/src/features/settings/components/Storage.tsx +138 -0
- package/src/features/settings/components/UpdateApp.tsx +1 -1
- package/src/features/settings/components/develop/StoragePickerTestButtons.tsx +148 -0
- package/src/features/settings/components/develop/UploadToastTestButton.tsx +29 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +55 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +34 -0
- package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +1 -1
- package/src/features/settings/utils/toSettingsUser.spec.ts +4 -0
- package/src/features/settings/utils/toSettingsUser.ts +2 -0
- package/src/features/sonner/SonnerContext.tsx +44 -60
- package/src/features/storage/StorageBridge.tsx +50 -0
- package/src/features/storage/StoragePickerContext.tsx +214 -0
- package/src/features/storage/api.spec.ts +303 -0
- package/src/features/storage/api.ts +414 -0
- package/src/features/storage/handleRequest.spec.ts +88 -0
- package/src/features/storage/handleRequest.ts +53 -0
- package/src/features/storage/quota.spec.ts +151 -0
- package/src/features/storage/quota.ts +104 -0
- package/src/features/storage/uploads/UploadToastCard.tsx +442 -0
- package/src/features/storage/uploads/UploadToaster.tsx +41 -0
- package/src/features/storage/uploads/handleTrackedUpload.spec.ts +170 -0
- package/src/features/storage/uploads/handleTrackedUpload.ts +97 -0
- package/src/features/storage/uploads/types.ts +24 -0
- package/src/features/storage/uploads/uploadQueue.spec.ts +118 -0
- package/src/features/storage/uploads/uploadQueue.ts +349 -0
- package/src/features/storage/uploads/useUploadQueue.ts +30 -0
- package/src/i18n/translations/en/common.json +33 -0
- package/src/i18n/translations/en/settings.json +56 -4
- package/src/i18n/translations/fr/common.json +33 -0
- package/src/i18n/translations/fr/settings.json +56 -4
- package/src/index.css +2 -1
- package/src/index.ts +2 -0
- package/src/lib/z-index.ts +9 -3
- package/src/routes/components/NavigationItemRoute.tsx +2 -1
- package/src/routes/routes.tsx +2 -13
- package/src/service-worker/register.ts +217 -101
- package/src/service-worker/sw-dev.ts +5 -1
- package/src/service-worker/sw.ts +5 -1
- package/src/shellui-target.d.ts +2 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { FOLDER_PLACEHOLDER } from '../api';
|
|
3
|
+
import { getUploadQueue, interruptUpload, resetUploadQueue } from './uploadQueue';
|
|
4
|
+
import { getUploadDisplayName, handleTrackedUpload } from './handleTrackedUpload';
|
|
5
|
+
|
|
6
|
+
class MockXHR {
|
|
7
|
+
static last: MockXHR | null = null;
|
|
8
|
+
status = 0;
|
|
9
|
+
statusText = '';
|
|
10
|
+
responseText = '';
|
|
11
|
+
upload: {
|
|
12
|
+
onprogress:
|
|
13
|
+
| ((event: { lengthComputable: boolean; loaded: number; total: number }) => void)
|
|
14
|
+
| null;
|
|
15
|
+
} = {
|
|
16
|
+
onprogress: null,
|
|
17
|
+
};
|
|
18
|
+
onload: (() => void) | null = null;
|
|
19
|
+
onerror: (() => void) | null = null;
|
|
20
|
+
onabort: (() => void) | null = null;
|
|
21
|
+
headers: Record<string, string> = {};
|
|
22
|
+
body: unknown = null;
|
|
23
|
+
aborted = false;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
MockXHR.last = this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
open(): void {}
|
|
30
|
+
|
|
31
|
+
setRequestHeader(key: string, value: string): void {
|
|
32
|
+
this.headers[key] = value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
send(body: unknown): void {
|
|
36
|
+
this.body = body;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
abort(): void {
|
|
40
|
+
this.aborted = true;
|
|
41
|
+
this.onabort?.();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('handleTrackedUpload', () => {
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
resetUploadQueue();
|
|
48
|
+
vi.unstubAllGlobals();
|
|
49
|
+
MockXHR.last = null;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('derives a display name from the path when the blob has no name', () => {
|
|
53
|
+
expect(getUploadDisplayName('docs/reports/q1.pdf', new Blob(['x']))).toBe('q1.pdf');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('skips the toast for folder placeholder uploads', async () => {
|
|
57
|
+
vi.stubGlobal(
|
|
58
|
+
'fetch',
|
|
59
|
+
vi.fn().mockResolvedValue({
|
|
60
|
+
ok: true,
|
|
61
|
+
status: 200,
|
|
62
|
+
headers: new Headers(),
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
await expect(
|
|
66
|
+
handleTrackedUpload({
|
|
67
|
+
storageUrl: 'http://localhost:8001',
|
|
68
|
+
accessToken: 'token',
|
|
69
|
+
payload: {
|
|
70
|
+
id: 'folder-1',
|
|
71
|
+
op: 'upload',
|
|
72
|
+
bucket: 'company',
|
|
73
|
+
path: `docs/${FOLDER_PLACEHOLDER}`,
|
|
74
|
+
file: new Blob([]),
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
).resolves.toEqual({ id: 'folder-1', data: { path: `docs/${FOLDER_PLACEHOLDER}` } });
|
|
78
|
+
expect(getUploadQueue()).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('records progress then success on the upload queue', async () => {
|
|
82
|
+
vi.stubGlobal('XMLHttpRequest', MockXHR);
|
|
83
|
+
const file = new Blob(['hello-world']);
|
|
84
|
+
const pending = handleTrackedUpload({
|
|
85
|
+
storageUrl: 'http://localhost:8001',
|
|
86
|
+
accessToken: 'token',
|
|
87
|
+
payload: {
|
|
88
|
+
id: 'up-1',
|
|
89
|
+
op: 'upload',
|
|
90
|
+
bucket: 'company',
|
|
91
|
+
path: 'docs/notes.txt',
|
|
92
|
+
file,
|
|
93
|
+
upsert: true,
|
|
94
|
+
contentType: 'text/plain',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const xhr = MockXHR.last;
|
|
99
|
+
expect(xhr).toBeTruthy();
|
|
100
|
+
if (!xhr) {
|
|
101
|
+
throw new Error('expected XMLHttpRequest');
|
|
102
|
+
}
|
|
103
|
+
expect(xhr.headers.Authorization).toBe('Bearer token');
|
|
104
|
+
expect(xhr.headers['Content-Type']).toBe('text/plain');
|
|
105
|
+
expect(xhr.headers['x-upsert']).toBe('true');
|
|
106
|
+
xhr.upload.onprogress?.({ lengthComputable: true, loaded: 4, total: 11 });
|
|
107
|
+
expect(getUploadQueue()[0]).toMatchObject({
|
|
108
|
+
id: 'up-1',
|
|
109
|
+
name: 'notes.txt',
|
|
110
|
+
status: 'uploading',
|
|
111
|
+
bytesUploaded: 4,
|
|
112
|
+
size: 11,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
xhr.status = 200;
|
|
116
|
+
xhr.onload?.();
|
|
117
|
+
await expect(pending).resolves.toEqual({ id: 'up-1', data: { path: 'docs/notes.txt' } });
|
|
118
|
+
expect(getUploadQueue()[0].status).toBe('success');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('maps http failures onto the queue and response', async () => {
|
|
122
|
+
vi.stubGlobal('XMLHttpRequest', MockXHR);
|
|
123
|
+
const pending = handleTrackedUpload({
|
|
124
|
+
storageUrl: 'http://localhost:8001',
|
|
125
|
+
accessToken: 'token',
|
|
126
|
+
payload: {
|
|
127
|
+
id: 'up-2',
|
|
128
|
+
op: 'upload',
|
|
129
|
+
bucket: 'company',
|
|
130
|
+
path: 'docs/notes.txt',
|
|
131
|
+
file: new Blob(['x']),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const xhr = MockXHR.last;
|
|
135
|
+
expect(xhr).toBeTruthy();
|
|
136
|
+
if (!xhr) {
|
|
137
|
+
throw new Error('expected XMLHttpRequest');
|
|
138
|
+
}
|
|
139
|
+
xhr.status = 403;
|
|
140
|
+
xhr.statusText = 'Forbidden';
|
|
141
|
+
xhr.responseText = JSON.stringify({ message: 'Denied' });
|
|
142
|
+
xhr.onload?.();
|
|
143
|
+
await expect(pending).resolves.toEqual({
|
|
144
|
+
id: 'up-2',
|
|
145
|
+
error: { message: 'Denied', status: 403 },
|
|
146
|
+
});
|
|
147
|
+
expect(getUploadQueue()[0]).toMatchObject({ status: 'error', error: 'Denied' });
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('returns a cancelled error when the user interrupts the upload', async () => {
|
|
151
|
+
vi.stubGlobal('XMLHttpRequest', MockXHR);
|
|
152
|
+
const pending = handleTrackedUpload({
|
|
153
|
+
storageUrl: 'http://localhost:8001',
|
|
154
|
+
accessToken: 'token',
|
|
155
|
+
payload: {
|
|
156
|
+
id: 'up-3',
|
|
157
|
+
op: 'upload',
|
|
158
|
+
bucket: 'company',
|
|
159
|
+
path: 'docs/notes.txt',
|
|
160
|
+
file: new Blob(['x']),
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
interruptUpload('up-3');
|
|
164
|
+
await expect(pending).resolves.toEqual({
|
|
165
|
+
id: 'up-3',
|
|
166
|
+
error: { message: 'Upload cancelled', status: 499, code: 'cancelled' },
|
|
167
|
+
});
|
|
168
|
+
expect(getUploadQueue()[0]).toMatchObject({ id: 'up-3', status: 'cancelled' });
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { StorageRequestPayload, StorageResponsePayload } from '@shellui/sdk';
|
|
2
|
+
import { isFolderPlaceholderPath, StorageHttpError, uploadObjectWithProgress } from '../api';
|
|
3
|
+
import { handleStorageRequest, type HandleStorageRequestInput } from '../handleRequest';
|
|
4
|
+
import {
|
|
5
|
+
addUpload,
|
|
6
|
+
completeUpload,
|
|
7
|
+
failUpload,
|
|
8
|
+
isUploadSignalAborted,
|
|
9
|
+
setUploadProgress,
|
|
10
|
+
} from './uploadQueue';
|
|
11
|
+
|
|
12
|
+
export function getUploadDisplayName(path: string, file: Blob): string {
|
|
13
|
+
if (typeof File !== 'undefined' && file instanceof File && file.name) {
|
|
14
|
+
return file.name;
|
|
15
|
+
}
|
|
16
|
+
const segment = path
|
|
17
|
+
.replace(/^\/+|\/+$/g, '')
|
|
18
|
+
.split('/')
|
|
19
|
+
.pop();
|
|
20
|
+
return segment || path;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toErrorPayload(err: unknown): StorageResponsePayload['error'] {
|
|
24
|
+
if (err instanceof StorageHttpError) {
|
|
25
|
+
return { message: err.message, status: err.status, code: err.code };
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
message: err instanceof Error ? err.message : 'Request failed',
|
|
29
|
+
status: 500,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Runs a storage upload with toaster progress. Folder placeholders skip the toast.
|
|
35
|
+
* Uploads keep running at ShellUI root regardless of route changes.
|
|
36
|
+
*/
|
|
37
|
+
export async function handleTrackedUpload(
|
|
38
|
+
input: HandleStorageRequestInput,
|
|
39
|
+
): Promise<StorageResponsePayload> {
|
|
40
|
+
const { storageUrl, accessToken, payload } = input;
|
|
41
|
+
if (payload.op !== 'upload') {
|
|
42
|
+
return handleStorageRequest(input);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isFolderPlaceholderPath(payload.path)) {
|
|
46
|
+
return handleStorageRequest(input);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!storageUrl || !accessToken || !payload.id) {
|
|
50
|
+
return handleStorageRequest(input);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const file = payload.file;
|
|
54
|
+
const { id, signal } = addUpload({
|
|
55
|
+
id: payload.id,
|
|
56
|
+
name: getUploadDisplayName(payload.path, file),
|
|
57
|
+
path: payload.path,
|
|
58
|
+
bucket: payload.bucket,
|
|
59
|
+
size: file.size || 0,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const data = await uploadObjectWithProgress(
|
|
64
|
+
storageUrl,
|
|
65
|
+
accessToken,
|
|
66
|
+
payload.bucket,
|
|
67
|
+
payload.path,
|
|
68
|
+
file,
|
|
69
|
+
{
|
|
70
|
+
upsert: payload.upsert,
|
|
71
|
+
contentType: payload.contentType,
|
|
72
|
+
signal,
|
|
73
|
+
onProgress: (loaded, total) => setUploadProgress(id, loaded, total),
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
if (!isUploadSignalAborted(id, signal)) {
|
|
77
|
+
completeUpload(id);
|
|
78
|
+
}
|
|
79
|
+
return { id: payload.id, data };
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (isUploadSignalAborted(id, signal)) {
|
|
82
|
+
return {
|
|
83
|
+
id: payload.id,
|
|
84
|
+
error: { message: 'Upload cancelled', status: 499, code: 'cancelled' },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const error = toErrorPayload(err);
|
|
88
|
+
failUpload(id, error?.message || 'Upload failed');
|
|
89
|
+
return { id: payload.id, error };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function isUploadPayload(
|
|
94
|
+
payload: StorageRequestPayload | undefined,
|
|
95
|
+
): payload is Extract<StorageRequestPayload, { op: 'upload' }> {
|
|
96
|
+
return payload?.op === 'upload';
|
|
97
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type UploadItemStatus = 'uploading' | 'success' | 'error' | 'cancelled';
|
|
2
|
+
|
|
3
|
+
export type UploadItem = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
bucket: string;
|
|
8
|
+
size: number;
|
|
9
|
+
bytesUploaded: number;
|
|
10
|
+
status: UploadItemStatus;
|
|
11
|
+
error?: string;
|
|
12
|
+
demo?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type UploadQueueSummary = {
|
|
16
|
+
total: number;
|
|
17
|
+
uploading: number;
|
|
18
|
+
success: number;
|
|
19
|
+
error: number;
|
|
20
|
+
cancelled: number;
|
|
21
|
+
bytesUploaded: number;
|
|
22
|
+
bytesTotal: number;
|
|
23
|
+
percent: number;
|
|
24
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
addUpload,
|
|
4
|
+
closeUploadToaster,
|
|
5
|
+
completeUpload,
|
|
6
|
+
dismissFinishedUploads,
|
|
7
|
+
failUpload,
|
|
8
|
+
getItemPercent,
|
|
9
|
+
getUploadQueue,
|
|
10
|
+
getUploadSummary,
|
|
11
|
+
interruptAllUploads,
|
|
12
|
+
interruptUpload,
|
|
13
|
+
removeUpload,
|
|
14
|
+
resetUploadQueue,
|
|
15
|
+
setUploadProgress,
|
|
16
|
+
setUploadToastExpanded,
|
|
17
|
+
isUploadToastExpanded,
|
|
18
|
+
} from './uploadQueue';
|
|
19
|
+
|
|
20
|
+
describe('uploadQueue', () => {
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
resetUploadQueue();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('tracks progress and overall percent across files', () => {
|
|
26
|
+
addUpload({
|
|
27
|
+
id: 'a',
|
|
28
|
+
name: 'a.pdf',
|
|
29
|
+
path: 'a.pdf',
|
|
30
|
+
bucket: 'company',
|
|
31
|
+
size: 100,
|
|
32
|
+
});
|
|
33
|
+
addUpload({
|
|
34
|
+
id: 'b',
|
|
35
|
+
name: 'b.pdf',
|
|
36
|
+
path: 'b.pdf',
|
|
37
|
+
bucket: 'company',
|
|
38
|
+
size: 100,
|
|
39
|
+
});
|
|
40
|
+
setUploadProgress('a', 50, 100);
|
|
41
|
+
completeUpload('b');
|
|
42
|
+
|
|
43
|
+
const summary = getUploadSummary();
|
|
44
|
+
expect(summary.total).toBe(2);
|
|
45
|
+
expect(summary.uploading).toBe(1);
|
|
46
|
+
expect(summary.success).toBe(1);
|
|
47
|
+
expect(summary.percent).toBe(75);
|
|
48
|
+
expect(getItemPercent(getUploadQueue()[0])).toBe(50);
|
|
49
|
+
expect(getItemPercent(getUploadQueue()[1])).toBe(100);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('interrupts an in-progress upload and keeps it as cancelled', () => {
|
|
53
|
+
const { signal } = addUpload({
|
|
54
|
+
id: 'a',
|
|
55
|
+
name: 'a.pdf',
|
|
56
|
+
path: 'a.pdf',
|
|
57
|
+
bucket: 'company',
|
|
58
|
+
size: 10,
|
|
59
|
+
});
|
|
60
|
+
interruptUpload('a');
|
|
61
|
+
expect(signal.aborted).toBe(true);
|
|
62
|
+
expect(getUploadQueue()).toMatchObject([{ id: 'a', status: 'cancelled' }]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('dismisses finished uploads and keeps in-progress ones', () => {
|
|
66
|
+
addUpload({ id: 'up', name: 'up.pdf', path: 'up.pdf', bucket: 'company', size: 10 });
|
|
67
|
+
addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
|
|
68
|
+
addUpload({ id: 'bad', name: 'bad.pdf', path: 'bad.pdf', bucket: 'company', size: 10 });
|
|
69
|
+
completeUpload('ok');
|
|
70
|
+
failUpload('bad', 'Denied');
|
|
71
|
+
dismissFinishedUploads();
|
|
72
|
+
expect(getUploadQueue().map((item) => item.id)).toEqual(['up']);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('cancels every in-progress upload and leaves them visible as cancelled', () => {
|
|
76
|
+
addUpload({ id: 'up', name: 'up.pdf', path: 'up.pdf', bucket: 'company', size: 10 });
|
|
77
|
+
addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
|
|
78
|
+
completeUpload('ok');
|
|
79
|
+
interruptAllUploads();
|
|
80
|
+
expect(getUploadQueue().map((item) => ({ id: item.id, status: item.status }))).toEqual([
|
|
81
|
+
{ id: 'up', status: 'cancelled' },
|
|
82
|
+
{ id: 'ok', status: 'success' },
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('does not count failed bytes toward overall percent', () => {
|
|
87
|
+
addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 100 });
|
|
88
|
+
addUpload({ id: 'bad', name: 'bad.pdf', path: 'bad.pdf', bucket: 'company', size: 100 });
|
|
89
|
+
completeUpload('ok');
|
|
90
|
+
setUploadProgress('bad', 80, 100);
|
|
91
|
+
failUpload('bad', 'Denied');
|
|
92
|
+
expect(getUploadSummary().percent).toBe(50);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('resets expanded state when the queue is emptied', () => {
|
|
96
|
+
addUpload({ id: 'a', name: 'a.pdf', path: 'a.pdf', bucket: 'company', size: 1 });
|
|
97
|
+
setUploadToastExpanded(true);
|
|
98
|
+
expect(isUploadToastExpanded()).toBe(true);
|
|
99
|
+
removeUpload('a');
|
|
100
|
+
expect(isUploadToastExpanded()).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('closes the toaster by cancelling leftover uploads', () => {
|
|
104
|
+
const { signal } = addUpload({
|
|
105
|
+
id: 'up',
|
|
106
|
+
name: 'up.pdf',
|
|
107
|
+
path: 'up.pdf',
|
|
108
|
+
bucket: 'company',
|
|
109
|
+
size: 10,
|
|
110
|
+
});
|
|
111
|
+
addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
|
|
112
|
+
completeUpload('ok');
|
|
113
|
+
closeUploadToaster();
|
|
114
|
+
expect(signal.aborted).toBe(true);
|
|
115
|
+
expect(getUploadQueue()).toEqual([]);
|
|
116
|
+
expect(isUploadToastExpanded()).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
});
|