TestDocument.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import { createTestDocument } from './DocumentTestHelper';
  3. import { DocumentBackendService } from '../../stores/effects/document/document_bd_svc';
  4. async function testCreateDocument() {
  5. const view = await createTestDocument();
  6. const svc = new DocumentBackendService(view.id);
  7. const document = await svc.open().then((result) => result.unwrap());
  8. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  9. // const content = JSON.parse(document.content);
  10. // The initial document content:
  11. // {
  12. // "document": {
  13. // "type": "editor",
  14. // "children": [
  15. // {
  16. // "type": "text"
  17. // }
  18. // ]
  19. // }
  20. // }
  21. await svc.close();
  22. }
  23. export const TestCreateDocument = () => {
  24. return TestButton('Test create document', testCreateDocument);
  25. };
  26. const TestButton = (title: string, onClick: () => void) => {
  27. return (
  28. <React.Fragment>
  29. <div>
  30. <button className='rounded-md bg-purple-400 p-4' type='button' onClick={() => onClick()}>
  31. {title}
  32. </button>
  33. </div>
  34. </React.Fragment>
  35. );
  36. };