1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-25 12:24:47 +02:00

Clean up test case

I'm combining the delete single file case from `discard_old_file_change`
with the content of `discard_range_select` and calling that
`discard_old_file_changes`. Hopefully that cleans things up a little
bit.

This also adds a check that the custom patch is getting reset properly.
This commit is contained in:
Aaron Hoffman 2024-01-30 13:52:40 -06:00
parent 62a0c895b4
commit d138f7ce86
4 changed files with 174 additions and 190 deletions

View File

@ -1,57 +0,0 @@
package commit
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiscardOldFileChange = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discarding a single file from an old commit (does rebase in background to remove the file but retain the other one)",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file0", "file0")
shell.Commit("first commit")
shell.CreateFileAndAdd("file1", "file2")
shell.CreateFileAndAdd("fileToRemove", "fileToRemove")
shell.Commit("commit to change")
shell.CreateFileAndAdd("file3", "file3")
shell.Commit("third commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("third commit").IsSelected(),
Contains("commit to change"),
Contains("first commit"),
).
SelectNextItem().
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
Contains("fileToRemove"),
).
SelectNextItem().
Press(keys.Universal.Remove)
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
Confirm()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("file1").IsSelected(),
)
t.FileSystem().PathNotPresent("fileToRemove")
},
})

View File

@ -0,0 +1,173 @@
package commit
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiscardOldFileChanges = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discarding a range of files from an old commit.",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("dir1/d1_file0", "file0\n")
shell.CreateFileAndAdd("dir1/subd1/subfile0", "file1\n")
shell.CreateFileAndAdd("dir2/d2_file1", "d2f1 content\n")
shell.CreateFileAndAdd("dir2/d2_file2", "d2f4 content\n")
shell.Commit("remove one file from this commit")
shell.UpdateFileAndAdd("dir2/d2_file1", "d2f1 content\nsecond line\n")
shell.DeleteFileAndAdd("dir2/d2_file2")
shell.CreateFileAndAdd("dir2/d2_file3", "d2f3 content\n")
shell.CreateFileAndAdd("dir2/d2_file4", "d2f2 content\n")
shell.Commit("remove four files from this commit")
shell.CreateFileAndAdd("dir1/fileToRemove", "file to remove content\n")
shell.CreateFileAndAdd("dir1/multiLineFile", "this file has\ncontent on\nthree lines\n")
shell.CreateFileAndAdd("dir1/subd1/file2ToRemove", "file2 to remove content\n")
shell.Commit("remove changes in multiple dirs from this commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("remove changes in multiple dirs from this commit").IsSelected(),
Contains("remove four files from this commit"),
Contains("remove one file from this commit"),
).
NavigateToLine(Contains("remove one file from this commit")).
PressEnter()
// Check removing a single file from an old commit
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("dir1").IsSelected(),
Contains("subd1"),
Contains("subfile0"),
Contains("d1_file0"),
Contains("dir2"),
Contains("d2_file1"),
Contains("d2_file2"),
).
NavigateToLine(Contains("d1_file0")).
Press(keys.Universal.Remove)
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
Confirm()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("dir1/subd1"),
Contains("subfile0"),
Contains("dir2"),
Contains("d2_file1").IsSelected(),
Contains("d2_file2"),
).
PressEscape()
// Check removing 4 files in the same directory
t.Views().Commits().
Focus().
Lines(
Contains("remove changes in multiple dirs from this commit"),
Contains("remove four files from this commit"),
Contains("remove one file from this commit").IsSelected(),
).
NavigateToLine(Contains("remove four files from this commit")).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("dir2").IsSelected(),
Contains("d2_file1"),
Contains("d2_file2"),
Contains("d2_file3"),
Contains("d2_file4"),
).
NavigateToLine(Contains("d2_file1")).
Press(keys.Universal.ToggleRangeSelect).
NavigateToLine(Contains("d2_file4")).
Press(keys.Universal.Remove)
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
Confirm()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("(none)"),
).
// for some reason I need to press escape twice. Seems like it happens every time
// more than one file is removed from a commit
PressEscape().
PressEscape()
// Check removing multiple files from 2 directories w/ a custom patch.
// This checks node selection logic & if the custom patch is getting reset.
t.Views().Commits().
IsFocused().
Lines(
Contains("remove changes in multiple dirs from this commit"),
Contains("remove four files from this commit").IsSelected(),
Contains("remove one file from this commit"),
).
NavigateToLine(Contains("remove changes in multiple dirs from this commit")).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("dir1").IsSelected(),
Contains("subd1"),
Contains("file2ToRemove"),
Contains("fileToRemove"),
Contains("multiLineFile"),
).
NavigateToLine(Contains("multiLineFile")).
PressEnter()
t.Views().PatchBuilding().
IsFocused().
SelectedLine(
Contains("+this file has"),
).
PressPrimaryAction().
PressEscape()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("dir1"),
Contains("subd1"),
Contains("file2ToRemove"),
Contains("fileToRemove"),
Contains("multiLineFile").IsSelected(),
).
NavigateToLine(Contains("dir1")).
Press(keys.Universal.ToggleRangeSelect).
NavigateToLine(Contains("subd1")).
Press(keys.Universal.Remove)
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
Confirm()
// "Building patch" will still be in this view if the patch isn't reset properly
t.Views().Information().Content(DoesNotContain("Building patch"))
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("(none)"),
)
},
})

View File

@ -1,131 +0,0 @@
package commit
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiscardRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discarding a range of files from an old commit.",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("dir1/file0", "file0\n")
shell.CreateFileAndAdd("dir1/dir2/file1", "file1\n")
shell.CreateFileAndAdd("dir3/file1", "d3f1 content\n")
shell.CreateFileAndAdd("dir3/file4", "d3f4 content\n")
shell.Commit("first commit")
shell.UpdateFileAndAdd("dir3/file1", "d3f1 content\nsecond line\n")
shell.CreateFileAndAdd("dir3/file2", "d3f2 content\n")
shell.CreateFileAndAdd("dir3/file3", "d3f3 content\n")
shell.DeleteFileAndAdd("dir3/file4")
shell.Commit("first commit to change")
shell.CreateFileAndAdd("dir1/fileToRemove", "file to remove content\n")
shell.CreateFileAndAdd("dir1/multiLineFile", "this file has\ncontent on\nthree lines\n")
shell.CreateFileAndAdd("dir1/dir2/file2ToRemove", "file2 to remove content\n")
shell.Commit("second commit to change")
shell.CreateFileAndAdd("file3", "file3")
shell.Commit("third commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("third commit").IsSelected(),
Contains("second commit to change"),
Contains("first commit to change"),
Contains("first commit"),
).
NavigateToLine(Contains("first commit to change")).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("dir3").IsSelected(),
Contains("file1"),
Contains("file2"),
Contains("file3"),
Contains("file4"),
).
NavigateToLine(Contains("file1")).
Press(keys.Universal.ToggleRangeSelect).
NavigateToLine(Contains("file4")).
Press(keys.Universal.Remove)
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
Confirm()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("(none)"),
).
// for some reason I need to press escape twice. Seems like it happens every time
// more than one file is removed from a commit
PressEscape().
PressEscape()
t.Views().Commits().
IsFocused().
Lines(
Contains("third commit"),
Contains("second commit to change"),
Contains("first commit to change").IsSelected(),
Contains("first commit"),
).
NavigateToLine(Contains("second commit to change")).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("dir1").IsSelected(),
Contains("dir2"),
Contains("file2ToRemove"),
Contains("fileToRemove"),
Contains("multiLineFile"),
).
NavigateToLine(Contains("multiLineFile")).
PressEnter()
t.Views().PatchBuilding().
IsFocused().
SelectedLine(
Contains("+this file has"),
).
PressPrimaryAction().
PressEscape()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("dir1"),
Contains("dir2"),
Contains("file2ToRemove"),
Contains("fileToRemove"),
Contains("multiLineFile").IsSelected(),
).
NavigateToLine(Contains("dir1")).
Press(keys.Universal.ToggleRangeSelect).
NavigateToLine(Contains("dir2")).
Press(keys.Universal.Remove)
t.ExpectPopup().Confirmation().
Title(Equals("Discard file changes")).
Content(Equals("Are you sure you want to remove changes to the selected file(s) from this commit?\n\nThis action will start a rebase, reverting these file changes. Be aware that if subsequent commits depend on these changes, you may need to resolve conflicts.\nNote: This will also reset any active custom patches.")).
Confirm()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("(none)"),
)
},
})

View File

@ -70,8 +70,7 @@ var tests = []*components.IntegrationTest{
commit.CommitWipWithPrefix,
commit.CommitWithPrefix,
commit.CreateTag,
commit.DiscardOldFileChange,
commit.DiscardRangeSelect,
commit.DiscardOldFileChanges,
commit.FindBaseCommitForFixup,
commit.FindBaseCommitForFixupWarningForAddedLines,
commit.Highlight,