mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-21 00:07:01 +08:00
feat: add test about tauri ipc provider
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
import { PutBlob, GetBlob } from '../ipc/types/blob';
|
||||||
|
import {
|
||||||
|
YDocumentUpdate,
|
||||||
|
GetDocumentParameter,
|
||||||
|
GetDocumentResponse,
|
||||||
|
} from '../ipc/types/document';
|
||||||
|
import { CreateUser, User } from '../ipc/types/user';
|
||||||
|
import {
|
||||||
|
CreateWorkspace,
|
||||||
|
CreateWorkspaceResult,
|
||||||
|
GetWorkspaces,
|
||||||
|
GetWorkspacesResult,
|
||||||
|
GetWorkspace,
|
||||||
|
GetWorkspaceResult,
|
||||||
|
} from '../ipc/types/workspace';
|
||||||
|
|
||||||
|
export const updateYDocument = async (parameters: YDocumentUpdate) =>
|
||||||
|
await true;
|
||||||
|
|
||||||
|
export const getYDocument = async (
|
||||||
|
parameters: GetDocumentParameter
|
||||||
|
): Promise<GetDocumentResponse> =>
|
||||||
|
await {
|
||||||
|
updates: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createWorkspace = async (
|
||||||
|
parameters: CreateWorkspace
|
||||||
|
): Promise<CreateWorkspaceResult> => await { id: 'xxx', name: 'xxx' };
|
||||||
|
|
||||||
|
export const getWorkspaces = async (
|
||||||
|
parameters: GetWorkspaces
|
||||||
|
): Promise<GetWorkspacesResult> =>
|
||||||
|
await {
|
||||||
|
workspaces: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getWorkspace = async (
|
||||||
|
parameters: GetWorkspace
|
||||||
|
): Promise<GetWorkspaceResult> =>
|
||||||
|
await {
|
||||||
|
workspace: {
|
||||||
|
created_at: 0,
|
||||||
|
id: '',
|
||||||
|
member_count: 1,
|
||||||
|
public: true,
|
||||||
|
type: 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const putBlob = async (parameters: PutBlob): Promise<string> =>
|
||||||
|
await 'path/xxx';
|
||||||
|
|
||||||
|
export const getBlob = async (parameters: GetBlob): Promise<number[]> =>
|
||||||
|
await [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will create a private workspace too.
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const createUser = async (parameters: CreateUser): Promise<User> =>
|
||||||
|
await {
|
||||||
|
created_at: 0,
|
||||||
|
id: 1,
|
||||||
|
email: 'xxx@xxx.xxx',
|
||||||
|
name: 'xxx',
|
||||||
|
};
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
import { WorkspaceUnitCollection } from '../../../workspace-unit-collection.js';
|
||||||
|
import { TauriIPCProvider } from '../index.js';
|
||||||
|
import { MessageCenter } from '../../../message/index.js';
|
||||||
|
import * as ipcMethods from './mock-apis.js';
|
||||||
|
|
||||||
|
test.describe.serial('tauri-ipc provider', async () => {
|
||||||
|
const workspaceMetaCollection = new WorkspaceUnitCollection();
|
||||||
|
const provider = new TauriIPCProvider({
|
||||||
|
workspaces: workspaceMetaCollection.createScope(),
|
||||||
|
messageCenter: new MessageCenter(),
|
||||||
|
});
|
||||||
|
provider.init(ipcMethods);
|
||||||
|
|
||||||
|
const workspaceName = 'workspace-test';
|
||||||
|
let workspaceId: string | undefined;
|
||||||
|
|
||||||
|
test('create workspace', async () => {
|
||||||
|
const workspaceUnit = await provider.createWorkspace({
|
||||||
|
name: workspaceName,
|
||||||
|
});
|
||||||
|
workspaceId = workspaceUnit?.id;
|
||||||
|
|
||||||
|
expect(workspaceMetaCollection.workspaces.length).toEqual(1);
|
||||||
|
expect(workspaceMetaCollection.workspaces[0].name).toEqual(workspaceName);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('workspace list cache', async () => {
|
||||||
|
const workspacesMetaCollection1 = new WorkspaceUnitCollection();
|
||||||
|
const provider1 = new TauriIPCProvider({
|
||||||
|
workspaces: workspacesMetaCollection1.createScope(),
|
||||||
|
messageCenter: new MessageCenter(),
|
||||||
|
});
|
||||||
|
await provider1.loadWorkspaces();
|
||||||
|
expect(workspacesMetaCollection1.workspaces.length).toEqual(1);
|
||||||
|
expect(workspacesMetaCollection1.workspaces[0].name).toEqual(workspaceName);
|
||||||
|
expect(workspacesMetaCollection1.workspaces[0].id).toEqual(workspaceId);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('update workspace', async () => {
|
||||||
|
await provider.updateWorkspaceMeta(workspaceId!, {
|
||||||
|
name: '1111',
|
||||||
|
});
|
||||||
|
expect(workspaceMetaCollection.workspaces[0].name).toEqual('1111');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user