-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
399 additions
and
322 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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Command, EditorState } from 'prosemirror-state'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { EditorView } from 'prosemirror-view'; | ||
import { arrow } from '../src/input'; | ||
import { | ||
TaggedNode, | ||
c11, | ||
cCursor, | ||
cCursorBefore, | ||
selectionFor, | ||
table, | ||
tr, | ||
} from './build'; | ||
|
||
function test( | ||
doc: TaggedNode, | ||
command: Command, | ||
result: TaggedNode | null | undefined, | ||
) { | ||
let state = EditorState.create({ doc, selection: selectionFor(doc) }); | ||
let view = new EditorView(document.createElement('div'), { state }); | ||
let ran = command(state, (tr) => (state = state.apply(tr)), view); | ||
if (result == null) { | ||
expect(ran).toBe(false); | ||
} else { | ||
let expected = { | ||
doc: result.toJSON(), | ||
selection: selectionFor(result).toJSON(), | ||
}; | ||
let actual = state.toJSON(); | ||
expect(actual).toEqual(expected); | ||
} | ||
} | ||
|
||
describe('arrow', () => { | ||
it('can move cursor to the right cell', () => | ||
test( | ||
table(tr(c11, c11, c11), tr(c11, cCursor, c11), tr(c11, c11, c11)), | ||
arrow('horiz', 1), | ||
table(tr(c11, c11, c11), tr(c11, c11, cCursorBefore), tr(c11, c11, c11)), | ||
)); | ||
|
||
it('can move cursor to the left cell', () => | ||
test( | ||
table(tr(c11, c11, c11), tr(c11, c11, cCursorBefore), tr(c11, c11, c11)), | ||
arrow('horiz', -1), | ||
table(tr(c11, c11, c11), tr(c11, cCursor, c11), tr(c11, c11, c11)), | ||
)); | ||
|
||
it('can move cursor to the bottom cell', () => | ||
test( | ||
table(tr(c11, c11, c11), tr(c11, cCursorBefore, c11), tr(c11, c11, c11)), | ||
arrow('vert', 1), | ||
table(tr(c11, c11, c11), tr(c11, c11, c11), tr(c11, cCursorBefore, c11)), | ||
)); | ||
|
||
it('can move cursor to the top cell', () => | ||
test( | ||
table(tr(c11, c11, c11), tr(c11, c11, c11), tr(c11, cCursorBefore, c11)), | ||
arrow('vert', -1), | ||
table(tr(c11, c11, c11), tr(c11, cCursorBefore, c11), tr(c11, c11, c11)), | ||
)); | ||
}); |
Oops, something went wrong.