mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Street Level photo viewer: settle opens, a gapless picker, a stated contract
Follow-ups to the photo viewer's move to a Vue view (#1868): - A panorama's open waits for a draw of the canvas counted from before it is shown, so a view that draws at once inside its listener no longer leaves the open pending; and when the last view unsubscribes, an open waiting on a draw goes on instead of hanging. - photoViewers.js supersedes the mounts not drawn on a microtask, after the winning presentation has reached every subscriber: a second subscriber sees the earlier mount, then the later one, never null between. - A presentation without a mountKey counts as the latest mount (among several without, the one that began presenting last), and one without actions or supersede is passed over without throwing. Both fields are documented on ViewerAdapter.subscribeView in registry.js and in the store's comment. - The guard test also refuses .width, .height, .ariaLabel, .id and .value writes in photoViewer.js, and .src writes outside loadImage, where only the off-page Image it creates may take one. - The test fakes draw every viewer through one shared view behind photoViewers.js's picker, as the application does, so provider and layer tests see supersede. Nothing changes in the running app. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
12dc0de20d
commit
33ac0545ef
9 files changed
+337
-49
No files matched your search
@@ -29,7 +29,7 @@ function fakeViewer() {
|
||||
return viewer;
|
||||
}
|
||||
|
||||
test('the later mount is drawn, whatever order the viewers present in', () => {
|
||||
test('the later mount is drawn, whatever order the viewers present in', async () => {
|
||||
const a = fakeViewer();
|
||||
const b = fakeViewer();
|
||||
const shown = [];
|
||||
@@ -40,6 +40,8 @@ test('the later mount is drawn, whatever order the viewers present in', () => {
|
||||
const later = b.view(2);
|
||||
b.present(later);
|
||||
assert.equal(shown.at(-1), later);
|
||||
// Once every subscriber has the later one.
|
||||
await Promise.resolve();
|
||||
assert.equal(a.superseded, 1, 'the earlier mount is told it is not drawn');
|
||||
// The earlier viewer presents again: it does not take the view back.
|
||||
a.present({ ...first, kind: 'flat' });
|
||||
@@ -53,3 +55,79 @@ test('the later mount is drawn, whatever order the viewers present in', () => {
|
||||
a.present(first);
|
||||
assert.equal(shown.length, 5, 'unsubscribed');
|
||||
});
|
||||
|
||||
/** A viewer that, superseded, unmounts as photoViewer.js does: it presents null. */
|
||||
function unmountingViewer() {
|
||||
const viewer = fakeViewer();
|
||||
const view = viewer.view;
|
||||
viewer.view = (mountKey) => {
|
||||
const presented = view(mountKey);
|
||||
const supersede = presented.actions.supersede;
|
||||
presented.actions.supersede = () => {
|
||||
supersede();
|
||||
viewer.present(null);
|
||||
};
|
||||
return presented;
|
||||
};
|
||||
return viewer;
|
||||
}
|
||||
|
||||
test('every subscriber sees the earlier mount, then the later one, with no gap', async () => {
|
||||
const a = unmountingViewer();
|
||||
const b = unmountingViewer();
|
||||
const first = [];
|
||||
const second = [];
|
||||
const unsubscribes = [
|
||||
subscribePhotoViewers([a, b], (view) => first.push(view)),
|
||||
subscribePhotoViewers([a, b], (view) => second.push(view)),
|
||||
];
|
||||
const earlier = a.view(1);
|
||||
a.present(earlier);
|
||||
const later = b.view(2);
|
||||
b.present(later);
|
||||
await Promise.resolve();
|
||||
assert.equal(a.superseded, 1, 'superseded once, by both');
|
||||
assert.deepEqual(first, [null, earlier, later]);
|
||||
assert.deepEqual(second, [null, earlier, later], 'never null between');
|
||||
for (const unsubscribe of unsubscribes) unsubscribe();
|
||||
});
|
||||
|
||||
test('a presentation without a mount key counts as the latest mount', () => {
|
||||
const a = fakeViewer();
|
||||
const b = fakeViewer();
|
||||
const c = fakeViewer();
|
||||
const shown = [];
|
||||
const unsubscribe = subscribePhotoViewers([a, b, c], (view) =>
|
||||
shown.push(view),
|
||||
);
|
||||
a.present(a.view(5));
|
||||
const keyless = { actions: {} };
|
||||
b.present(keyless);
|
||||
assert.equal(shown.at(-1), keyless, 'after the keyed one');
|
||||
// A keyed mount presenting later does not take it back.
|
||||
a.present(a.view(6));
|
||||
assert.equal(shown.at(-1), keyless);
|
||||
// Of two without, the one that began presenting last.
|
||||
const newer = { actions: {} };
|
||||
c.present(newer);
|
||||
assert.equal(shown.at(-1), newer);
|
||||
b.present({ ...keyless, kind: 'flat' });
|
||||
assert.equal(shown.at(-1), newer, 'presenting again is not a new mount');
|
||||
unsubscribe();
|
||||
});
|
||||
|
||||
test('a presentation without actions or supersede is drawn and passed over without throwing', async () => {
|
||||
const a = fakeViewer();
|
||||
const b = fakeViewer();
|
||||
const shown = [];
|
||||
const unsubscribe = subscribePhotoViewers([a, b], (view) => shown.push(view));
|
||||
a.present({ mountKey: 1 });
|
||||
const later = { mountKey: 2, actions: {} };
|
||||
assert.doesNotThrow(() => b.present(later));
|
||||
await Promise.resolve();
|
||||
assert.equal(shown.at(-1), later);
|
||||
a.present({ mountKey: 3 });
|
||||
await Promise.resolve();
|
||||
assert.equal(shown.at(-1).mountKey, 3);
|
||||
unsubscribe();
|
||||
});
|
||||
Reference in new issue
Block a user