Skip to content

Commit

Permalink
Merge pull request jesseduffield#2339 from jesseduffield/integration-…
Browse files Browse the repository at this point in the history
…tests-5
  • Loading branch information
jesseduffield authored Dec 30, 2022
2 parents 31bdd27 + 5c42e1a commit cceff63
Show file tree
Hide file tree
Showing 209 changed files with 344 additions and 559 deletions.
9 changes: 7 additions & 2 deletions pkg/gui/confirmation_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,13 @@ func (gui *Gui) clearConfirmationViewKeyBindings() {

func (gui *Gui) refreshSuggestions() {
gui.suggestionsAsyncHandler.Do(func() func() {
suggestions := gui.findSuggestions(gui.c.GetPromptInput())
return func() { gui.setSuggestions(suggestions) }
findSuggestionsFn := gui.findSuggestions
if findSuggestionsFn != nil {
suggestions := gui.findSuggestions(gui.c.GetPromptInput())
return func() { gui.setSuggestions(suggestions) }
} else {
return func() {}
}
})
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/integration/components/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,32 @@ func (self *Shell) SetConfig(key string, value string) *Shell {
self.RunCommand(fmt.Sprintf(`git config --local "%s" %s`, key, value))
return self
}

// creates a clone of the repo in a sibling directory and adds the clone
// as a remote, then fetches it.
func (self *Shell) CloneIntoRemote(name string) *Shell {
self.RunCommand(fmt.Sprintf("git clone --bare . ../%s", name))
self.RunCommand(fmt.Sprintf("git remote add %s ../%s", name, name))
self.RunCommand(fmt.Sprintf("git fetch %s", name))

return self
}

// e.g. branch: 'master', upstream: 'origin/master'
func (self *Shell) SetBranchUpstream(branch string, upstream string) *Shell {
self.RunCommand(fmt.Sprintf("git branch --set-upstream-to=%s %s", upstream, branch))

return self
}

func (self *Shell) RemoveRemoteBranch(remoteName string, branch string) *Shell {
self.RunCommand(fmt.Sprintf("git -C ../%s branch -d %s", remoteName, branch))

return self
}

func (self *Shell) HardReset(ref string) *Shell {
self.RunCommand(fmt.Sprintf("git reset --hard %s", ref))

return self
}
39 changes: 0 additions & 39 deletions pkg/integration/tests/file/exclude_gitignore.go

This file was deleted.

63 changes: 63 additions & 0 deletions pkg/integration/tests/file/gitignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package file

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

var GitIgnore = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Verify that we can't ignore the .gitignore file, then ignore/exclude other files",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
shell.CreateFile(".gitignore", "")
shell.CreateFile("toExclude", "")
shell.CreateFile("toIgnore", "")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Lines(
Contains(`?? .gitignore`).IsSelected(),
Contains(`?? toExclude`),
Contains(`?? toIgnore`),
).
Press(keys.Files.IgnoreFile).
// ensure we can't exclude the .gitignore file
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .git/info/exclude")).Confirm()

t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot exclude .gitignore")).Confirm()
}).
Press(keys.Files.IgnoreFile).
// ensure we can't ignore the .gitignore file
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .gitignore")).Confirm()

t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot ignore .gitignore")).Confirm()

t.FileSystem().FileContent(".gitignore", Equals(""))
t.FileSystem().FileContent(".git/info/exclude", DoesNotContain(".gitignore"))
}).
SelectNextItem().
Press(keys.Files.IgnoreFile).
// exclude a file
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .git/info/exclude")).Confirm()

t.FileSystem().FileContent(".gitignore", Equals(""))
t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
}).
SelectNextItem().
Press(keys.Files.IgnoreFile).
// ignore a file
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .gitignore")).Confirm()

t.FileSystem().FileContent(".gitignore", Equals("toIgnore\n"))
t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
})
},
})
20 changes: 20 additions & 0 deletions pkg/integration/tests/filter_by_path/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package filter_by_path

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

var CliArg = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filter commits by file path, using CLI arg",
ExtraCmdArgs: "-f filterFile",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
commonSetup(shell)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
postFilterTest(t)
},
})
76 changes: 76 additions & 0 deletions pkg/integration/tests/filter_by_path/select_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package filter_by_path

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

var SelectFile = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filter commits by file path, by finding file in UI and filtering on it",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
commonSetup(shell)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains(`only filterFile`).IsSelected(),
Contains(`only otherFile`),
Contains(`both files`),
).
PressEnter()

// when you click into the commit itself, you see all files from that commit
t.Views().CommitFiles().
IsFocused().
Lines(
Contains(`filterFile`).IsSelected(),
).
Press(keys.Universal.FilteringMenu)

t.ExpectPopup().Menu().Title(Equals("Filtering")).Select(Contains("filter by 'filterFile'")).Confirm()

postFilterTest(t)
},
})

func commonSetup(shell *Shell) {
shell.CreateFileAndAdd("filterFile", "original filterFile content")
shell.CreateFileAndAdd("otherFile", "original otherFile content")
shell.Commit("both files")

shell.UpdateFileAndAdd("otherFile", "new otherFile content")
shell.Commit("only otherFile")

shell.UpdateFileAndAdd("filterFile", "new filterFile content")
shell.Commit("only filterFile")
}

func postFilterTest(t *TestDriver) {
t.Views().Information().Content(Contains("filtering by 'filterFile'"))

t.Views().Commits().
IsFocused().
Lines(
Contains(`only filterFile`).IsSelected(),
Contains(`both files`),
).
SelectNextItem().
PressEnter()

// we only show the filtered file's changes in the main view
t.Views().Main().
Content(Contains("filterFile").DoesNotContain("otherFile"))

// when you click into the commit itself, you see all files from that commit
t.Views().CommitFiles().
IsFocused().
Lines(
Contains(`filterFile`),
Contains(`otherFile`),
)
}
35 changes: 35 additions & 0 deletions pkg/integration/tests/filter_by_path/type_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package filter_by_path

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

var TypeFile = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Filter commits by file path, by finding file in UI and filtering on it",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
commonSetup(shell)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Press(keys.Universal.FilteringMenu)

t.ExpectPopup().Menu().
Title(Equals("Filtering")).
Select(Contains("enter path to filter by")).
Confirm()

t.ExpectPopup().Prompt().
Title(Equals("Enter path:")).
Type("filterF").
SuggestionLines(Equals("filterFile")).
ConfirmFirstSuggestion()

postFilterTest(t)
},
})
49 changes: 49 additions & 0 deletions pkg/integration/tests/sync/fetch_prune.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package sync

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

var FetchPrune = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Fetch from the remote with the 'prune' option set in the git config",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Git.AutoFetch = false
},
SetupRepo: func(shell *Shell) {
// This option makes it so that git checks for deleted branches in the remote
// upon fetching.
shell.SetConfig("fetch.prune", "true")

shell.EmptyCommit("my commit message")

shell.NewBranch("branch_to_remove")
shell.Checkout("master")
shell.CloneIntoRemote("origin")
shell.SetBranchUpstream("master", "origin/master")
shell.SetBranchUpstream("branch_to_remove", "origin/branch_to_remove")

// # unbenownst to our test repo we're removing the branch on the remote, so upon
// # fetching with prune: true we expect git to realise the remote branch is gone
shell.RemoveRemoteBranch("origin", "branch_to_remove")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Lines(
Contains("master"),
Contains("branch_to_remove").DoesNotContain("upstream gone"),
)

t.Views().Files().
IsFocused().
Press(keys.Files.Fetch)

t.Views().Branches().
Lines(
Contains("master"),
Contains("branch_to_remove").Contains("upstream gone"),
)
},
})
57 changes: 57 additions & 0 deletions pkg/integration/tests/sync/rename_branch_and_pull.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package sync

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

var RenameBranchAndPull = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Rename a branch to no longer match its upstream, then pull from the upstream",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Git.AutoFetch = false
},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("one")
shell.EmptyCommit("two")

shell.CloneIntoRemote("origin")
shell.SetBranchUpstream("master", "origin/master")

// remove the 'two' commit so that we have something to pull from the remote
shell.HardReset("HEAD^")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Lines(
Contains("one"),
)

t.Views().Branches().
Focus().
Lines(
Contains("master"),
).
Press(keys.Branches.RenameBranch).
Tap(func() {
t.ExpectPopup().Confirmation().
Title(Equals("rename branch")).
Content(Equals("This branch is tracking a remote. This action will only rename the local branch name, not the name of the remote branch. Continue?")).
Confirm()

t.ExpectPopup().Prompt().
Title(Contains("Enter new branch name")).
InitialText(Equals("master")).
Type("-local").
Confirm()
}).
Press(keys.Universal.PullFiles)

t.Views().Commits().
Lines(
Contains("two"),
Contains("one"),
)
},
})
Loading

0 comments on commit cceff63

Please sign in to comment.