1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-07 22:02:56 +03:00

Add integration tests for searching/filtering

This commit is contained in:
Jesse Duffield
2023-06-03 16:10:53 +10:00
parent 7d7399a89f
commit 261f30f49c
12 changed files with 540 additions and 26 deletions

View File

@@ -42,6 +42,7 @@ var Search = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Universal.StartSearch).
Tap(func() {
t.ExpectSearch().
Clear().
Type("o").
Confirm()

View File

@@ -0,0 +1,84 @@
package filter_and_search
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var FilterCommitFiles = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Basic commit file filtering by text",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateDir("folder1")
shell.CreateFileAndAdd("folder1/apple-grape", "apple-grape")
shell.CreateFileAndAdd("folder1/apple-orange", "apple-orange")
shell.CreateFileAndAdd("folder1/grape-orange", "grape-orange")
shell.Commit("first commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains(`first commit`).IsSelected(),
).
Press(keys.Universal.Confirm)
t.Views().CommitFiles().
IsFocused().
Lines(
Contains(`folder1`).IsSelected(),
Contains(`apple-grape`),
Contains(`apple-orange`),
Contains(`grape-orange`),
).
Press(keys.Files.ToggleTreeView).
Lines(
Contains(`folder1/apple-grape`).IsSelected(),
Contains(`folder1/apple-orange`),
Contains(`folder1/grape-orange`),
).
FilterOrSearch("apple").
Lines(
Contains(`folder1/apple-grape`).IsSelected(),
Contains(`folder1/apple-orange`),
).
Press(keys.Files.ToggleTreeView).
// filter still applies when we toggle tree view
Lines(
Contains(`folder1`),
Contains(`apple-grape`).IsSelected(),
Contains(`apple-orange`),
).
Press(keys.Files.ToggleTreeView).
Lines(
Contains(`folder1/apple-grape`).IsSelected(),
Contains(`folder1/apple-orange`),
).
NavigateToLine(Contains(`folder1/apple-orange`)).
Press(keys.Universal.Return).
Lines(
Contains(`folder1/apple-grape`),
// selection is retained after escaping filter mode
Contains(`folder1/apple-orange`).IsSelected(),
Contains(`folder1/grape-orange`),
).
Tap(func() {
t.Views().Search().IsInvisible()
}).
Press(keys.Files.ToggleTreeView).
Lines(
Contains(`folder1`),
Contains(`apple-grape`),
Contains(`apple-orange`).IsSelected(),
Contains(`grape-orange`),
).
FilterOrSearch("folder1/grape").
Lines(
// first item is always selected after filtering
Contains(`folder1`).IsSelected(),
Contains(`grape-orange`),
)
},
})

View File

@@ -0,0 +1,76 @@
package filter_and_search
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var FilterFiles = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Basic file filtering by text",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateDir("folder1")
shell.CreateFile("folder1/apple-grape", "apple-grape")
shell.CreateFile("folder1/apple-orange", "apple-orange")
shell.CreateFile("folder1/grape-orange", "grape-orange")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
Focus().
Lines(
Contains(`folder1`).IsSelected(),
Contains(`apple-grape`),
Contains(`apple-orange`),
Contains(`grape-orange`),
).
Press(keys.Files.ToggleTreeView).
Lines(
Contains(`folder1/apple-grape`).IsSelected(),
Contains(`folder1/apple-orange`),
Contains(`folder1/grape-orange`),
).
FilterOrSearch("apple").
Lines(
Contains(`folder1/apple-grape`).IsSelected(),
Contains(`folder1/apple-orange`),
).
Press(keys.Files.ToggleTreeView).
// filter still applies when we toggle tree view
Lines(
Contains(`folder1`),
Contains(`apple-grape`).IsSelected(),
Contains(`apple-orange`),
).
Press(keys.Files.ToggleTreeView).
Lines(
Contains(`folder1/apple-grape`).IsSelected(),
Contains(`folder1/apple-orange`),
).
NavigateToLine(Contains(`folder1/apple-orange`)).
Press(keys.Universal.Return).
Lines(
Contains(`folder1/apple-grape`),
// selection is retained after escaping filter mode
Contains(`folder1/apple-orange`).IsSelected(),
Contains(`folder1/grape-orange`),
).
Tap(func() {
t.Views().Search().IsInvisible()
}).
Press(keys.Files.ToggleTreeView).
Lines(
Contains(`folder1`),
Contains(`apple-grape`),
Contains(`apple-orange`).IsSelected(),
Contains(`grape-orange`),
).
FilterOrSearch("folder1/grape").
Lines(
// first item is always selected after filtering
Contains(`folder1`).IsSelected(),
Contains(`grape-orange`),
)
},
})

View File

@@ -0,0 +1,48 @@
package filter_and_search
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var FilterMenu = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filtering the keybindings menu",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFile("myfile", "myfile")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Lines(
Contains(`??`).Contains(`myfile`).IsSelected(),
).
Press(keys.Universal.OptionMenu).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Keybindings")).
Filter("Toggle staged").
Lines(
// menu has filtered down to the one item that matches the filter
Contains(`Toggle staged`).IsSelected(),
).
Confirm()
})
t.Views().Files().
IsFocused().
Lines(
// file has been staged
Contains(`A `).Contains(`myfile`).IsSelected(),
).
// Upon opening the menu again, the filter should have been reset
Press(keys.Universal.OptionMenu).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Keybindings")).
LineCount(GreaterThan(1))
})
},
})

View File

@@ -0,0 +1,147 @@
package filter_and_search
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var NestedFilter = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filter in the several nested panels and verify the filters are preserved as you escape back to the surface",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
// need to create some branches, each with their own commits
shell.NewBranch("branch-gold")
shell.CreateFileAndAdd("apple", "apple")
shell.CreateFileAndAdd("orange", "orange")
shell.CreateFileAndAdd("grape", "grape")
shell.Commit("commit-knife")
shell.NewBranch("branch-silver")
shell.UpdateFileAndAdd("apple", "apple-2")
shell.UpdateFileAndAdd("orange", "orange-2")
shell.UpdateFileAndAdd("grape", "grape-2")
shell.Commit("commit-spoon")
shell.NewBranch("branch-bronze")
shell.UpdateFileAndAdd("apple", "apple-3")
shell.UpdateFileAndAdd("orange", "orange-3")
shell.UpdateFileAndAdd("grape", "grape-3")
shell.Commit("commit-fork")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains(`branch-bronze`).IsSelected(),
Contains(`branch-silver`),
Contains(`branch-gold`),
).
FilterOrSearch("sil").
Lines(
Contains(`branch-silver`).IsSelected(),
).
PressEnter()
t.Views().SubCommits().
IsFocused().
Lines(
Contains(`commit-spoon`).IsSelected(),
Contains(`commit-knife`),
).
FilterOrSearch("knife").
Lines(
// sub-commits view searches, it doesn't filter, so we haven't filtered down the list
Contains(`commit-spoon`),
Contains(`commit-knife`).IsSelected(),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains(`apple`).IsSelected(),
Contains(`grape`),
Contains(`orange`),
).
FilterOrSearch("grape").
Lines(
Contains(`grape`).IsSelected(),
).
PressEnter()
t.Views().PatchBuilding().
IsFocused().
FilterOrSearch("newline").
SelectedLine(Contains("No newline at end of file")).
PressEscape(). // cancel search
Tap(func() {
t.Views().Search().IsInvisible()
}).
// escape to commit-files view
PressEscape()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains(`grape`).IsSelected(),
).
Tap(func() {
t.Views().Search().IsVisible().Content(Contains("matches for 'grape'"))
}).
// cancel search
PressEscape().
Tap(func() {
t.Views().Search().IsInvisible()
}).
Lines(
Contains(`apple`),
Contains(`grape`).IsSelected(),
Contains(`orange`),
).
// escape to sub-commits view
PressEscape()
t.Views().SubCommits().
IsFocused().
Lines(
Contains(`commit-spoon`),
Contains(`commit-knife`).IsSelected(),
).
Tap(func() {
t.Views().Search().IsVisible().Content(Contains("matches for 'knife'"))
}).
// cancel search
PressEscape().
Tap(func() {
t.Views().Search().IsInvisible()
}).
Lines(
Contains(`commit-spoon`),
// still selected
Contains(`commit-knife`).IsSelected(),
).
// escape to branches view
PressEscape()
t.Views().Branches().
IsFocused().
Lines(
Contains(`branch-silver`).IsSelected(),
).
Tap(func() {
t.Views().Search().IsVisible().Content(Contains("matches for 'sil'"))
}).
// cancel search
PressEscape().
Tap(func() {
t.Views().Search().IsInvisible()
}).
Lines(
Contains(`branch-bronze`),
Contains(`branch-silver`).IsSelected(),
Contains(`branch-gold`),
)
},
})

View File

@@ -0,0 +1,105 @@
package filter_and_search
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
// This one requires some explanation: the sub-commits and diff-file contexts are
// 'transient' in that they are spawned inside a window when you need them, but
// can be relocated elsewhere if you need them somewhere else. So for example if
// I hit enter on a branch I'll see the sub-commits view, but if I then navigate
// to the reflog context and hit enter on a reflog, the sub-commits view is moved
// to the reflog window. This is because we re-use the same view (it's a limitation
// that would be nice to remove in the future).
// Nonetheless, we need to ensure that upon moving the view, the filter is cancelled.
var NestedFilterTransient = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filter in a transient panel (sub-commits and diff-files) and ensure filter is cancelled when the panel is moved",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
// need to create some branches, each with their own commits
shell.NewBranch("mybranch")
shell.CreateFileAndAdd("file-one", "file-one")
shell.CreateFileAndAdd("file-two", "file-two")
shell.Commit("commit-one")
shell.EmptyCommit("commit-two")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains(`mybranch`).IsSelected(),
).
PressEnter()
t.Views().SubCommits().
IsFocused().
Lines(
Contains(`commit-two`).IsSelected(),
Contains(`commit-one`),
).
FilterOrSearch("one").
Lines(
Contains(`commit-two`),
Contains(`commit-one`).IsSelected(),
)
t.Views().ReflogCommits().
Focus().
SelectedLine(Contains("commit: commit-two")).
PressEnter()
t.Views().SubCommits().
IsFocused().
// the search on the sub-commits context has been cancelled
Lines(
Contains(`commit-two`).IsSelected(),
Contains(`commit-one`),
).
Tap(func() {
t.Views().Search().IsInvisible()
}).
NavigateToLine(Contains("commit-one")).
PressEnter()
// Now let's test the commit files context
t.Views().CommitFiles().
IsFocused().
Lines(
Contains(`file-one`).IsSelected(),
Contains(`file-two`),
).
FilterOrSearch("one").
Lines(
Contains(`file-one`).IsSelected(),
)
t.Views().Branches().
Focus().
SelectedLine(Contains("mybranch")).
PressEnter()
t.Views().SubCommits().
IsFocused().
Lines(
Contains(`commit-two`).IsSelected(),
Contains(`commit-one`),
).
NavigateToLine(Contains("commit-one")).
PressEnter()
t.Views().CommitFiles().
IsFocused().
// the search on the commit-files context has been cancelled
Lines(
Contains(`file-one`).IsSelected(),
Contains(`file-two`),
).
Tap(func() {
t.Views().Search().IsInvisible()
})
},
})

View File

@@ -13,6 +13,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands"
"github.com/jesseduffield/lazygit/pkg/integration/tests/diff"
"github.com/jesseduffield/lazygit/pkg/integration/tests/file"
"github.com/jesseduffield/lazygit/pkg/integration/tests/filter_and_search"
"github.com/jesseduffield/lazygit/pkg/integration/tests/filter_by_path"
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
"github.com/jesseduffield/lazygit/pkg/integration/tests/misc"
@@ -94,6 +95,11 @@ var tests = []*components.IntegrationTest{
file.DiscardUnstagedFileChanges,
file.Gitignore,
file.RememberCommitMessageAfterFail,
filter_and_search.FilterCommitFiles,
filter_and_search.FilterFiles,
filter_and_search.FilterMenu,
filter_and_search.NestedFilter,
filter_and_search.NestedFilterTransient,
filter_by_path.CliArg,
filter_by_path.SelectFile,
filter_by_path.TypeFile,