jbrowse-plugin-msaview 3.4.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LaunchMsaView/components/BlastQuery/BlastAutomaticPanel.js +4 -6
- package/dist/LaunchMsaView/components/BlastQuery/searchChoiceStorage.d.ts +7 -0
- package/dist/LaunchMsaView/components/BlastQuery/searchChoiceStorage.js +42 -0
- package/dist/LaunchMsaView/components/BlastQuery/searchChoiceStorage.test.d.ts +1 -0
- package/dist/LaunchMsaView/components/BlastQuery/searchChoiceStorage.test.js +32 -0
- package/dist/LaunchMsaView/components/OrthologQuery/OrthologPanel.js +2 -1
- package/dist/LaunchMsaViewExtensionPoint/index.js +11 -6
- package/dist/LaunchMsaViewExtensionPoint/index.test.d.ts +1 -0
- package/dist/LaunchMsaViewExtensionPoint/index.test.js +43 -0
- package/dist/MsaViewPanel/afterCreateAutoruns.d.ts +15 -0
- package/dist/MsaViewPanel/afterCreateAutoruns.js +93 -70
- package/dist/MsaViewPanel/components/LaunchProgress.js +11 -2
- package/dist/MsaViewPanel/components/MsaViewPanel.test.js +19 -0
- package/dist/MsaViewPanel/doLaunchBlast.d.ts +3 -1
- package/dist/MsaViewPanel/doLaunchBlast.js +10 -12
- package/dist/MsaViewPanel/doLaunchOrthologs.d.ts +3 -1
- package/dist/MsaViewPanel/doLaunchOrthologs.js +6 -5
- package/dist/MsaViewPanel/doLaunchOrthologs.test.js +38 -24
- package/dist/MsaViewPanel/model.d.ts +160 -10
- package/dist/MsaViewPanel/model.js +51 -1
- package/dist/MsaViewPanel/msaDataStore.d.ts +5 -3
- package/dist/MsaViewPanel/msaDataStore.js +16 -7
- package/dist/MsaViewPanel/msaDataStore.test.d.ts +1 -0
- package/dist/MsaViewPanel/msaDataStore.test.js +44 -0
- package/dist/MsaViewPanel/runLaunch.d.ts +38 -0
- package/dist/MsaViewPanel/runLaunch.js +65 -0
- package/dist/MsaViewPanel/runLaunch.test.d.ts +1 -0
- package/dist/MsaViewPanel/runLaunch.test.js +129 -0
- package/dist/MsaViewPanel/storedData.test.d.ts +1 -0
- package/dist/MsaViewPanel/storedData.test.js +160 -0
- package/dist/jbrowse-plugin-msaview.umd.production.min.js +35 -35
- package/dist/jbrowse-plugin-msaview.umd.production.min.js.map +4 -4
- package/dist/utils/blastCache.js +32 -0
- package/dist/utils/blastCache.test.d.ts +1 -0
- package/dist/utils/blastCache.test.js +72 -0
- package/dist/utils/ebiBlast.d.ts +4 -2
- package/dist/utils/ebiBlast.js +6 -4
- package/dist/utils/ebiJobDispatcher.d.ts +6 -3
- package/dist/utils/ebiJobDispatcher.js +13 -6
- package/dist/utils/fetch.d.ts +8 -1
- package/dist/utils/fetch.js +28 -2
- package/dist/utils/msa.d.ts +4 -2
- package/dist/utils/msa.js +9 -5
- package/dist/utils/ncbiDomains.d.ts +2 -2
- package/dist/utils/ncbiOrthologs.d.ts +11 -1
- package/dist/utils/ncbiOrthologs.js +26 -7
- package/dist/utils/ncbiOrthologs.test.js +23 -1
- package/dist/utils/pantherOrthologs.js +2 -10
- package/dist/utils/phmmer.d.ts +2 -1
- package/dist/utils/phmmer.js +4 -2
- package/dist/utils/poll.d.ts +6 -1
- package/dist/utils/poll.js +7 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +14 -14
- package/src/LaunchMsaView/components/BlastQuery/BlastAutomaticPanel.tsx +7 -11
- package/src/LaunchMsaView/components/BlastQuery/searchChoiceStorage.test.ts +43 -0
- package/src/LaunchMsaView/components/BlastQuery/searchChoiceStorage.ts +64 -0
- package/src/LaunchMsaView/components/OrthologQuery/OrthologPanel.tsx +2 -2
- package/src/LaunchMsaViewExtensionPoint/index.test.ts +51 -0
- package/src/LaunchMsaViewExtensionPoint/index.ts +21 -6
- package/src/MsaViewPanel/afterCreateAutoruns.ts +100 -66
- package/src/MsaViewPanel/components/LaunchProgress.tsx +20 -2
- package/src/MsaViewPanel/components/MsaViewPanel.test.tsx +21 -0
- package/src/MsaViewPanel/doLaunchBlast.ts +14 -10
- package/src/MsaViewPanel/doLaunchOrthologs.test.ts +41 -26
- package/src/MsaViewPanel/doLaunchOrthologs.ts +8 -4
- package/src/MsaViewPanel/model.ts +54 -1
- package/src/MsaViewPanel/msaDataStore.test.ts +54 -0
- package/src/MsaViewPanel/msaDataStore.ts +22 -13
- package/src/MsaViewPanel/runLaunch.test.ts +154 -0
- package/src/MsaViewPanel/runLaunch.ts +102 -0
- package/src/MsaViewPanel/storedData.test.ts +196 -0
- package/src/utils/blastCache.test.ts +86 -0
- package/src/utils/blastCache.ts +34 -1
- package/src/utils/ebiBlast.ts +8 -2
- package/src/utils/ebiJobDispatcher.ts +18 -3
- package/src/utils/fetch.ts +29 -2
- package/src/utils/msa.ts +11 -3
- package/src/utils/ncbiDomains.ts +4 -2
- package/src/utils/ncbiOrthologs.test.ts +25 -0
- package/src/utils/ncbiOrthologs.ts +27 -7
- package/src/utils/pantherOrthologs.ts +6 -11
- package/src/utils/phmmer.ts +5 -1
- package/src/utils/poll.ts +8 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { beforeEach, expect, test, vi } from 'vitest';
|
|
2
|
+
import { retrieveMsaData } from './msaDataStore';
|
|
3
|
+
// An in-memory stand-in for the one object store this module opens, with a
|
|
4
|
+
// switch for the write half so a browser that refuses writes can be played back.
|
|
5
|
+
const { rows, state } = vi.hoisted(() => ({
|
|
6
|
+
rows: new Map(),
|
|
7
|
+
state: { putFails: false },
|
|
8
|
+
}));
|
|
9
|
+
vi.mock('../utils/idb', () => ({
|
|
10
|
+
createDbOpener: () => () => Promise.resolve({
|
|
11
|
+
get: (_store, id) => Promise.resolve(rows.get(id)),
|
|
12
|
+
put: (_store, value) => {
|
|
13
|
+
if (state.putFails) {
|
|
14
|
+
return Promise.reject(new Error('QuotaExceededError'));
|
|
15
|
+
}
|
|
16
|
+
rows.set(value.id, value);
|
|
17
|
+
return Promise.resolve(value.id);
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
}));
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
rows.clear();
|
|
23
|
+
state.putFails = false;
|
|
24
|
+
});
|
|
25
|
+
// cleanupOldData deletes by timestamp, so without this a session opened every
|
|
26
|
+
// single day still lost its alignment on the eighth
|
|
27
|
+
test('reading a row refreshes its timestamp, making the expiry "unused for 7 days"', async () => {
|
|
28
|
+
rows.set('msa-1', { id: 'msa-1', msa: '>a\nMK', timestamp: 1000 });
|
|
29
|
+
const before = Date.now();
|
|
30
|
+
expect((await retrieveMsaData('msa-1'))?.msa).toBe('>a\nMK');
|
|
31
|
+
expect(rows.get('msa-1').timestamp).toBeGreaterThanOrEqual(before);
|
|
32
|
+
});
|
|
33
|
+
test('a row that is no longer there reads as undefined and writes nothing', async () => {
|
|
34
|
+
expect(await retrieveMsaData('msa-gone')).toBeUndefined();
|
|
35
|
+
expect(rows.size).toBe(0);
|
|
36
|
+
});
|
|
37
|
+
// the refresh is housekeeping; failing it must not turn a readable alignment
|
|
38
|
+
// into a missing one, which is what the caller reports as expired
|
|
39
|
+
test('a refresh that fails still hands back the data it read', async () => {
|
|
40
|
+
vi.spyOn(console, 'warn').mockImplementation(() => { });
|
|
41
|
+
rows.set('msa-1', { id: 'msa-1', msa: '>a\nMK', timestamp: 1000 });
|
|
42
|
+
state.putFails = true;
|
|
43
|
+
expect((await retrieveMsaData('msa-1'))?.msa).toBe('>a\nMK');
|
|
44
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { JBrowsePluginMsaViewModel } from './model';
|
|
2
|
+
/**
|
|
3
|
+
* What a launch is allowed to do to the model and to the network while it runs.
|
|
4
|
+
*
|
|
5
|
+
* Every write a launch makes goes through `act`, so "nothing touches the model
|
|
6
|
+
* once the launch has been abandoned" is one rule in one place. Spreading that
|
|
7
|
+
* guard across the call sites only takes one omission to undo: an abandoned
|
|
8
|
+
* launch keeps running until its next network hop rejects, and an action on a
|
|
9
|
+
* destroyed mobx-state-tree node throws where nothing is catching.
|
|
10
|
+
*/
|
|
11
|
+
export interface LaunchScope {
|
|
12
|
+
/** aborts when the user cancels, and when the view is destroyed */
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
act: (fn: () => void) => void;
|
|
15
|
+
onProgress: (arg: string) => void;
|
|
16
|
+
/** the EBI job id, published before the first poll so the view can link out */
|
|
17
|
+
onRid: (arg: string) => void;
|
|
18
|
+
}
|
|
19
|
+
interface LaunchedData {
|
|
20
|
+
msa: string;
|
|
21
|
+
tree: string;
|
|
22
|
+
treeMetadata: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Run one launch attempt, owning the AbortController that ties it to the view.
|
|
26
|
+
*
|
|
27
|
+
* The controller lives on the model because two things end a launch and neither
|
|
28
|
+
* is here: the Cancel button, and the disposer `afterCreate` registers. Before
|
|
29
|
+
* it existed, closing a view mid-BLAST left the poller checking EBI for the
|
|
30
|
+
* job's lifetime and then writing to a node that was gone.
|
|
31
|
+
*/
|
|
32
|
+
export declare function runLaunch({ self, message, launch, onLaunched, }: {
|
|
33
|
+
self: JBrowsePluginMsaViewModel;
|
|
34
|
+
message: string;
|
|
35
|
+
launch: (scope: LaunchScope) => Promise<LaunchedData>;
|
|
36
|
+
onLaunched: () => void;
|
|
37
|
+
}): void;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isAbortError } from '../utils/fetch';
|
|
2
|
+
/**
|
|
3
|
+
* Run one launch attempt, owning the AbortController that ties it to the view.
|
|
4
|
+
*
|
|
5
|
+
* The controller lives on the model because two things end a launch and neither
|
|
6
|
+
* is here: the Cancel button, and the disposer `afterCreate` registers. Before
|
|
7
|
+
* it existed, closing a view mid-BLAST left the poller checking EBI for the
|
|
8
|
+
* job's lifetime and then writing to a node that was gone.
|
|
9
|
+
*/
|
|
10
|
+
export function runLaunch({ self, message, launch, onLaunched, }) {
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const { signal } = controller;
|
|
13
|
+
self.setLaunchController(controller);
|
|
14
|
+
const act = (fn) => {
|
|
15
|
+
if (!signal.aborted) {
|
|
16
|
+
fn();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const scope = {
|
|
20
|
+
signal,
|
|
21
|
+
act,
|
|
22
|
+
onProgress: arg => {
|
|
23
|
+
act(() => {
|
|
24
|
+
self.setProgress(arg);
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
onRid: arg => {
|
|
28
|
+
act(() => {
|
|
29
|
+
self.setRid(arg);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
void (async () => {
|
|
34
|
+
try {
|
|
35
|
+
act(() => {
|
|
36
|
+
self.setProgress(message);
|
|
37
|
+
self.setError(undefined);
|
|
38
|
+
});
|
|
39
|
+
const data = await launch(scope);
|
|
40
|
+
act(() => {
|
|
41
|
+
self.setData(data);
|
|
42
|
+
onLaunched();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
// a cancel is not a failure: drawing the error panel for one would tell
|
|
47
|
+
// the user their launch broke when they are the one who stopped it
|
|
48
|
+
if (!isAbortError(e)) {
|
|
49
|
+
act(() => {
|
|
50
|
+
self.setError(e);
|
|
51
|
+
});
|
|
52
|
+
console.error(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
act(() => {
|
|
57
|
+
self.setProgress('');
|
|
58
|
+
// only if a later launch has not already claimed the slot
|
|
59
|
+
if (self.launchController === controller) {
|
|
60
|
+
self.setLaunchController(undefined);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { runLaunch } from './runLaunch';
|
|
3
|
+
/**
|
|
4
|
+
* A model that records every write, so "no model actions after abort" is
|
|
5
|
+
* assertable rather than inferred. The real thing throws on a destroyed node;
|
|
6
|
+
* here a write that should not have happened simply shows up in the log.
|
|
7
|
+
*/
|
|
8
|
+
function makeModel() {
|
|
9
|
+
const writes = [];
|
|
10
|
+
const model = {
|
|
11
|
+
launchController: undefined,
|
|
12
|
+
setLaunchController(arg) {
|
|
13
|
+
model.launchController = arg;
|
|
14
|
+
writes.push(`setLaunchController:${arg ? 'set' : 'cleared'}`);
|
|
15
|
+
},
|
|
16
|
+
setProgress: (arg) => writes.push(`setProgress:${arg}`),
|
|
17
|
+
setError: (e) => writes.push(`setError:${e instanceof Error ? e.message : String(e)}`),
|
|
18
|
+
setRid: (arg) => writes.push(`setRid:${arg}`),
|
|
19
|
+
setData: () => writes.push('setData'),
|
|
20
|
+
};
|
|
21
|
+
return { model, writes };
|
|
22
|
+
}
|
|
23
|
+
const DATA = { msa: '>a\nMK', tree: '(a);', treeMetadata: '{}' };
|
|
24
|
+
/** run the microtask queue out so the launch's async body has finished */
|
|
25
|
+
const settle = () => new Promise(res => setTimeout(res, 0));
|
|
26
|
+
describe('a launch that finishes', () => {
|
|
27
|
+
test('applies its data, clears its params and releases the controller', async () => {
|
|
28
|
+
const { model, writes } = makeModel();
|
|
29
|
+
const onLaunched = vi.fn();
|
|
30
|
+
runLaunch({
|
|
31
|
+
self: model,
|
|
32
|
+
message: 'Submitting query',
|
|
33
|
+
onLaunched,
|
|
34
|
+
launch: async (scope) => {
|
|
35
|
+
scope.onRid('ncbiblast-1');
|
|
36
|
+
scope.onProgress('Re-checking BLAST status in... 7');
|
|
37
|
+
return DATA;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
await settle();
|
|
41
|
+
expect(writes).toEqual([
|
|
42
|
+
'setLaunchController:set',
|
|
43
|
+
'setProgress:Submitting query',
|
|
44
|
+
'setError:undefined',
|
|
45
|
+
'setRid:ncbiblast-1',
|
|
46
|
+
'setProgress:Re-checking BLAST status in... 7',
|
|
47
|
+
'setData',
|
|
48
|
+
'setProgress:',
|
|
49
|
+
'setLaunchController:cleared',
|
|
50
|
+
]);
|
|
51
|
+
expect(onLaunched).toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
// The failure this file exists for: closing a view mid-BLAST left the poller
|
|
55
|
+
// running for the job's lifetime and then writing to a destroyed
|
|
56
|
+
// mobx-state-tree node, whose throw surfaced as an unhandled rejection.
|
|
57
|
+
describe('a launch that is abandoned', () => {
|
|
58
|
+
async function abandonMidFlight(reject) {
|
|
59
|
+
const { model, writes } = makeModel();
|
|
60
|
+
let released;
|
|
61
|
+
const held = new Promise(res => {
|
|
62
|
+
released = res;
|
|
63
|
+
});
|
|
64
|
+
let captured;
|
|
65
|
+
runLaunch({
|
|
66
|
+
self: model,
|
|
67
|
+
message: 'Submitting query',
|
|
68
|
+
onLaunched: () => {
|
|
69
|
+
throw new Error('a cancelled launch must not report success');
|
|
70
|
+
},
|
|
71
|
+
launch: async (scope) => {
|
|
72
|
+
captured = scope;
|
|
73
|
+
await held;
|
|
74
|
+
// what the network hop does once its signal is aborted: either it
|
|
75
|
+
// rejects with an AbortError, or it had already resolved and returns
|
|
76
|
+
if (reject) {
|
|
77
|
+
throw new DOMException('Aborted', 'AbortError');
|
|
78
|
+
}
|
|
79
|
+
return DATA;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
await settle();
|
|
83
|
+
const before = writes.length;
|
|
84
|
+
model.launchController.abort();
|
|
85
|
+
// everything the launch would still try to do after the abort
|
|
86
|
+
captured.onProgress('Re-checking BLAST status in... 3');
|
|
87
|
+
captured.onRid('ncbiblast-2');
|
|
88
|
+
captured.act(() => {
|
|
89
|
+
throw new Error('act must not run its callback after an abort');
|
|
90
|
+
});
|
|
91
|
+
released();
|
|
92
|
+
await settle();
|
|
93
|
+
return writes.slice(before);
|
|
94
|
+
}
|
|
95
|
+
test('nothing is written to the model once the abort lands', async () => {
|
|
96
|
+
expect(await abandonMidFlight(true)).toEqual([]);
|
|
97
|
+
});
|
|
98
|
+
test('a launch that resolved anyway still applies nothing', async () => {
|
|
99
|
+
expect(await abandonMidFlight(false)).toEqual([]);
|
|
100
|
+
});
|
|
101
|
+
test('an abort renders no error, so a cancel does not read as a failure', async () => {
|
|
102
|
+
const { model, writes } = makeModel();
|
|
103
|
+
runLaunch({
|
|
104
|
+
self: model,
|
|
105
|
+
message: 'Submitting query',
|
|
106
|
+
onLaunched: () => { },
|
|
107
|
+
launch: () => Promise.reject(new DOMException('Aborted', 'AbortError')),
|
|
108
|
+
});
|
|
109
|
+
await settle();
|
|
110
|
+
expect(writes.some(w => w.startsWith('setError:Aborted'))).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('a launch that fails', () => {
|
|
114
|
+
test('records the error and stops the spinner', async () => {
|
|
115
|
+
vi.spyOn(console, 'error').mockImplementation(() => { });
|
|
116
|
+
const { model, writes } = makeModel();
|
|
117
|
+
runLaunch({
|
|
118
|
+
self: model,
|
|
119
|
+
message: 'Resolving orthologs',
|
|
120
|
+
onLaunched: () => {
|
|
121
|
+
throw new Error('a failed launch must not report success');
|
|
122
|
+
},
|
|
123
|
+
launch: () => Promise.reject(new Error('Only 1 ortholog(s) found')),
|
|
124
|
+
});
|
|
125
|
+
await settle();
|
|
126
|
+
expect(writes).toContain('setError:Only 1 ortholog(s) found');
|
|
127
|
+
expect(writes.at(-2)).toBe('setProgress:');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { loadStoredData, storeDataToIndexedDB } from './afterCreateAutoruns';
|
|
3
|
+
import { generateDataStoreId, retrieveMsaData, storeMsaData, } from './msaDataStore';
|
|
4
|
+
// IndexedDB itself is msaDataStore.test.ts's subject; what is under test here is
|
|
5
|
+
// which writes these two autoruns decide to make.
|
|
6
|
+
vi.mock('./msaDataStore', () => ({
|
|
7
|
+
cleanupOldData: vi.fn(),
|
|
8
|
+
generateDataStoreId: vi.fn(),
|
|
9
|
+
retrieveMsaData: vi.fn(),
|
|
10
|
+
storeMsaData: vi.fn(),
|
|
11
|
+
}));
|
|
12
|
+
const mockRetrieve = vi.mocked(retrieveMsaData);
|
|
13
|
+
const mockStore = vi.mocked(storeMsaData);
|
|
14
|
+
const mockGenerateId = vi.mocked(generateDataStoreId);
|
|
15
|
+
const MSA = '>a\nMK';
|
|
16
|
+
const NEW_ID = 'msa-generated';
|
|
17
|
+
function makeModel(over = {}) {
|
|
18
|
+
const model = {
|
|
19
|
+
dataStoreId: undefined,
|
|
20
|
+
rows: [],
|
|
21
|
+
data: {},
|
|
22
|
+
msaFilehandle: undefined,
|
|
23
|
+
treeFilehandle: undefined,
|
|
24
|
+
isStoringData: false,
|
|
25
|
+
lastStoredData: undefined,
|
|
26
|
+
loadingStoredData: false,
|
|
27
|
+
error: undefined,
|
|
28
|
+
setDataStoreId(arg) {
|
|
29
|
+
model.dataStoreId = arg;
|
|
30
|
+
},
|
|
31
|
+
setIsStoringData(arg) {
|
|
32
|
+
model.isStoringData = arg;
|
|
33
|
+
},
|
|
34
|
+
setLastStoredData(arg) {
|
|
35
|
+
model.lastStoredData = arg;
|
|
36
|
+
},
|
|
37
|
+
setLoadingStoredData(arg) {
|
|
38
|
+
model.loadingStoredData = arg;
|
|
39
|
+
},
|
|
40
|
+
setError(arg) {
|
|
41
|
+
model.error = arg;
|
|
42
|
+
},
|
|
43
|
+
setMSA(arg) {
|
|
44
|
+
model.data.msa = arg;
|
|
45
|
+
},
|
|
46
|
+
setTree(arg) {
|
|
47
|
+
model.data.tree = arg;
|
|
48
|
+
},
|
|
49
|
+
setTreeMetadata(arg) {
|
|
50
|
+
model.data.treeMetadata = arg;
|
|
51
|
+
},
|
|
52
|
+
...over,
|
|
53
|
+
};
|
|
54
|
+
return model;
|
|
55
|
+
}
|
|
56
|
+
const settle = () => new Promise(res => setTimeout(res, 0));
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
vi.clearAllMocks();
|
|
59
|
+
mockGenerateId.mockReturnValue(NEW_ID);
|
|
60
|
+
mockStore.mockResolvedValue(true);
|
|
61
|
+
});
|
|
62
|
+
describe('restoring a view from IndexedDB', () => {
|
|
63
|
+
test('a row that is still there is applied and recorded as stored', async () => {
|
|
64
|
+
mockRetrieve.mockResolvedValue({
|
|
65
|
+
msa: MSA,
|
|
66
|
+
tree: '(a);',
|
|
67
|
+
treeMetadata: '{}',
|
|
68
|
+
});
|
|
69
|
+
const model = makeModel({ dataStoreId: 'msa-1' });
|
|
70
|
+
loadStoredData(model);
|
|
71
|
+
await settle();
|
|
72
|
+
expect(model.data.msa).toBe(MSA);
|
|
73
|
+
expect(model.error).toBeUndefined();
|
|
74
|
+
// recorded, so the store autorun does not write the restored data straight
|
|
75
|
+
// back out again
|
|
76
|
+
expect(model.lastStoredData).toEqual({
|
|
77
|
+
msa: MSA,
|
|
78
|
+
tree: '(a);',
|
|
79
|
+
treeMetadata: '{}',
|
|
80
|
+
});
|
|
81
|
+
model.rows = [['a', 'MK']];
|
|
82
|
+
storeDataToIndexedDB(model);
|
|
83
|
+
expect(mockStore).not.toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
// the row expires or the user clears site data, and the view used to reopen as
|
|
86
|
+
// a blank import form with no hint that anything had been lost
|
|
87
|
+
test('a row that is gone says so, in words that name the policy', async () => {
|
|
88
|
+
mockRetrieve.mockResolvedValue(undefined);
|
|
89
|
+
const model = makeModel({ dataStoreId: 'msa-1' });
|
|
90
|
+
loadStoredData(model);
|
|
91
|
+
await settle();
|
|
92
|
+
expect(model.error).toBeInstanceOf(Error);
|
|
93
|
+
expect(model.error.message).toMatch(/7 days/);
|
|
94
|
+
// the id names nothing now, so it goes -- otherwise react-msaview's "Return
|
|
95
|
+
// to import form" lands straight back on this error
|
|
96
|
+
expect(model.dataStoreId).toBeUndefined();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('keeping IndexedDB up to date', () => {
|
|
100
|
+
test('the first alignment is written under a fresh id', async () => {
|
|
101
|
+
const model = makeModel({ rows: [['a', 'MK']], data: { msa: MSA } });
|
|
102
|
+
storeDataToIndexedDB(model);
|
|
103
|
+
await settle();
|
|
104
|
+
expect(mockStore).toHaveBeenCalledWith(NEW_ID, { msa: MSA });
|
|
105
|
+
expect(model.dataStoreId).toBe(NEW_ID);
|
|
106
|
+
expect(model.isStoringData).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
// react-msaview's "calculate neighbor-joining tree" replaces data.tree long
|
|
109
|
+
// after the first write; the row used to keep the alignment's original tree
|
|
110
|
+
// forever, so a reopened session restored a picture the user had replaced
|
|
111
|
+
test('an edit after the first write updates the existing row', async () => {
|
|
112
|
+
const model = makeModel({
|
|
113
|
+
dataStoreId: 'msa-1',
|
|
114
|
+
rows: [['a', 'MK']],
|
|
115
|
+
data: { msa: MSA, tree: '(a);' },
|
|
116
|
+
lastStoredData: { msa: MSA, tree: '(a);' },
|
|
117
|
+
});
|
|
118
|
+
storeDataToIndexedDB(model);
|
|
119
|
+
expect(mockStore).not.toHaveBeenCalled();
|
|
120
|
+
model.data.tree = '(a:0.1);';
|
|
121
|
+
storeDataToIndexedDB(model);
|
|
122
|
+
await settle();
|
|
123
|
+
expect(mockStore).toHaveBeenCalledWith('msa-1', {
|
|
124
|
+
msa: MSA,
|
|
125
|
+
tree: '(a:0.1);',
|
|
126
|
+
treeMetadata: undefined,
|
|
127
|
+
});
|
|
128
|
+
expect(model.dataStoreId).toBe('msa-1');
|
|
129
|
+
});
|
|
130
|
+
// a browser that refuses IndexedDB (private mode) answers every write the same
|
|
131
|
+
// way, and the autorun reruns on its own isStoringData flag -- so a write that
|
|
132
|
+
// is not recorded as attempted is a write that retries forever
|
|
133
|
+
test('a write that fails is not retried on the same data', async () => {
|
|
134
|
+
vi.spyOn(console, 'error').mockImplementation(() => { });
|
|
135
|
+
mockStore.mockResolvedValue(false);
|
|
136
|
+
const model = makeModel({ rows: [['a', 'MK']], data: { msa: MSA } });
|
|
137
|
+
storeDataToIndexedDB(model);
|
|
138
|
+
await settle();
|
|
139
|
+
expect(model.dataStoreId).toBeUndefined();
|
|
140
|
+
storeDataToIndexedDB(model);
|
|
141
|
+
await settle();
|
|
142
|
+
expect(mockStore).toHaveBeenCalledTimes(1);
|
|
143
|
+
});
|
|
144
|
+
test('a view reading from a filehandle stores nothing, since the file is the source', () => {
|
|
145
|
+
storeDataToIndexedDB(makeModel({
|
|
146
|
+
rows: [['a', 'MK']],
|
|
147
|
+
data: { msa: MSA },
|
|
148
|
+
msaFilehandle: { uri: 'msa.fa', locationType: 'UriLocation' },
|
|
149
|
+
}));
|
|
150
|
+
expect(mockStore).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
test('a write already in flight is not duplicated', () => {
|
|
153
|
+
storeDataToIndexedDB(makeModel({
|
|
154
|
+
rows: [['a', 'MK']],
|
|
155
|
+
data: { msa: MSA },
|
|
156
|
+
isStoringData: true,
|
|
157
|
+
}));
|
|
158
|
+
expect(mockStore).not.toHaveBeenCalled();
|
|
159
|
+
});
|
|
160
|
+
});
|