mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-03 09:48:28 +03:00
test: improve coverage (#1780)
This commit is contained in:
parent
60324b8967
commit
f5574c68fe
68
packages/workspace/src/local/__tests__/crud.spec.ts
Normal file
68
packages/workspace/src/local/__tests__/crud.spec.ts
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @vitest-environment happy-dom
|
||||
*/
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import type { LocalWorkspace, WorkspaceCRUD } from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import { afterEach, assertType, describe, expect, test } from 'vitest';
|
||||
|
||||
import { CRUD } from '../crud';
|
||||
|
||||
afterEach(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
describe('crud', () => {
|
||||
test('type', () => {
|
||||
assertType<WorkspaceCRUD<WorkspaceFlavour.LOCAL>>(CRUD);
|
||||
});
|
||||
|
||||
test('basic', async () => {
|
||||
const workspace = await CRUD.get('not_exist');
|
||||
expect(workspace).toBeNull();
|
||||
|
||||
expect(await CRUD.list()).toEqual([]);
|
||||
});
|
||||
|
||||
test('delete not exist', async () => {
|
||||
expect(async () =>
|
||||
CRUD.delete({
|
||||
id: 'not_exist',
|
||||
flavour: WorkspaceFlavour.LOCAL,
|
||||
blockSuiteWorkspace: new Workspace({ id: 'test' }),
|
||||
providers: [],
|
||||
})
|
||||
).rejects.toThrowError();
|
||||
});
|
||||
|
||||
test('create & delete', async () => {
|
||||
const workspace = new Workspace({ id: 'test' })
|
||||
.register(AffineSchemas)
|
||||
.register(__unstableSchemas);
|
||||
const page = workspace.createPage('test');
|
||||
const pageBlockId = page.addBlock('affine:page', {
|
||||
title: new page.Text(''),
|
||||
});
|
||||
page.addBlock('affine:surface', {}, null);
|
||||
const frameId = page.addBlock('affine:frame', {}, pageBlockId);
|
||||
page.addBlock('affine:paragraph', {}, frameId);
|
||||
|
||||
const id = await CRUD.create(workspace);
|
||||
const list = await CRUD.list();
|
||||
expect(list.length).toBe(1);
|
||||
expect(list[0].id).toBe(id);
|
||||
const localWorkspace = list.at(0) as LocalWorkspace;
|
||||
expect(localWorkspace.id).toBe(id);
|
||||
expect(localWorkspace.flavour).toBe(WorkspaceFlavour.LOCAL);
|
||||
expect(
|
||||
Workspace.Y.encodeStateAsUpdate(localWorkspace.blockSuiteWorkspace.doc)
|
||||
).toEqual(Workspace.Y.encodeStateAsUpdate(workspace.doc));
|
||||
|
||||
await CRUD.delete(localWorkspace);
|
||||
expect(await CRUD.get(id)).toBeNull();
|
||||
expect(await CRUD.list()).toEqual([]);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user