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

add helper functions for popups in tests

This commit is contained in:
Jesse Duffield
2022-12-24 17:48:57 +11:00
parent aedfce2845
commit b623ecf898
40 changed files with 380 additions and 402 deletions

View File

@ -20,8 +20,9 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{
input.PrimaryAction()
input.NextItem()
input.PrimaryAction()
input.PressKeys(keys.Files.CommitChanges)
input.Press(keys.Files.CommitChanges)
assert.InCommitMessagePanel()
commitMessage := "my commit message"
input.Type(commitMessage)
input.Confirm()

View File

@ -17,11 +17,12 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(0)
input.PrimaryAction()
input.PressKeys(keys.Files.CommitChanges)
input.Press(keys.Files.CommitChanges)
assert.InCommitMessagePanel()
input.Type("first line")
input.PressKeys(keys.Universal.AppendNewline)
input.PressKeys(keys.Universal.AppendNewline)
input.Press(keys.Universal.AppendNewline)
input.Press(keys.Universal.AppendNewline)
input.Type("third line")
input.Confirm()

View File

@ -23,13 +23,10 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
assert.CurrentViewName("commits")
input.NextItem()
input.PressKeys(keys.Universal.New)
assert.CurrentViewName("confirmation")
input.Press(keys.Universal.New)
branchName := "my-branch-name"
input.Type(branchName)
input.Confirm()
input.Prompt(Contains("New Branch Name"), branchName)
assert.CommitCount(2)
assert.HeadCommitMessage(Contains("commit 2"))

View File

@ -20,18 +20,13 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{
input.SwitchToCommitsWindow()
input.PressKeys(keys.Commits.RevertCommit)
assert.InConfirm()
assert.CurrentViewTitle(Equals("Revert commit"))
assert.CurrentViewContent(MatchesRegexp("Are you sure you want to revert \\w+?"))
input.Confirm()
input.Press(keys.Commits.RevertCommit)
input.AcceptConfirmation(Equals("Revert commit"), MatchesRegexp(`Are you sure you want to revert \w+?`))
assert.CommitCount(2)
assert.HeadCommitMessage(Contains("Revert \"first commit\""))
input.PreviousItem()
assert.MainViewContent(Contains("-myfile content"))
assert.FileSystemPathNotPresent("myfile")
input.Wait(10)
},
})

View File

@ -18,11 +18,28 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0)
assert.CurrentViewName("files")
assert.SelectedLine(Contains("myfile"))
// stage the file
input.PrimaryAction()
input.Confirm()
input.PrimaryAction()
input.PressKeys(keys.Files.CommitChanges)
input.Enter()
assert.CurrentViewName("stagingSecondary")
// we start with both lines having been staged
assert.ViewContent("stagingSecondary", Contains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+with a second line"))
assert.ViewContent("staging", NotContains("+myfile content"))
assert.ViewContent("staging", NotContains("+with a second line"))
// unstage the selected line
input.PrimaryAction()
// the line should have been moved to the main view
assert.ViewContent("stagingSecondary", NotContains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+with a second line"))
assert.ViewContent("staging", Contains("+myfile content"))
assert.ViewContent("staging", NotContains("+with a second line"))
input.Press(keys.Files.CommitChanges)
commitMessage := "my commit message"
input.Type(commitMessage)
input.Confirm()
@ -30,5 +47,7 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(1)
assert.HeadCommitMessage(Equals(commitMessage))
assert.CurrentWindowName("stagingSecondary")
// TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
},
})

View File

@ -18,17 +18,38 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0)
// stage the file
assert.CurrentViewName("files")
assert.SelectedLine(Contains("myfile"))
input.PrimaryAction()
input.Confirm()
input.PrimaryAction()
input.PressKeys(keys.Files.CommitChangesWithoutHook)
input.Enter()
assert.CurrentViewName("stagingSecondary")
// we start with both lines having been staged
assert.ViewContent("stagingSecondary", Contains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+with a second line"))
assert.ViewContent("staging", NotContains("+myfile content"))
assert.ViewContent("staging", NotContains("+with a second line"))
commitMessage := "my commit message"
// unstage the selected line
input.PrimaryAction()
// the line should have been moved to the main view
assert.ViewContent("stagingSecondary", NotContains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+with a second line"))
assert.ViewContent("staging", Contains("+myfile content"))
assert.ViewContent("staging", NotContains("+with a second line"))
input.Press(keys.Files.CommitChangesWithoutHook)
assert.InCommitMessagePanel()
assert.CurrentViewContent(Contains("WIP"))
commitMessage := ": my commit message"
input.Type(commitMessage)
input.Confirm()
assert.CommitCount(1)
assert.HeadCommitMessage(Equals("WIP" + commitMessage))
assert.CurrentWindowName("stagingSecondary")
assert.CurrentViewName("stagingSecondary")
// TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
},
})

View File

@ -5,6 +5,8 @@ import (
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
// TODO: find out why we can't use assert.SelectedLine() on the staging/stagingSecondary views.
var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Staging a couple files, going in the unstaged files menu, staging a line and committing",
ExtraCmdArgs: "",
@ -18,10 +20,18 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0)
input.Confirm()
assert.CurrentViewName("files")
assert.SelectedLine(Contains("myfile"))
input.Enter()
assert.CurrentViewName("staging")
assert.ViewContent("stagingSecondary", NotContains("+myfile content"))
// stage the first line
input.PrimaryAction()
input.PressKeys(keys.Files.CommitChanges)
assert.ViewContent("staging", NotContains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+myfile content"))
input.Press(keys.Files.CommitChanges)
assert.InCommitMessagePanel()
commitMessage := "my commit message"
input.Type(commitMessage)
input.Confirm()
@ -29,5 +39,7 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(1)
assert.HeadCommitMessage(Equals(commitMessage))
assert.CurrentWindowName("staging")
// TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
},
})

View File

@ -1,33 +0,0 @@
package commit
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var UnstagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Staging a couple files, going in the unstaged files menu, staging a line and committing without pre-commit hooks",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
CreateFile("myfile", "myfile content\nwith a second line").
CreateFile("myfile2", "myfile2 content")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0)
input.Confirm()
input.PrimaryAction()
input.PressKeys(keys.Files.CommitChangesWithoutHook)
commitMessage := "my commit message"
input.Type(commitMessage)
input.Confirm()
assert.CommitCount(1)
assert.HeadCommitMessage(Equals("WIP" + commitMessage))
assert.CurrentWindowName("staging")
},
})