mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-24 13:43:12 +02:00
Unit test: UndoManager
This commit is contained in:
parent
44e5b625a9
commit
82a398487b
33
.vscode/launch.json
vendored
33
.vscode/launch.json
vendored
@ -20,6 +20,35 @@
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "pwa-node"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Jest: run all tests",
|
||||
"program": "${workspaceRoot}/webapp/node_modules/jest/bin/jest.js",
|
||||
"cwd": "${workspaceRoot}/webapp",
|
||||
"args": [
|
||||
"--verbose",
|
||||
"-i",
|
||||
"--no-cache"
|
||||
],
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Jest: run current file",
|
||||
"program": "${workspaceRoot}/webapp/node_modules/jest/bin/jest.js",
|
||||
"cwd": "${workspaceRoot}/webapp",
|
||||
"args": [
|
||||
"${fileBasename}",
|
||||
"--verbose",
|
||||
"-i",
|
||||
"--no-cache",
|
||||
],
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
},
|
||||
]
|
||||
}
|
||||
|
46
webapp/src/undoManager.test.ts
Normal file
46
webapp/src/undoManager.test.ts
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import undoManager from './undomanager'
|
||||
import {Utils} from './utils'
|
||||
|
||||
test('Basic undo/redo', async () => {
|
||||
expect(!undoManager.canUndo).toBe(true)
|
||||
expect(!undoManager.canRedo).toBe(true)
|
||||
|
||||
const values: string[] = []
|
||||
|
||||
await undoManager.perform(
|
||||
async () => {
|
||||
values.push('a')
|
||||
},
|
||||
async () => {
|
||||
values.pop()
|
||||
},
|
||||
'test',
|
||||
)
|
||||
|
||||
expect(undoManager.canUndo).toBe(true)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
expect(Utils.arraysEqual(values, ['a'])).toBe(true)
|
||||
expect(undoManager.undoDescription).toBe('test')
|
||||
expect(undoManager.redoDescription).toBe(undefined)
|
||||
|
||||
await undoManager.undo()
|
||||
expect(undoManager.canUndo).toBe(false)
|
||||
expect(undoManager.canRedo).toBe(true)
|
||||
expect(Utils.arraysEqual(values, [])).toBe(true)
|
||||
expect(undoManager.undoDescription).toBe(undefined)
|
||||
expect(undoManager.redoDescription).toBe('test')
|
||||
|
||||
await undoManager.redo()
|
||||
expect(undoManager.canUndo).toBe(true)
|
||||
expect(undoManager.canRedo).toBe(false)
|
||||
expect(Utils.arraysEqual(values, ['a'])).toBe(true)
|
||||
|
||||
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 New Issue
Block a user