Skip to content

Commit 87b98fc

Browse files
committed
test: TestUndoRedoInteraction + update .golden files
1 parent b679707 commit 87b98fc

13 files changed

+69
-36
lines changed

main_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,35 @@ func TestCollapseRecursiveWithSizes(t *testing.T) {
129129
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")})
130130
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second))
131131
}
132+
133+
func TestUndoRedoInteraction(t *testing.T) {
134+
tm := prepare(t)
135+
targetKey := []byte(`"title"`)
136+
137+
// Leave root, then delete (first key)
138+
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("j")})
139+
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("d")})
140+
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("d")})
141+
142+
// Verify the node is gone from the output
143+
teatest.WaitFor(t, tm.Output(), func(b []byte) bool {
144+
return !bytes.Contains(b, targetKey)
145+
}, teatest.WithDuration(time.Second))
146+
147+
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("u")})
148+
149+
// Verify the node reappeared
150+
teatest.WaitFor(t, tm.Output(), func(b []byte) bool {
151+
return bytes.Contains(b, targetKey)
152+
}, teatest.WithDuration(time.Second))
153+
154+
tm.Send(tea.KeyMsg{Type: tea.KeyCtrlR})
155+
156+
// Verify it is gone again
157+
teatest.WaitFor(t, tm.Output(), func(b []byte) bool {
158+
return !bytes.Contains(b, targetKey)
159+
}, teatest.WithDuration(time.Second))
160+
161+
tm.Send(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("q")})
162+
tm.WaitFinished(t)
163+
}

testdata/TestCollapseRecursive.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"tags": […],
1010
"year": 3000,
1111
"funny": true,
12-
"author": {"name":"John Doe",…}
12+
"author": {"name":"John Doe",…},
13+
"hasAvatar": true
1314
}
1415
~
1516
~
@@ -35,6 +36,5 @@
3536
~
3637
~
3738
~
38-
~
3939
~
4040
1% 

testdata/TestCollapseRecursiveWithSizes.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[?25l[?2004h{ (6 keys)
1+
[?25l[?2004h{ (7 keys)
22
"title": "Lorem ipsum",
33
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusm
44
od tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam
@@ -9,7 +9,8 @@
99
"tags": […], (3 items)
1010
"year": 3000,
1111
"funny": true,
12-
"author": {"name":"John Doe",…} (2 keys)
12+
"author": {"name":"John Doe",…}, (2 keys)
13+
"hasAvatar": true
1314
}
1415
~
1516
~
@@ -35,6 +36,5 @@
3536
~
3637
~
3738
~
38-
~
3939
~
4040
1% 

testdata/TestDig.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"author": {
1717
"name": "John Doe",
1818
"email": "john@doe.com"
19-
}
19+
},
20+
"hasAvatar": true
2021
}
2122
~
2223
~
@@ -36,5 +37,4 @@
3637
~
3738
~
3839
~
39-
~
40-
.year 60% 
40+
.year 56% 

testdata/TestGotoLine.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
11 "author": {
1818
12 "name": "John Doe",
1919
13 "email": "john@doe.com"
20-
14 }
21-
15 }
20+
14 },
21+
15 "hasAvatar": true
22+
16 }
2223
~
2324
~
2425
~
@@ -36,5 +37,4 @@
3637
~
3738
~
3839
~
39-
~
40-
.tags[0] 33% 
40+
.tags[0] 31% 

testdata/TestGotoLineCollapsed.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
 8 ],
1515
 9 "year": 3000,
1616
10 "funny": true,
17-
11 "author": {"name":"John Doe",…}
18-
15 }
17+
11 "author": {"name":"John Doe",…},
18+
15 "hasAvatar": true
19+
16 }
1920
~
2021
~
2122
~
@@ -36,5 +37,4 @@
3637
~
3738
~
3839
~
39-
~
40-
.tags[0] 33% 
40+
.tags[0] 31% 

testdata/TestGotoLineInputGreaterThanTotalLines.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
11 "author": {
1818
12 "name": "John Doe",
1919
13 "email": "john@doe.com"
20-
14 }
21-
15 }
22-
~
20+
14 },
21+
15 "hasAvatar": true
22+
16 }
2323
~
2424
~
2525
~

testdata/TestGotoLineInputInvalid.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
 4 "tags": […],
1111
 9 "year": 3000,
1212
10 "funny": true,
13-
11 "author": {"name":"John Doe",…}
14-
15 }
13+
11 "author": {"name":"John Doe",…},
14+
15 "hasAvatar": true
15+
16 }
1516
~
1617
~
1718
~
@@ -36,5 +37,4 @@
3637
~
3738
~
3839
~
39-
~
40-
.text 20% 
40+
.text 18% 

testdata/TestGotoLineInputLessThanOne.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
11 "author": {
1818
12 "name": "John Doe",
1919
13 "email": "john@doe.com"
20-
14 }
21-
15 }
22-
~
20+
14 },
21+
15 "hasAvatar": true
22+
16 }
2323
~
2424
~
2525
~

testdata/TestGotoLineKeepsHistory.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
11 "author": {
1818
12 "name": "John Doe",
1919
13 "email": "john@doe.com"
20-
14 }
21-
15 }
20+
14 },
21+
15 "hasAvatar": true
22+
16 }
2223
~
2324
~
2425
~
@@ -36,5 +37,4 @@
3637
~
3738
~
3839
~
39-
~
40-
.tags 26% 
40+
.tags 25% 

0 commit comments

Comments
 (0)