mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
refactor: drive share, location and scene controls through product state
This commit is contained in:
1 parent
21a0d0c74e
commit
45d97376d0
21 files changed
+606
-96
No files matched your search
@@ -108,3 +108,64 @@ test('empty queries and refused navigation do not issue a lookup', async () => {
|
||||
assert.equal(f.requests.length, 0);
|
||||
assert.ok(f.calls.some((x) => x[0] === 'blur'));
|
||||
});
|
||||
|
||||
|
||||
test('search snapshots retain the current busy owner when an older request settles', async () => {
|
||||
const f = fixture();
|
||||
const events = [];
|
||||
f.search.subscribe((event) => events.push(event));
|
||||
assert.equal(events[0].state.status, 'idle');
|
||||
const first = f.search.run('First');
|
||||
const second = f.search.run('Second');
|
||||
f.requests[0].resolve({ label: 'First' });
|
||||
await first;
|
||||
const settled = events.at(-1);
|
||||
assert.equal(settled.change.generation, 1);
|
||||
assert.equal(settled.state.generation, 2);
|
||||
assert.equal(settled.state.searching, true);
|
||||
f.requests[1].resolve({ label: 'Second', lat: 1, lng: 2 });
|
||||
await second;
|
||||
const found = events.filter((event) => event.change?.type === 'found');
|
||||
assert.equal(found.length, 1);
|
||||
assert.equal(found[0].state.query, 'Second');
|
||||
assert.throws(() => { found[0].state.destination.label = 'Changed'; }, TypeError);
|
||||
assert.equal(f.search.getState().destination.label, 'Second');
|
||||
assert.equal(f.search.getState().searching, false);
|
||||
const count = events.length;
|
||||
f.search.destroy();
|
||||
assert.equal(f.search.getState().status, 'disposed');
|
||||
f.search.subscribe(() => events.push('late'));
|
||||
assert.equal(events.length, count);
|
||||
});
|
||||
|
||||
test('a subscriber that destroys a started lookup prevents the provider from being called', async () => {
|
||||
const f = fixture();
|
||||
f.search.subscribe(({ change }) => {
|
||||
if (change?.type === 'started') f.search.destroy();
|
||||
});
|
||||
await f.search.run('Place');
|
||||
assert.equal(f.requests.length, 0);
|
||||
assert.equal(f.search.controller, null);
|
||||
});
|
||||
|
||||
test('a reentrant replacement in a result callback cannot publish the obsolete result over the new query', async () => {
|
||||
const f = fixture();
|
||||
let replacement;
|
||||
const found = [];
|
||||
f.search.subscribe(({ state, change }) => {
|
||||
if (change?.type === 'found') found.push(state.query);
|
||||
});
|
||||
f.search.onResult = () => {
|
||||
f.search.onResult = null;
|
||||
replacement = f.search.run('Second');
|
||||
};
|
||||
const first = f.search.run('First');
|
||||
f.requests[0].resolve({ label: 'First' });
|
||||
await first;
|
||||
assert.equal(f.search.getState().query, 'Second');
|
||||
assert.equal(f.search.getState().searching, true);
|
||||
assert.deepEqual(found, []);
|
||||
f.requests[1].resolve({ label: 'Second' });
|
||||
await replacement;
|
||||
assert.deepEqual(found, ['Second']);
|
||||
});
|
||||
Reference in new issue
Block a user