chore(editor): move legacy doc collection to test workspace (#9507)
This commit is contained in:
@@ -9,7 +9,8 @@ import {
|
||||
type SchemaToModel,
|
||||
} from '../schema/index.js';
|
||||
import { Block, type YBlock } from '../store/doc/block/index.js';
|
||||
import { DocCollection, IdGeneratorType } from '../store/index.js';
|
||||
import { TestWorkspace } from '../test/test-workspace.js';
|
||||
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||
|
||||
const pageSchema = defineBlockSchema({
|
||||
flavour: 'page',
|
||||
@@ -28,7 +29,7 @@ const pageSchema = defineBlockSchema({
|
||||
type RootModel = SchemaToModel<typeof pageSchema>;
|
||||
|
||||
function createTestOptions() {
|
||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
||||
const idGenerator = createAutoIncrementIdGenerator();
|
||||
const schema = new Schema();
|
||||
schema.register([pageSchema]);
|
||||
return { id: 'test-collection', idGenerator, schema };
|
||||
@@ -37,7 +38,7 @@ function createTestOptions() {
|
||||
const defaultDocId = 'doc:home';
|
||||
function createTestDoc(docId = defaultDocId) {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc({ id: docId });
|
||||
doc.load();
|
||||
|
||||
@@ -6,8 +6,10 @@ import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
||||
|
||||
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
||||
import type { BlockModel, BlockSchemaType, Doc } from '../index.js';
|
||||
import { DocCollection, IdGeneratorType, Schema } from '../index.js';
|
||||
import { Schema } from '../index.js';
|
||||
import type { DocMeta } from '../store/workspace.js';
|
||||
import { TestWorkspace } from '../test/test-workspace.js';
|
||||
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||
import type { BlockSuiteDoc } from '../yjs/index.js';
|
||||
import {
|
||||
NoteBlockSchema,
|
||||
@@ -23,7 +25,7 @@ export const BlockSchemas = [
|
||||
] as BlockSchemaType[];
|
||||
|
||||
function createTestOptions() {
|
||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
||||
const idGenerator = createAutoIncrementIdGenerator();
|
||||
const schema = new Schema();
|
||||
schema.register(BlockSchemas);
|
||||
return { id: 'test-collection', idGenerator, schema };
|
||||
@@ -60,7 +62,7 @@ function createRoot(doc: Doc) {
|
||||
|
||||
function createTestDoc(docId = defaultDocId) {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc({ id: docId });
|
||||
doc.load();
|
||||
@@ -92,7 +94,7 @@ beforeEach(() => {
|
||||
describe('basic', () => {
|
||||
it('can init collection', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
|
||||
const doc = collection.createDoc({ id: 'doc:home' });
|
||||
@@ -132,7 +134,7 @@ describe('basic', () => {
|
||||
it('init collection with custom id generator', () => {
|
||||
const options = createTestOptions();
|
||||
let id = 100;
|
||||
const collection = new DocCollection({
|
||||
const collection = new TestWorkspace({
|
||||
...options,
|
||||
idGenerator: () => {
|
||||
return String(id++);
|
||||
@@ -151,7 +153,7 @@ describe('basic', () => {
|
||||
|
||||
it('doc ready lifecycle', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc({
|
||||
id: 'space:0',
|
||||
@@ -176,9 +178,9 @@ describe('basic', () => {
|
||||
|
||||
it('collection docs with yjs applyUpdate', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const collection2 = new DocCollection(options);
|
||||
const collection2 = new TestWorkspace(options);
|
||||
const doc = collection.createDoc({
|
||||
id: 'space:0',
|
||||
});
|
||||
@@ -378,7 +380,7 @@ describe('addBlock', () => {
|
||||
|
||||
it('can add and remove multi docs', async () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
|
||||
const doc0 = collection.createDoc({ id: 'doc:home' });
|
||||
@@ -403,7 +405,7 @@ describe('addBlock', () => {
|
||||
|
||||
it('can remove doc that has not been loaded', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
|
||||
const doc0 = collection.createDoc({ id: 'doc:home' });
|
||||
@@ -414,7 +416,7 @@ describe('addBlock', () => {
|
||||
|
||||
it('can set doc state', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
collection.createDoc({ id: 'doc:home' });
|
||||
|
||||
@@ -456,7 +458,7 @@ describe('addBlock', () => {
|
||||
|
||||
it('can set collection common meta fields', async () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
|
||||
queueMicrotask(() => collection.meta.setName('hello'));
|
||||
await waitOnce(collection.meta.commonFieldsUpdated);
|
||||
@@ -863,7 +865,7 @@ describe('getBlock', () => {
|
||||
describe('flags', () => {
|
||||
it('update flags', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
|
||||
const awareness = collection.awarenessStore;
|
||||
|
||||
@@ -2,11 +2,9 @@ import { expect, test, vi } from 'vitest';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { Schema } from '../schema/index.js';
|
||||
import {
|
||||
BlockViewType,
|
||||
DocCollection,
|
||||
IdGeneratorType,
|
||||
} from '../store/index.js';
|
||||
import { BlockViewType } from '../store/index.js';
|
||||
import { TestWorkspace } from '../test/test-workspace.js';
|
||||
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||
import {
|
||||
DividerBlockSchema,
|
||||
ListBlockSchema,
|
||||
@@ -25,7 +23,7 @@ const BlockSchemas = [
|
||||
];
|
||||
|
||||
function createTestOptions() {
|
||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
||||
const idGenerator = createAutoIncrementIdGenerator();
|
||||
const schema = new Schema();
|
||||
schema.register(BlockSchemas);
|
||||
return { id: 'test-collection', idGenerator, schema };
|
||||
@@ -33,7 +31,7 @@ function createTestOptions() {
|
||||
|
||||
test('trigger props updated', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
|
||||
const doc = collection.createDoc({ id: 'home' });
|
||||
@@ -93,7 +91,7 @@ test('trigger props updated', () => {
|
||||
|
||||
test('stash and pop', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
|
||||
const doc = collection.createDoc({ id: 'home' });
|
||||
@@ -163,7 +161,7 @@ test('stash and pop', () => {
|
||||
|
||||
test('always get latest value in onChange', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
|
||||
const doc = collection.createDoc({ id: 'home' });
|
||||
@@ -210,7 +208,7 @@ test('always get latest value in onChange', () => {
|
||||
|
||||
test('query', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const doc1 = collection.createDoc({ id: 'home' });
|
||||
doc1.load();
|
||||
@@ -247,7 +245,7 @@ test('query', () => {
|
||||
|
||||
test('local readonly', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const doc1 = collection.createDoc({ id: 'home' });
|
||||
doc1.load();
|
||||
|
||||
@@ -5,7 +5,8 @@ import { describe, expect, it, vi } from 'vitest';
|
||||
import { type BlockModel, defineBlockSchema } from '../schema/base.js';
|
||||
import { SchemaValidateError } from '../schema/error.js';
|
||||
import { Schema } from '../schema/index.js';
|
||||
import { DocCollection, IdGeneratorType } from '../store/index.js';
|
||||
import { TestWorkspace } from '../test/test-workspace.js';
|
||||
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||
import {
|
||||
DividerBlockSchema,
|
||||
ListBlockSchema,
|
||||
@@ -15,7 +16,7 @@ import {
|
||||
} from './test-schema.js';
|
||||
|
||||
function createTestOptions() {
|
||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
||||
const idGenerator = createAutoIncrementIdGenerator();
|
||||
const schema = new Schema();
|
||||
schema.register(BlockSchemas);
|
||||
return { id: 'test-collection', idGenerator, schema };
|
||||
@@ -60,7 +61,7 @@ const BlockSchemas = [
|
||||
const defaultDocId = 'doc0';
|
||||
function createTestDoc(docId = defaultDocId) {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc({ id: docId });
|
||||
doc.load();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { DocCollection } from '../store/index.js';
|
||||
import type { TestWorkspace } from '../test';
|
||||
|
||||
declare global {
|
||||
interface WindowEventMap {
|
||||
'test-result': CustomEvent<TestResult>;
|
||||
}
|
||||
interface Window {
|
||||
collection: DocCollection;
|
||||
collection: TestWorkspace;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@ import {
|
||||
Schema,
|
||||
type SchemaToModel,
|
||||
} from '../schema/index.js';
|
||||
import { DocCollection, IdGeneratorType } from '../store/index.js';
|
||||
import { TestWorkspace } from '../test/test-workspace.js';
|
||||
import { AssetsManager, BaseBlockTransformer } from '../transformer/index.js';
|
||||
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||
|
||||
const docSchema = defineBlockSchema({
|
||||
flavour: 'page',
|
||||
@@ -44,7 +45,7 @@ const docSchema = defineBlockSchema({
|
||||
type RootBlockModel = SchemaToModel<typeof docSchema>;
|
||||
|
||||
function createTestOptions() {
|
||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
||||
const idGenerator = createAutoIncrementIdGenerator();
|
||||
const schema = new Schema();
|
||||
schema.register([docSchema]);
|
||||
return { id: 'test-collection', idGenerator, schema };
|
||||
@@ -56,7 +57,7 @@ const assets = new AssetsManager({ blob: blobCRUD });
|
||||
|
||||
test('model to snapshot', () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc({ id: 'home' });
|
||||
doc.load();
|
||||
@@ -73,7 +74,7 @@ test('model to snapshot', () => {
|
||||
|
||||
test('snapshot to model', async () => {
|
||||
const options = createTestOptions();
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc({ id: 'home' });
|
||||
doc.load();
|
||||
|
||||
Reference in New Issue
Block a user