Unit test: grouped undo/redo
This commit is contained in:
parent
82a398487b
commit
b1b6d5b070
2 changed files with 80 additions and 6 deletions
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
@ -29,8 +29,6 @@
|
|||
"cwd": "${workspaceRoot}/webapp",
|
||||
"args": [
|
||||
"--verbose",
|
||||
"-i",
|
||||
"--no-cache"
|
||||
],
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
|
@ -44,8 +42,6 @@
|
|||
"args": [
|
||||
"${fileBasename}",
|
||||
"--verbose",
|
||||
"-i",
|
||||
"--no-cache",
|
||||
],
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
|
|
|
@ -5,8 +5,8 @@ import undoManager from './undomanager'
|
|||
import {Utils} from './utils'
|
||||
|
||||
test('Basic undo/redo', async () => {
|
||||
expect(!undoManager.canUndo).toBe(true)
|
||||
expect(!undoManager.canRedo).toBe(true)
|
||||
expect(undoManager.canUndo).toBe(false)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
|
||||
const values: string[] = []
|
||||
|
||||
|
@ -44,3 +44,81 @@ test('Basic undo/redo', async () => {
|
|||
expect(undoManager.undoDescription).toBe(undefined)
|
||||
expect(undoManager.redoDescription).toBe(undefined)
|
||||
})
|
||||
|
||||
test('Grouped undo/redo', async () => {
|
||||
expect(undoManager.canUndo).toBe(false)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
|
||||
const values: string[] = []
|
||||
const groupId = 'the group id'
|
||||
|
||||
await undoManager.perform(
|
||||
async () => {
|
||||
values.push('a')
|
||||
},
|
||||
async () => {
|
||||
values.pop()
|
||||
},
|
||||
'insert a',
|
||||
)
|
||||
|
||||
expect(undoManager.canUndo).toBe(true)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
expect(Utils.arraysEqual(values, ['a'])).toBe(true)
|
||||
expect(undoManager.undoDescription).toBe('insert a')
|
||||
expect(undoManager.redoDescription).toBe(undefined)
|
||||
|
||||
await undoManager.perform(
|
||||
async () => {
|
||||
values.push('b')
|
||||
},
|
||||
async () => {
|
||||
values.pop()
|
||||
},
|
||||
'insert b',
|
||||
groupId,
|
||||
)
|
||||
|
||||
expect(undoManager.canUndo).toBe(true)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
expect(Utils.arraysEqual(values, ['a', 'b'])).toBe(true)
|
||||
expect(undoManager.undoDescription).toBe('insert b')
|
||||
expect(undoManager.redoDescription).toBe(undefined)
|
||||
|
||||
await undoManager.perform(
|
||||
async () => {
|
||||
values.push('c')
|
||||
},
|
||||
async () => {
|
||||
values.pop()
|
||||
},
|
||||
'insert c',
|
||||
groupId,
|
||||
)
|
||||
|
||||
expect(undoManager.canUndo).toBe(true)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
expect(Utils.arraysEqual(values, ['a', 'b', 'c'])).toBe(true)
|
||||
expect(undoManager.undoDescription).toBe('insert c')
|
||||
expect(undoManager.redoDescription).toBe(undefined)
|
||||
|
||||
await undoManager.undo()
|
||||
expect(undoManager.canUndo).toBe(true)
|
||||
expect(undoManager.canRedo).toBe(true)
|
||||
expect(Utils.arraysEqual(values, ['a'])).toBe(true)
|
||||
expect(undoManager.undoDescription).toBe('insert a')
|
||||
expect(undoManager.redoDescription).toBe('insert b')
|
||||
|
||||
await undoManager.redo()
|
||||
expect(undoManager.canUndo).toBe(true)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
expect(Utils.arraysEqual(values, ['a', 'b', 'c'])).toBe(true)
|
||||
expect(undoManager.undoDescription).toBe('insert c')
|
||||
expect(undoManager.redoDescription).toBe(undefined)
|
||||
|
||||
await undoManager.clear()
|
||||
expect(undoManager.canUndo).toBe(false)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
expect(undoManager.undoDescription).toBe(undefined)
|
||||
expect(undoManager.redoDescription).toBe(undefined)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue