fix(sql-library): load saved files earlier at startup
This commit is contained in:
5 files changed
+63
-16
No files matched your search
+3
-2
@@ -61,14 +61,15 @@ test("web startup uses the guarded initializer behind the existing authenticatio
|
||||
assert.ok(initAppStart >= 0 && initAppEnd > initAppStart);
|
||||
|
||||
const initAppSource = appSource.slice(initAppStart, initAppEnd);
|
||||
const savedSqlInitialization = initAppSource.indexOf("savedSqlStore.initFromStorage()");
|
||||
const webInitialization = initAppSource.indexOf("await initializeOpenTabs({");
|
||||
const optionalInitialization = initAppSource.indexOf("initializeOptionalState: () => settingsStore.initAiConfigs()", webInitialization);
|
||||
const requiredRestoration = initAppSource.indexOf("restoreOpenTabs,", optionalInitialization);
|
||||
const savedSqlInitialization = initAppSource.indexOf("savedSqlStore.initFromStorage()", requiredRestoration);
|
||||
assert.ok(savedSqlInitialization >= 0);
|
||||
assert.ok(webInitialization >= 0);
|
||||
assert.ok(savedSqlInitialization < webInitialization);
|
||||
assert.ok(optionalInitialization > webInitialization);
|
||||
assert.ok(requiredRestoration > optionalInitialization);
|
||||
assert.ok(savedSqlInitialization > requiredRestoration);
|
||||
assert.equal(initAppSource.includes("if (!desktopOpenTabsRestorationBarrier) await settingsStore.initAiConfigs()"), false);
|
||||
|
||||
const mountedStart = appSource.indexOf("onMounted(async () =>");
|
||||
|
||||
+32
@@ -28,6 +28,38 @@ beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test("tracks saved SQL library loading and supports retry after failure", async () => {
|
||||
let resolveLoad: ((library: SavedSqlLibrary) => void) | undefined;
|
||||
apiMock.loadSavedSqlLibrary.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise<SavedSqlLibrary>((resolve) => {
|
||||
resolveLoad = resolve;
|
||||
}),
|
||||
);
|
||||
|
||||
const store = useSavedSqlStore();
|
||||
assert.equal(store.loadState, "idle");
|
||||
|
||||
const loading = store.initFromStorage();
|
||||
assert.equal(store.loadState, "loading");
|
||||
await Promise.resolve();
|
||||
resolveLoad?.({ folders: [], files: [] });
|
||||
await loading;
|
||||
|
||||
assert.equal(store.loadState, "loaded");
|
||||
assert.equal(store.isLoaded, true);
|
||||
|
||||
setActivePinia(createPinia());
|
||||
const retryingStore = useSavedSqlStore();
|
||||
apiMock.loadSavedSqlLibrary.mockRejectedValueOnce(new Error("storage unavailable"));
|
||||
await assert.rejects(retryingStore.initFromStorage(), /storage unavailable/);
|
||||
assert.equal(retryingStore.loadState, "failed");
|
||||
|
||||
apiMock.loadSavedSqlLibrary.mockResolvedValueOnce({ folders: [], files: [] });
|
||||
await retryingStore.initFromStorage();
|
||||
assert.equal(retryingStore.loadState, "loaded");
|
||||
});
|
||||
|
||||
test("concurrent saved SQL folder creates reuse the same pending folder", async () => {
|
||||
let resolveSave: ((folder: SavedSqlFolder) => void) | undefined;
|
||||
apiMock.saveSavedSqlFolder.mockImplementation(
|
||||
|
||||
Reference in new issue
Block a user