-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathlist_formatting_test.js
More file actions
150 lines (138 loc) · 5.57 KB
/
Copy pathlist_formatting_test.js
File metadata and controls
150 lines (138 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import * as config from "trix/config"
import {
assert,
clickToolbarButton,
expectDocument,
moveCursor,
pressKey,
test,
testGroup,
testIf,
triggerEvent,
typeCharacters,
} from "test/test_helper"
import { nextFrame } from "../test_helpers/timing_helpers"
testGroup("List formatting", { template: "editor_empty" }, () => {
test("creating a new list item", async () => {
await typeCharacters("a")
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("\n")
assert.locationRange({ index: 1, offset: 0 })
assert.blockAttributes([ 0, 2 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 2, 3 ], [ "bulletList", "bullet" ])
})
test("breaking out of a list", async () => {
await typeCharacters("a")
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("\n\n")
assert.blockAttributes([ 0, 2 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 2, 3 ], [])
expectDocument("a\n\n")
})
test("pressing return at the beginning of a non-empty list item", async () => {
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("a\nb")
await moveCursor("left")
await pressKey("return")
assert.blockAttributes([ 0, 2 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 2, 3 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 3, 5 ], [ "bulletList", "bullet" ])
expectDocument("a\n\nb\n")
})
test("pressing tab increases nesting level, tab+shift decreases nesting level", async () => {
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("a")
await pressKey("return")
await pressKey("tab")
await typeCharacters("b")
assert.blockAttributes([ 0, 1 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 2, 3 ], [ "bulletList", "bullet", "bulletList", "bullet" ])
await nextFrame()
// press shift tab
triggerEvent(document.activeElement, "keydown", {
key: "Tab",
charCode: 0,
keyCode: 9,
which: 9,
shiftKey: true,
})
assert.blockAttributes([ 0, 1 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 2, 3 ], [ "bulletList", "bullet" ])
expectDocument("a\nb\n")
})
testIf(config.input.getLevel() === 0, "pressing shift-return at the end of a list item", async () => {
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("a")
const pressShiftReturn = triggerEvent(document.activeElement, "keydown", {
charCode: 0,
keyCode: 13,
which: 13,
shiftKey: true,
})
assert.notOk(pressShiftReturn) // Assert defaultPrevented
assert.blockAttributes([ 0, 2 ], [ "bulletList", "bullet" ])
expectDocument("a\n\n")
})
test("pressing delete at the beginning of a non-empty nested list item", async () => {
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("a\n")
await clickToolbarButton({ action: "increaseNestingLevel" })
await typeCharacters("b\n")
await clickToolbarButton({ action: "increaseNestingLevel" })
await typeCharacters("c")
getSelectionManager().setLocationRange({ index: 1, offset: 0 })
getComposition().deleteInDirection("backward")
getEditorController().render()
await nextFrame()
assert.blockAttributes([ 0, 2 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 3, 4 ], [ "bulletList", "bullet", "bulletList", "bullet" ])
expectDocument("ab\nc\n")
})
test("increasing nesting level applies to all selected items", async () => {
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("a\nb\nc")
getSelectionManager().setLocationRange([
{ index: 0, offset: 0 },
{ index: 2, offset: 1 },
])
await clickToolbarButton({ action: "increaseNestingLevel" })
assert.blockAttributes([ 0, 2 ], [ "bulletList", "bullet", "bulletList", "bullet" ])
assert.blockAttributes([ 2, 4 ], [ "bulletList", "bullet", "bulletList", "bullet" ])
assert.blockAttributes([ 4, 6 ], [ "bulletList", "bullet", "bulletList", "bullet" ])
expectDocument("a\nb\nc\n")
})
test("decreasing nesting level applies to all selected items", async () => {
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("a\n")
await clickToolbarButton({ action: "increaseNestingLevel" })
await typeCharacters("b\n")
await clickToolbarButton({ action: "increaseNestingLevel" })
await typeCharacters("c")
getSelectionManager().setLocationRange([
{ index: 1, offset: 0 },
{ index: 2, offset: 1 },
])
await clickToolbarButton({ action: "decreaseNestingLevel" })
assert.blockAttributes([ 0, 2 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 2, 4 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 4, 6 ], [ "bulletList", "bullet", "bulletList", "bullet" ])
expectDocument("a\nb\nc\n")
})
test("decreasing list item's level decreases its nested items level too", async () => {
await clickToolbarButton({ attribute: "bullet" })
await typeCharacters("a\n")
await clickToolbarButton({ action: "increaseNestingLevel" })
await typeCharacters("b\n")
await clickToolbarButton({ action: "increaseNestingLevel" })
await typeCharacters("c")
getSelectionManager().setLocationRange({ index: 1, offset: 1 })
for (let n = 0; n < 3; n++) {
getComposition().deleteInDirection("backward")
getEditorController().render()
}
assert.blockAttributes([ 0, 2 ], [ "bulletList", "bullet" ])
assert.blockAttributes([ 2, 3 ], [])
assert.blockAttributes([ 3, 5 ], [ "bulletList", "bullet" ])
expectDocument("a\n\nc\n")
})
})