Skip to content

Commit 3876408

Browse files
committed
Add integration test for accordion mode
1 parent a5ee61c commit 3876408

File tree

12 files changed

+168
-17
lines changed

12 files changed

+168
-17
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/integrii/flaggy v1.4.0
1919
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68
2020
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d
21-
github.com/jesseduffield/gocui v0.3.1-0.20230719103719-ea5c8b64cf35
21+
github.com/jesseduffield/gocui v0.3.1-0.20230719120401-398f4965241f
2222
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
2323
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
2424
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 h1:EQP2Tv8T
7272
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
7373
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d h1:bO+OmbreIv91rCe8NmscRwhFSqkDJtzWCPV4Y+SQuXE=
7474
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
75-
github.com/jesseduffield/gocui v0.3.1-0.20230719103719-ea5c8b64cf35 h1:ZWI/Tkg89iTpZDuxWYsR/f6xu+U827N8L1YnSvqug88=
76-
github.com/jesseduffield/gocui v0.3.1-0.20230719103719-ea5c8b64cf35/go.mod h1:dJ/BEUt3OWtaRg/PmuJWendRqREhre9JQ1SLvqrVJ8s=
75+
github.com/jesseduffield/gocui v0.3.1-0.20230719120401-398f4965241f h1:w/pxI34XepTAx4HwxUu8ipimbVRgSTS+7ahmgFQwH80=
76+
github.com/jesseduffield/gocui v0.3.1-0.20230719120401-398f4965241f/go.mod h1:dJ/BEUt3OWtaRg/PmuJWendRqREhre9JQ1SLvqrVJ8s=
7777
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
7878
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
7979
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY=

pkg/gui/gui.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,29 @@ var RuneReplacements = map[rune]string{
522522
}
523523

524524
func (gui *Gui) initGocui(headless bool, test integrationTypes.IntegrationTest) (*gocui.Gui, error) {
525-
playRecording := test != nil && os.Getenv(components.SANDBOX_ENV_VAR) != "true"
525+
runInSandbox := os.Getenv(components.SANDBOX_ENV_VAR) == "true"
526+
playRecording := test != nil && !runInSandbox
527+
528+
width, height := 0, 0
529+
if test != nil {
530+
if test.RequiresHeadless() {
531+
if runInSandbox {
532+
panic("Test requires headless, can't run in sandbox")
533+
}
534+
headless = true
535+
width, height = test.HeadlessDimensions()
536+
}
537+
}
526538

527-
g, err := gocui.NewGui(gocui.OutputTrue, OverlappingEdges, playRecording, headless, RuneReplacements)
539+
g, err := gocui.NewGui(gocui.NewGuiOpts{
540+
OutputMode: gocui.OutputTrue,
541+
SupportOverlaps: OverlappingEdges,
542+
PlayRecording: playRecording,
543+
Headless: headless,
544+
RuneReplacements: RuneReplacements,
545+
Width: width,
546+
Height: height,
547+
})
528548
if err != nil {
529549
return nil, err
530550
}

pkg/integration/clients/tui.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ func RunTUI() {
2828
app := newApp(testDir)
2929
app.loadTests()
3030

31-
g, err := gocui.NewGui(gocui.OutputTrue, false, false, false, gui.RuneReplacements)
31+
g, err := gocui.NewGui(gocui.NewGuiOpts{
32+
OutputMode: gocui.OutputTrue,
33+
RuneReplacements: gui.RuneReplacements,
34+
})
3235
if err != nil {
3336
log.Panicln(err)
3437
}

pkg/integration/components/test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import (
1919
// to get the test's name via it's file's path.
2020
const unitTestDescription = "test test"
2121

22+
const (
23+
defaultWidth = 100
24+
defaultHeight = 100
25+
)
26+
2227
type IntegrationTest struct {
2328
name string
2429
description string
@@ -32,6 +37,8 @@ type IntegrationTest struct {
3237
keys config.KeybindingConfig,
3338
)
3439
gitVersion GitVersionRestriction
40+
width int
41+
height int
3542
}
3643

3744
var _ integrationTypes.IntegrationTest = &IntegrationTest{}
@@ -52,6 +59,11 @@ type NewIntegrationTestArgs struct {
5259
Skip bool
5360
// to run a test only on certain git versions
5461
GitVersion GitVersionRestriction
62+
// width and height when running in headless mode, for testing
63+
// the UI in different sizes.
64+
// If these are set, the test must be run in headless mode
65+
Width int
66+
Height int
5567
}
5668

5769
type GitVersionRestriction struct {
@@ -120,6 +132,8 @@ func NewIntegrationTest(args NewIntegrationTestArgs) *IntegrationTest {
120132
setupConfig: args.SetupConfig,
121133
run: args.Run,
122134
gitVersion: args.GitVersion,
135+
width: args.Width,
136+
height: args.Height,
123137
}
124138
}
125139

@@ -172,6 +186,18 @@ func (self *IntegrationTest) Run(gui integrationTypes.GuiDriver) {
172186
}
173187
}
174188

189+
func (self *IntegrationTest) HeadlessDimensions() (int, int) {
190+
if self.width == 0 && self.height == 0 {
191+
return defaultWidth, defaultHeight
192+
}
193+
194+
return self.width, self.height
195+
}
196+
197+
func (self *IntegrationTest) RequiresHeadless() bool {
198+
return self.width != 0 && self.height != 0
199+
}
200+
175201
func testNameFromCurrentFilePath() string {
176202
path := utils.FilePath(3)
177203
return TestNameFromFilePath(path)

pkg/integration/components/view_driver.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ func (self *ViewDriver) TopLines(matchers ...*TextMatcher) *ViewDriver {
8282
return self.assertLines(0, matchers...)
8383
}
8484

85+
// Asserts on the visible lines of the view.
86+
// Note, this assumes that the view's viewport is filled with lines
87+
func (self *ViewDriver) VisibleLines(matchers ...*TextMatcher) *ViewDriver {
88+
self.validateMatchersPassed(matchers)
89+
self.validateVisibleLineCount(matchers)
90+
91+
// Get the origin of the view and offset that.
92+
// Note that we don't do any retrying here so if we want to bring back retry logic
93+
// we'll need to update this.
94+
originY := self.getView().OriginY()
95+
96+
return self.assertLines(originY, matchers...)
97+
}
98+
8599
// asserts that somewhere in the view there are consequetive lines matching the given matchers.
86100
func (self *ViewDriver) ContainsLines(matchers ...*TextMatcher) *ViewDriver {
87101
self.validateMatchersPassed(matchers)
@@ -212,6 +226,16 @@ func (self *ViewDriver) validateEnoughLines(matchers []*TextMatcher) {
212226
})
213227
}
214228

229+
// assumes the view's viewport is filled with lines
230+
func (self *ViewDriver) validateVisibleLineCount(matchers []*TextMatcher) {
231+
view := self.getView()
232+
233+
self.t.assertWithRetries(func() (bool, string) {
234+
count := view.InnerHeight() + 1
235+
return count == len(matchers), fmt.Sprintf("unexpected number of visible lines in view '%s'. Expected exactly %d, got %d", view.Name(), len(matchers), count)
236+
})
237+
}
238+
215239
func (self *ViewDriver) assertLines(offset int, matchers ...*TextMatcher) *ViewDriver {
216240
view := self.getView()
217241

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ var tests = []*components.IntegrationTest{
209209
tag.CrudAnnotated,
210210
tag.CrudLightweight,
211211
tag.Reset,
212+
ui.Accordion,
212213
ui.DoublePopup,
213214
ui.SwitchTabFromMenu,
214215
undo.UndoCheckoutAndDrop,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package ui
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
// When in acccordion mode, Lazygit looks like this:
9+
//
10+
// ╶─Status─────────────────────────╴┌─Patch──────────────────────────────────────────────────────────┐
11+
// ╶─Files - Submodules──────0 of 0─╴│commit 6e56dd04b70e548976f7f2928c4d9c359574e2bc ▲
12+
// ╶─Local branches - Remotes1 of 1─╴│Author: CI <[email protected]> █
13+
// ┌─Commits - Reflog───────────────┐│Date: Wed Jul 19 22:00:03 2023 +1000 │
14+
// │7fe02805 CI commit 12 ▲│ ▼
15+
// │6e56dd04 CI commit 11 █└────────────────────────────────────────────────────────────────┘
16+
// │a35c687d CI commit 10 ▼┌─Command log────────────────────────────────────────────────────┐
17+
// └───────────────────────10 of 20─┘│Random tip: To filter commits by path, press '<c-s>' │
18+
// ╶─Stash───────────────────0 of 0─╴└────────────────────────────────────────────────────────────────┘
19+
// <pgup>/<pgdown>: Scroll, <esc>: Cancel, q: Quit, ?: Keybindings, 1-Donate Ask Question unversioned
20+
21+
var Accordion = NewIntegrationTest(NewIntegrationTestArgs{
22+
Description: "Verify accordion mode kicks in when the screen height is too small",
23+
ExtraCmdArgs: []string{},
24+
Width: 100,
25+
Height: 10,
26+
Skip: false,
27+
SetupConfig: func(config *config.AppConfig) {},
28+
SetupRepo: func(shell *Shell) {
29+
shell.CreateNCommits(20)
30+
},
31+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
32+
t.Views().Commits().
33+
Focus().
34+
VisibleLines(
35+
Contains("commit 20").IsSelected(),
36+
Contains("commit 19"),
37+
Contains("commit 18"),
38+
).
39+
// go past commit 11, then come back, so that it ends up in the centre of the viewport
40+
NavigateToLine(Contains("commit 11")).
41+
NavigateToLine(Contains("commit 10")).
42+
NavigateToLine(Contains("commit 11")).
43+
VisibleLines(
44+
Contains("commit 12"),
45+
Contains("commit 11").IsSelected(),
46+
Contains("commit 10"),
47+
)
48+
49+
t.Views().Files().
50+
Focus()
51+
52+
// ensure we retain the same viewport upon re-focus
53+
t.Views().Commits().
54+
Focus().
55+
VisibleLines(
56+
Contains("commit 12"),
57+
Contains("commit 11").IsSelected(),
58+
Contains("commit 10"),
59+
)
60+
},
61+
})

pkg/integration/types/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
type IntegrationTest interface {
1414
Run(GuiDriver)
1515
SetupConfig(config *config.AppConfig)
16+
RequiresHeadless() bool
17+
// width and height when running headless
18+
HeadlessDimensions() (int, int)
1619
}
1720

1821
// this is the interface through which our integration tests interact with the lazygit gui

vendor/github.com/jesseduffield/gocui/gui.go

Lines changed: 21 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)