mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Never let a share rewrite the Data Library entries remembered as on
Every restore wrote the selection it applied to browser storage, so opening a link that switched no library entry on stored every saved entry as off, and the next bare visit restored them off. Core layer state never writes a recipient's preferences from a share. The library now keeps what is remembered as on apart from what a share switches on for the session: a share's entries still join the library, but only a local restore and the viewer's own choices change what is remembered.
This commit is contained in:
1 parent
53f0a32a1b
commit
2d5db9f63d
2 files changed
+60
-7
No files matched your search
@@ -201,12 +201,48 @@ test('a link decides what is on and adds its entries to the library', async (t)
|
||||
await manager.waitForLayerSettled?.('lib-sea-marks');
|
||||
assert.equal(manager.isEnabled('lib-sea-marks'), true);
|
||||
assert.equal(manager.isEnabled('lib-night-lights'), false);
|
||||
// The link's entry joins the library; what is remembered as on stays
|
||||
// the viewer's own.
|
||||
assert.deepEqual(JSON.parse(storage.store.get(LIBRARY_STORAGE_KEY)), {
|
||||
added: ['night-lights', 'sea-marks'],
|
||||
on: ['sea-marks'],
|
||||
on: ['night-lights'],
|
||||
});
|
||||
});
|
||||
|
||||
test('a share never rewrites what this browser remembers as on', async (t) => {
|
||||
const saved = JSON.stringify({
|
||||
added: ['night-lights', 'sea-marks'],
|
||||
on: ['night-lights'],
|
||||
});
|
||||
const storage = memoryStorage(saved);
|
||||
const manager = sealedManager(t);
|
||||
const shareLink = fakeShareLink([]);
|
||||
const library = createDataLibrary({
|
||||
entries,
|
||||
ledger,
|
||||
dataManager: manager,
|
||||
services: {},
|
||||
storage,
|
||||
shareLink,
|
||||
source: source({}),
|
||||
});
|
||||
await library.start();
|
||||
assert.equal(manager.isEnabled('lib-night-lights'), false);
|
||||
shareLink.listener(['01']);
|
||||
await manager.waitForLayerSettled?.('lib-sea-marks');
|
||||
assert.equal(manager.isEnabled('lib-sea-marks'), true);
|
||||
assert.deepEqual(JSON.parse(storage.store.get(LIBRARY_STORAGE_KEY)), {
|
||||
added: ['night-lights', 'sea-marks'],
|
||||
on: ['night-lights'],
|
||||
});
|
||||
// An explicit choice is remembered, and only that one.
|
||||
await manager.setEnabled('lib-sea-marks', false, { origin: 'user' });
|
||||
await manager.setEnabled('lib-night-lights', true, { origin: 'user' });
|
||||
await manager.setEnabled('lib-night-lights', false, { origin: 'user' });
|
||||
assert.deepEqual(JSON.parse(storage.store.get(LIBRARY_STORAGE_KEY)).on, []);
|
||||
library.destroy();
|
||||
});
|
||||
|
||||
/** A ShareLinkManager stand-in: the opening share and in-tab navigation. */
|
||||
function fakeShareLink(initialLibraryTokens) {
|
||||
const link = {
|
||||
|
||||
Reference in new issue
Block a user