summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/staging/stage_lines.go
blob: f1777fb36c8408577ca1943e3c292702368a0c37 (plain)
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
package staging

import (
	"github.com/jesseduffield/lazygit/pkg/config"
	. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var StageLines = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage and unstage various lines of a file in the staging panel",
	ExtraCmdArgs: "",
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "one\ntwo\n")
		shell.Commit("one")

		shell.UpdateFile("file1", "one\ntwo\nthree\nfour\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			SelectedLine(Contains("+three")).
			// stage 'three'
			PressPrimaryAction().
			// 'three' moves over to the staging secondary panel
			Content(DoesNotContain("+three")).
			Tap(func() {
				t.Views().StagingSecondary().
					Content(Contains("+three"))
			}).
			SelectedLine(Contains("+four")).
			// stage 'four'
			PressPrimaryAction().
			// nothing left in our staging panel
			IsEmpty()

		// because we've staged everything we get moved to the staging secondary panel
		// do the same thing as above, moving the lines back to the staging panel
		t.Views().StagingSecondary().
			IsFocused().
			Content(Contains("+three\n+four")).
			SelectedLine(Contains("+three")).
			PressPrimaryAction().
			Content(DoesNotContain("+three")).
			Tap(func() {
				t.Views().Staging().
					Content(Contains("+three"))
			}).
			SelectedLine(Contains("+four")).
			// pressing 'remove' has the same effect as pressing space when in the staging secondary panel
			Press(keys.Universal.Remove).
			IsEmpty()

		// stage one line and then manually toggle to the staging secondary panel
		t.Views().Staging().
			IsFocused().
			Content(Contains("+three\n+four")).
			SelectedLine(Contains("+three")).
			PressPrimaryAction().
			Content(DoesNotContain("+three")).
			Tap(func() {
				t.Views().StagingSecondary().
					Content(Contains("+three"))
			}).
			Press(keys.Universal.TogglePanel)

		// manually toggle back to the staging panel
		t.Views().StagingSecondary().
			IsFocused().
			Press(keys.Universal.TogglePanel)

		t.Views().Staging().
			SelectedLine(Contains("+four")).
			// discard the line
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Unstage lines")).
					Content(Contains("Are you sure you want to delete the selected lines")).
					Confirm()
			}).
			IsEmpty()

		t.Views().StagingSecondary().
			IsFocused().
			Content(Contains("+three\n")).
			// return to file
			PressEscape()

		t.Views().Files().
			IsFocused().
			Lines(
				Contains("M  file1").IsSelected(),
			).
			PressEnter()

		// because we only have a staged change we'll land in the staging secondary panel
		t.Views().StagingSecondary().
			IsFocused()
	},
})