mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: rename document test (#1925)
This commit is contained in:
parent
7e7cee4bf4
commit
45045beeb9
@ -0,0 +1,10 @@
|
|||||||
|
import { ViewLayoutTypePB, WorkspaceSettingPB } from '../../../services/backend';
|
||||||
|
import { FolderEventReadCurrentWorkspace } from '../../../services/backend/events/flowy-folder';
|
||||||
|
import { AppBackendService } from '../../stores/effects/folder/app/app_bd_svc';
|
||||||
|
|
||||||
|
export async function createTestDocument() {
|
||||||
|
const workspaceSetting: WorkspaceSettingPB = await FolderEventReadCurrentWorkspace().then((result) => result.unwrap());
|
||||||
|
const app = workspaceSetting.workspace.apps.items[0];
|
||||||
|
const appService = new AppBackendService(app.id);
|
||||||
|
return await appService.createView({ name: 'New Document', layoutType: ViewLayoutTypePB.Document });
|
||||||
|
}
|
@ -21,6 +21,7 @@ import {
|
|||||||
TestMoveKanbanBoardColumn,
|
TestMoveKanbanBoardColumn,
|
||||||
TestMoveKanbanBoardRow,
|
TestMoveKanbanBoardRow,
|
||||||
} from './TestGroup';
|
} from './TestGroup';
|
||||||
|
import { TestCreateDocument } from './TestDocument';
|
||||||
|
|
||||||
export const TestAPI = () => {
|
export const TestAPI = () => {
|
||||||
return (
|
return (
|
||||||
@ -46,6 +47,7 @@ export const TestAPI = () => {
|
|||||||
<TestMoveKanbanBoardRow></TestMoveKanbanBoardRow>
|
<TestMoveKanbanBoardRow></TestMoveKanbanBoardRow>
|
||||||
<TestMoveKanbanBoardColumn></TestMoveKanbanBoardColumn>
|
<TestMoveKanbanBoardColumn></TestMoveKanbanBoardColumn>
|
||||||
<TestCreateKanbanBoardColumn></TestCreateKanbanBoardColumn>
|
<TestCreateKanbanBoardColumn></TestCreateKanbanBoardColumn>
|
||||||
|
<TestCreateDocument></TestCreateDocument>
|
||||||
</ul>
|
</ul>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { createTestDocument } from './DocumentTestHelper';
|
||||||
|
import { DocumentBackendService } from '../../stores/effects/document/document_bd_svc';
|
||||||
|
|
||||||
|
async function testCreateDocument() {
|
||||||
|
const view = await createTestDocument();
|
||||||
|
const svc = new DocumentBackendService(view.id);
|
||||||
|
const document = await svc.open().then((result) => result.unwrap());
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
const content = JSON.parse(document.content);
|
||||||
|
// The initial document content:
|
||||||
|
// {
|
||||||
|
// "document": {
|
||||||
|
// "type": "editor",
|
||||||
|
// "children": [
|
||||||
|
// {
|
||||||
|
// "type": "text"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
await svc.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TestCreateDocument = () => {
|
||||||
|
return TestButton('Test create document', testCreateDocument);
|
||||||
|
};
|
||||||
|
|
||||||
|
const TestButton = (title: string, onClick: () => void) => {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div>
|
||||||
|
<button className='rounded-md bg-purple-400 p-4' type='button' onClick={() => onClick()}>
|
||||||
|
{title}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
};
|
@ -0,0 +1,30 @@
|
|||||||
|
import {
|
||||||
|
DocumentDataPB,
|
||||||
|
DocumentVersionPB,
|
||||||
|
EditPayloadPB,
|
||||||
|
FlowyError,
|
||||||
|
OpenDocumentPayloadPB,
|
||||||
|
ViewIdPB,
|
||||||
|
} from '../../../../services/backend';
|
||||||
|
import { DocumentEventApplyEdit, DocumentEventGetDocument } from '../../../../services/backend/events/flowy-document';
|
||||||
|
import { Result } from 'ts-results';
|
||||||
|
import { FolderEventCloseView } from '../../../../services/backend/events/flowy-folder';
|
||||||
|
|
||||||
|
export class DocumentBackendService {
|
||||||
|
constructor(public readonly viewId: string) {}
|
||||||
|
|
||||||
|
open = (): Promise<Result<DocumentDataPB, FlowyError>> => {
|
||||||
|
const payload = OpenDocumentPayloadPB.fromObject({ document_id: this.viewId, version: DocumentVersionPB.V1 });
|
||||||
|
return DocumentEventGetDocument(payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
applyEdit = (operations: string) => {
|
||||||
|
const payload = EditPayloadPB.fromObject({ doc_id: this.viewId, operations: operations });
|
||||||
|
return DocumentEventApplyEdit(payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
close = () => {
|
||||||
|
const payload = ViewIdPB.fromObject({ value: this.viewId });
|
||||||
|
return FolderEventCloseView(payload);
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
export class Document {}
|
Loading…
x
Reference in New Issue
Block a user