fix: import workspace may only show default preload page (#2685)

This commit is contained in:
Peng Xiao
2023-06-06 14:42:50 +08:00
committed by GitHub
parent f78760cb83
commit 84f68fc2c0
3 changed files with 139 additions and 75 deletions
@@ -3,14 +3,15 @@ import type { Y as YType } from '@blocksuite/store';
import { uuidv4, Workspace } from '@blocksuite/store';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import type { SQLiteProvider } from '../../type';
import { createSQLiteProvider } from '../index';
import type { SQLiteDBDownloadProvider, SQLiteProvider } from '../../type';
import { createSQLiteDBDownloadProvider, createSQLiteProvider } from '../index';
const Y = Workspace.Y;
let id: string;
let workspace: Workspace;
let provider: SQLiteProvider;
let downloadProvider: SQLiteDBDownloadProvider;
let offlineYdoc: YType.Doc;
@@ -60,12 +61,13 @@ beforeEach(() => {
});
workspace.register(AffineSchemas).register(__unstableSchemas);
provider = createSQLiteProvider(workspace);
downloadProvider = createSQLiteDBDownloadProvider(workspace);
offlineYdoc = new Y.Doc();
offlineYdoc.getText('text').insert(0, 'sqlite-hello');
});
describe('SQLite provider', () => {
test('connect', async () => {
describe('SQLite download provider', () => {
test('sync updates', async () => {
// on connect, the updates from sqlite should be sync'ed to the existing ydoc
// and ydoc should be sync'ed back to sqlite
// Workspace.Y.applyUpdate(workspace.doc);
@@ -73,7 +75,8 @@ describe('SQLite provider', () => {
expect(offlineYdoc.getText('text').toString()).toBe('sqlite-hello');
await provider.connect();
downloadProvider.sync();
await downloadProvider.whenReady;
// depending on the nature of the sync, the data can be sync'ed in either direction
const options = ['mem-hellosqlite-hello', 'sqlite-hellomem-hello'];
@@ -83,10 +86,10 @@ describe('SQLite provider', () => {
expect(synced.length).toBe(1);
expect(workspace.doc.getText('text').toString()).toBe(synced[0]);
workspace.doc.getText('text').insert(0, 'world');
// workspace.doc.getText('text').insert(0, 'world');
// check if the data are sync'ed
expect(offlineYdoc.getText('text').toString()).toBe('world' + synced[0]);
// // check if the data are sync'ed
// expect(offlineYdoc.getText('text').toString()).toBe('world' + synced[0]);
});
test('blobs will be synced to sqlite on connect', async () => {
@@ -98,14 +101,15 @@ describe('SQLite provider', () => {
return blob;
});
await provider.connect();
downloadProvider.sync();
await downloadProvider.whenReady;
await new Promise(resolve => setTimeout(resolve, 100));
expect(mockedAddBlob).toBeCalledWith(id, 'blob1', bin);
});
test('on db update', async () => {
await provider.connect();
provider.connect();
offlineYdoc.getText('text').insert(0, 'sqlite-world');
@@ -114,8 +118,8 @@ describe('SQLite provider', () => {
update: Y.encodeStateAsUpdate(offlineYdoc),
});
// not yet updated
expect(workspace.doc.getText('text').toString()).toBe('sqlite-hello');
// not yet updated (because the workspace id is different)
expect(workspace.doc.getText('text').toString()).toBe('');
triggerDBUpdate?.({
workspaceId: id,