mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(infra): migrate to new infra (#5565)
This commit is contained in:
46
packages/frontend/core/src/testing.ts
Normal file
46
packages/frontend/core/src/testing.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import type { Page as BlockSuitePage } from '@blocksuite/store';
|
||||
import {
|
||||
configureTestingInfraServices,
|
||||
PageManager,
|
||||
ServiceCollection,
|
||||
WorkspaceManager,
|
||||
} from '@toeverything/infra';
|
||||
|
||||
import { CurrentPageService } from './modules/page';
|
||||
import { CurrentWorkspaceService } from './modules/workspace';
|
||||
import { configureWebServices } from './web';
|
||||
|
||||
export async function configureTestingEnvironment() {
|
||||
const serviceCollection = new ServiceCollection();
|
||||
|
||||
configureWebServices(serviceCollection);
|
||||
configureTestingInfraServices(serviceCollection);
|
||||
|
||||
const rootServices = serviceCollection.provider();
|
||||
|
||||
const workspaceManager = rootServices.get(WorkspaceManager);
|
||||
|
||||
const { workspace } = workspaceManager.open(
|
||||
await workspaceManager.createWorkspace(WorkspaceFlavour.LOCAL, async ws => {
|
||||
const initPage = async (page: BlockSuitePage) => {
|
||||
await page.load();
|
||||
const pageBlockId = page.addBlock('affine:page', {
|
||||
title: new page.Text(''),
|
||||
});
|
||||
const frameId = page.addBlock('affine:note', {}, pageBlockId);
|
||||
page.addBlock('affine:paragraph', {}, frameId);
|
||||
};
|
||||
await initPage(ws.createPage({ id: 'page0' }));
|
||||
})
|
||||
);
|
||||
|
||||
await workspace.engine.sync.waitForSynced();
|
||||
|
||||
const { page } = workspace.services.get(PageManager).openByPageId('page0');
|
||||
|
||||
rootServices.get(CurrentWorkspaceService).openWorkspace(workspace);
|
||||
workspace.services.get(CurrentPageService).openPage(page);
|
||||
|
||||
return { services: rootServices, workspace, page };
|
||||
}
|
||||
Reference in New Issue
Block a user