1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-25 22:32:13 +02:00

update integration test for toggling whitespace

This commit is contained in:
Jesse Duffield
2023-03-26 15:56:11 +11:00
parent 037cd99138
commit 2e32e55957

View File

@@ -5,29 +5,60 @@ import (
. "github.com/jesseduffield/lazygit/pkg/integration/components" . "github.com/jesseduffield/lazygit/pkg/integration/components"
) )
var (
initialFileContent = "first-line\nold-second-line\nthird-line\n"
// We're indenting each line and modifying the second line
updatedFileContent = " first-line\n new-second-line\n third-line\n"
)
var IgnoreWhitespace = NewIntegrationTest(NewIntegrationTestArgs{ var IgnoreWhitespace = NewIntegrationTest(NewIntegrationTestArgs{
Description: "View diff with and without ignoring whitespace", Description: "Toggle whitespace in the diff",
ExtraCmdArgs: "", ExtraCmdArgs: "",
Skip: false, Skip: false,
SetupConfig: func(config *config.AppConfig) {}, SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) { SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "first line\nsecond line\n") shell.CreateFileAndAdd("myfile", initialFileContent)
shell.Commit("first commit") shell.Commit("initial commit")
// First line has a real change, second line changes only indentation: shell.UpdateFile("myfile", updatedFileContent)
shell.UpdateFileAndAdd("file1", "first line changed\n second line\n")
shell.Commit("second commit")
}, },
Run: func(t *TestDriver, keys config.KeybindingConfig) { Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits(). t.Views().Main().ContainsLines(
Focus(). Contains(`-first-line`),
Tap(func() { Contains(`-old-second-line`),
// By default, both changes are shown in the diff: Contains(`-third-line`),
t.Views().Main().Content(Contains("-first line\n-second line\n+first line changed\n+ second line\n")) Contains(`+ first-line`),
}). Contains(`+ new-second-line`),
Press(keys.Universal.ToggleWhitespaceInDiffView). Contains(`+ third-line`),
Tap(func() { )
// After enabling ignore whitespace, only the real change remains:
t.Views().Main().Content(Contains("-first line\n+first line changed\n")) t.Views().Files().
}) IsFocused().
Press(keys.Universal.ToggleWhitespaceInDiffView)
t.ExpectToast(Equals("Whitespace will be ignored in the diff view"))
// lines with only whitespace changes are ignored (first and third lines)
t.Views().Main().ContainsLines(
Contains(` first-line`),
Contains(`-old-second-line`),
Contains(`+ new-second-line`),
Contains(` third-line`),
)
// when toggling again it goes back to showing whitespace
t.Views().Files().
IsFocused().
Press(keys.Universal.ToggleWhitespaceInDiffView)
t.ExpectToast(Equals("Whitespace will be shown in the diff view"))
t.Views().Main().ContainsLines(
Contains(`-first-line`),
Contains(`-old-second-line`),
Contains(`-third-line`),
Contains(`+ first-line`),
Contains(`+ new-second-line`),
Contains(`+ third-line`),
)
}, },
}) })