|
1 | 1 | import React from 'react' |
2 | 2 | import {describe, expect, test, vi} from 'vitest' |
| 3 | +import {userEvent} from 'vitest/browser' |
3 | 4 | import {defineSchema} from '../src' |
4 | 5 | import {InternalEditorEngineRefPlugin} from '../src/plugins/plugin.internal.editor-engine-ref' |
5 | 6 | import {NodePlugin} from '../src/plugins/plugin.node' |
@@ -36,6 +37,53 @@ describe('Performance', () => { |
36 | 37 | console.warn(`Inserted 1000 blocks in ${duration.toFixed(2)}ms`) |
37 | 38 | }) |
38 | 39 |
|
| 40 | + test('Typing 20 characters in a 1000-block document', async () => { |
| 41 | + const {editor, locator} = await createTestEditor() |
| 42 | + |
| 43 | + editor.send({ |
| 44 | + type: 'insert.blocks', |
| 45 | + blocks: Array.from({length: 1000}, (_, i) => ({ |
| 46 | + _type: 'block', |
| 47 | + _key: `b${i}`, |
| 48 | + children: [ |
| 49 | + {_type: 'span', _key: `s${i}`, text: `block ${i}`, marks: []}, |
| 50 | + ], |
| 51 | + markDefs: [], |
| 52 | + style: 'normal', |
| 53 | + })), |
| 54 | + placement: 'auto', |
| 55 | + }) |
| 56 | + |
| 57 | + await vi.waitFor(() => { |
| 58 | + expect(editor.getSnapshot().context.value.length).toBe(1000) |
| 59 | + |
| 60 | + expect(locator.getByText('block 999')).toBeInTheDocument() |
| 61 | + }) |
| 62 | + |
| 63 | + await userEvent.click(locator.getByText('block 500')) |
| 64 | + |
| 65 | + const start = performance.now() |
| 66 | + |
| 67 | + await userEvent.keyboard('performance!!!!!!!!!') |
| 68 | + |
| 69 | + await vi.waitFor(() => { |
| 70 | + const children = ( |
| 71 | + editor.getSnapshot().context.value[500] as { |
| 72 | + children?: Array<{text?: string}> |
| 73 | + } |
| 74 | + ).children |
| 75 | + expect( |
| 76 | + children?.some((child) => child.text?.includes('performance')), |
| 77 | + ).toBe(true) |
| 78 | + }) |
| 79 | + |
| 80 | + const duration = performance.now() - start |
| 81 | + |
| 82 | + console.warn( |
| 83 | + `Typed 20 characters in a 1000-block document in ${duration.toFixed(2)}ms`, |
| 84 | + ) |
| 85 | + }) |
| 86 | + |
39 | 87 | test('Inserting 1000 blocks before an existing block', async () => { |
40 | 88 | const {editor, locator} = await createTestEditor() |
41 | 89 |
|
|
0 commit comments