summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/staging/discard_all_changes.go
blob: 7d27e7ec2f48b7ebdc3e232a8afc65834649c2e9 (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
package staging

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

var DiscardAllChanges = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Discard all changes of a file in the staging panel, then assert we land in the staging panel of the next file",
	ExtraCmdArgs: "",
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "one\ntwo\n")
		shell.CreateFileAndAdd("file2", "1\n2\n")
		shell.Commit("one")

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

		t.Views().Staging().
			IsFocused().
			SelectedLine(Contains("+three")).
			// discard the line
			Press(keys.Universal.Remove).
			Tap(func() {
				t.Actions().ConfirmDiscardLines()
			}).
			SelectedLine(Contains("+four")).
			// discard the other line
			Press(keys.Universal.Remove).
			Tap(func() {
				t.Actions().ConfirmDiscardLines()

				// because there are no more changes in file1 we switch to file2
				t.Views().Files().
					Lines(
						Contains("file2").IsSelected(),
					)
			}).
			// assert we are still in the staging panel, but now looking at the changes of the other file
			IsFocused().
			SelectedLine(Contains("+3"))
	},
})