Multiple improvements
This commit is contained in:
@@ -730,3 +730,35 @@ test('creator identity never falls back to insecure randomness or replaces corru
|
||||
assert.throws(() => api.creatorId(), /Gerätekennung/);
|
||||
assert.equal(localStorage.getItem('wegwichtel.creator-id.v1'), 'broken');
|
||||
});
|
||||
|
||||
|
||||
test('route selection reads metadata only and station media is loaded and released separately', async () => {
|
||||
const { api, context } = await loadLocalRoutes();
|
||||
const reads = [0, 0];
|
||||
const revoked = [];
|
||||
let urlNumber = 0;
|
||||
context.URL.createObjectURL = () => `blob:lazy-${++urlNumber}`;
|
||||
context.URL.revokeObjectURL = url => revoked.push(url);
|
||||
const files = [];
|
||||
for (let id = 0; id < 2; id++) {
|
||||
const file = Object.assign(new Blob(['image']), { name: `${id}.jpg` });
|
||||
const handle = { async getFile() { reads[id]++; return file; } };
|
||||
files.push(await api.storeMediaFile('lazy', id, 'image', id, file, handle));
|
||||
}
|
||||
api.save({ id: 'lazy', route: { name: 'Lazy' }, pois: files.map((image, id) => ({ id, images: [image] })) });
|
||||
await api.getAppRoute('lazy');
|
||||
api.get('lazy');
|
||||
assert.deepEqual(reads, [0, 0]);
|
||||
const first = await api.getPoiWithMedia('lazy', 0, { requestPermission: true });
|
||||
assert.deepEqual(reads, [1, 0]);
|
||||
assert.equal(first.images[0].url, 'blob:lazy-1');
|
||||
const second = await api.getAppPoi('lazy', 1);
|
||||
assert.deepEqual(reads, [1, 1]);
|
||||
assert.equal(second.images[0].url, 'blob:lazy-2');
|
||||
api.releasePoiMedia(first); api.releasePoiMedia(first); api.releasePoiMedia(second);
|
||||
api.releasePoiMedia({ images: [{ url: 'https://example.org/image.jpg' }] });
|
||||
assert.deepEqual(revoked, ['blob:lazy-1', 'blob:lazy-2']);
|
||||
assert.equal(await api.getPoiWithMedia('lazy', 9), null);
|
||||
assert.equal(await api.getAppPoi('missing', 0), null);
|
||||
assert.equal(api.get('lazy').pois[0].images[0].url, undefined);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user