refactor(infra): migrate to new infra (#5565)

This commit is contained in:
EYHN
2024-01-30 07:16:39 +00:00
parent 1e3499c323
commit 329fc19852
170 changed files with 2007 additions and 4354 deletions

View 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 };
}