-
Notifications
You must be signed in to change notification settings - Fork 960
Expand file tree
/
Copy pathapiFileManagerObjectUrls.test.ts
More file actions
56 lines (52 loc) · 1.73 KB
/
Copy pathapiFileManagerObjectUrls.test.ts
File metadata and controls
56 lines (52 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import deferredPromise from '@helpers/cancellablePromise';
import {ApiFileManager} from '@appManagers/apiFileManager';
function makeManager({
getCacheContext,
setCacheContextBlob,
download
}: {
getCacheContext: () => {downloaded: number, type: string, url: string},
setCacheContextBlob: (media: any, type: string, blob: Blob) => {downloaded: number, type: string, url: string},
download: Promise<Blob>
}) {
const manager = Object.create(ApiFileManager.prototype) as ApiFileManager;
(manager as any).thumbsStorage = {
getCacheContext,
setCacheContextBlob
};
manager.downloadMedia = vi.fn(() => download) as any;
return manager;
}
describe('ApiFileManager object URLs', () => {
it('re-reads the canonical context before concurrent downloads create a URL', async() => {
const media = {_: 'document', id: 'concurrent'} as any;
const blob = new Blob(['downloaded']);
const download = deferredPromise<Blob>();
let canonical: {downloaded: number, type: string, url: string};
const getCacheContext = vi.fn(() => canonical || {
downloaded: 0,
type: '',
url: ''
});
const setCacheContextBlob = vi.fn((media, type, blob: Blob) => {
return canonical = {
downloaded: blob.size,
type,
url: 'blob:test/concurrent'
};
});
const manager = makeManager({
download,
getCacheContext,
setCacheContextBlob
});
const first = manager.downloadMediaURL({media});
const second = manager.downloadMediaURL({media});
download.resolve(blob);
await expect(Promise.all([first, second])).resolves.toEqual([
'blob:test/concurrent',
'blob:test/concurrent'
]);
expect(setCacheContextBlob).toHaveBeenCalledOnce();
});
});