-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Delete was deleting line block style * Insert was not working properly
- Loading branch information
1 parent
66d6c5d
commit 2c82bc6
Showing
9 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,10 +37,10 @@ | |
}, | ||
"devDependencies": { | ||
"@testing-library/dom": "^10.1.0", | ||
"@testing-library/react": "^15.0.5", | ||
"@testing-library/react": "^15.0.6", | ||
"@testing-library/user-event": "^14.5.2", | ||
"@types/lodash": "^4.17.0", | ||
"@types/node": "^20.12.7", | ||
"@types/node": "^20.12.8", | ||
"@types/react": "^18.3.1", | ||
"@types/react-dom": "^18.3.0", | ||
"@types/react-router-dom": "^5.3.3", | ||
|
@@ -67,5 +67,6 @@ | |
"vite-plugin-qrcode": "^0.2.3", | ||
"vite-tsconfig-paths": "^4.3.2", | ||
"vitest": "^1.5.3" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha256.0624e30eff866cdeb363b15061bdb7fd9425b17bc1bb42c22f5f4efdea21f6b3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
126 changes: 126 additions & 0 deletions
126
code/client/tests/editor/slate/handlers/history/cut.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import {describe, test, expect, beforeEach} from "vitest"; | ||
import {BaseRemoveTextOperation, Editor} from "slate"; | ||
import {Fugue} from "@domain/editor/crdt/fugue"; | ||
import { | ||
removeText, | ||
mockEditor, | ||
toBatch, | ||
applyBatch, | ||
getUndoOperations, getRedoOperations, removeNode | ||
} from "@tests/editor/slate/handlers/history/utils"; | ||
import {toSlate} from "@domain/editor/slate/utils/slate"; | ||
import {InsertTextOperation, RemoveTextOperation} from "@domain/editor/operations/history/types"; | ||
import {pointToCursor} from "@domain/editor/slate/utils/selection"; | ||
import {nodeInsert} from "@domain/editor/crdt/utils"; | ||
|
||
|
||
let editor: Editor | ||
let fugue : Fugue | ||
|
||
beforeEach(() => { | ||
editor = mockEditor(); | ||
fugue = new Fugue(); | ||
}); | ||
|
||
describe('Single line', () => { | ||
|
||
describe('Single style', () => { | ||
|
||
const cutSingleLine = () => { | ||
fugue.insertLocal({line: 0, column: 0}, ...'abcdef'.split('')); | ||
editor.children = toSlate(fugue); | ||
|
||
const batch = toBatch( | ||
removeText('abcdef', [0,0], 0) | ||
); | ||
applyBatch(editor, batch); | ||
} | ||
|
||
beforeEach(cutSingleLine); | ||
|
||
test('Should undo cut', () => { | ||
const {operations} = getUndoOperations(editor, 1) | ||
|
||
const operation = operations[0] as InsertTextOperation; | ||
|
||
expect(operation.text).toStrictEqual('abcdef'.split('')); | ||
expect(operation.cursor).toEqual({line: 0, column: 0}); | ||
|
||
}); | ||
|
||
test('Should redo cut', () => { | ||
|
||
const {operations, editorBatch} = getRedoOperations(editor, 1) | ||
|
||
const operation = operations[0] as RemoveTextOperation; | ||
const editorOperation = editorBatch!.operations[0] as BaseRemoveTextOperation; | ||
|
||
expect(operation.selection).toEqual( | ||
{ | ||
start: pointToCursor(editor, {path: editorOperation.path, offset: 0}), | ||
end: pointToCursor(editor, {path: editorOperation.path, offset: editorOperation.offset + editorOperation.text.length - 1}) | ||
} | ||
) | ||
}); | ||
}); | ||
|
||
describe('Multiple styles', () => { | ||
const cutMultipleStyles = () => { | ||
fugue.insertLocal({line: 0, column: 0}, ...'abc'.split('')); | ||
fugue.insertLocal({line: 0, column: 3}, | ||
nodeInsert('text', ['bold']), | ||
nodeInsert('text', ['italic']), | ||
); | ||
editor.children = toSlate(fugue); | ||
|
||
const batch = toBatch( | ||
removeText('abc', [0, 0], 0), | ||
removeText('text', [0, 1], 0), | ||
removeNode({text: ''}, [0, 1]), | ||
removeText('text', [0, 2], 0), | ||
removeNode({text: ''}, [0, 2]), | ||
); | ||
editor.history.undos = [batch]; | ||
} | ||
|
||
beforeEach(cutMultipleStyles); | ||
|
||
test('Should undo cut', () => { | ||
const {operations, editorBatch} = getUndoOperations(editor, 3); // remove node op. with empty text are ignored | ||
|
||
const editorOperations = editorBatch!.operations.filter(op => | ||
op.type === 'remove_text') as BaseRemoveTextOperation[]; | ||
|
||
|
||
for (const i in operations) { | ||
const operation = operations[i] as InsertTextOperation; | ||
const editorOperation = editorOperations[i]; | ||
|
||
expect(operation.text).toStrictEqual(editorOperation.text.split('')); | ||
expect(operation.cursor).toEqual(pointToCursor(editor, {path: editorOperation.path, offset: editorOperation.offset})); | ||
} | ||
}); | ||
|
||
test('Should redo cut', () => { | ||
const {operations, editorBatch} = getRedoOperations(editor, 3); | ||
|
||
const editorOperations = editorBatch!.operations.filter(op => | ||
op.type === 'remove_text') as BaseRemoveTextOperation[]; | ||
|
||
for (const i in operations) { | ||
const operation = operations[i] as RemoveTextOperation; | ||
const editorOperation = editorOperations[i]; | ||
|
||
expect(operation.selection).toEqual({ | ||
start: pointToCursor(editor, {path: editorOperation.path, offset: editorOperation.offset}), | ||
end: pointToCursor(editor, {path: editorOperation.path, offset: editorOperation.offset + editorOperation.text.length - 1}) | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
// describe('Multiple lines', () => { | ||
// | ||
// | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
"@types/express": "^4.17.21", | ||
"@types/jest": "^29.5.12", | ||
"@types/lodash": "^4.17.0", | ||
"@types/node": "^20.12.7", | ||
"@types/node": "^20.12.8", | ||
"@types/supertest": "^6.0.2", | ||
"@types/uuid": "^9.0.8", | ||
"@typescript-eslint/eslint-plugin": "^7.8.0", | ||
|
@@ -46,5 +46,6 @@ | |
"tsconfig-paths": "^4.2.0", | ||
"tsx": "^4.8.2", | ||
"typescript": "^5.4.5" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha256.0624e30eff866cdeb363b15061bdb7fd9425b17bc1bb42c22f5f4efdea21f6b3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters