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

cleaner test assertions

This commit is contained in:
Jesse Duffield
2022-12-26 11:12:56 +11:00
parent fa0414777f
commit 9a6f21ce42
34 changed files with 442 additions and 378 deletions

View File

@ -30,6 +30,6 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{
assert.HeadCommitMessage(Equals("first line"))
input.SwitchToCommitsWindow()
assert.MainViewContent(MatchesRegexp("first line\n\\s*\n\\s*third line"))
assert.MainView().Content(MatchesRegexp("first line\n\\s*\n\\s*third line"))
},
})

View File

@ -20,8 +20,7 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(3)
input.SwitchToCommitsWindow()
assert.CurrentViewName("commits")
assert.CurrentViewLines(
assert.CurrentView().Name("commits").Lines(
Contains("commit 3"),
Contains("commit 2"),
Contains("commit 1"),
@ -35,7 +34,7 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
assert.CurrentBranchName(branchName)
assert.ViewLines("commits",
assert.View("commits").Lines(
Contains("commit 2"),
Contains("commit 1"),
)

View File

@ -20,13 +20,21 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{
input.SwitchToCommitsWindow()
assert.CurrentView().Name("commits").Lines(
Contains("first commit"),
)
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.CurrentView().Name("commits").
Lines(
Contains("Revert \"first commit\""),
Contains("first commit"),
).
SelectedLineIdx(0)
assert.MainView().Content(Contains("-myfile content"))
assert.FileSystemPathNotPresent("myfile")
},
})

View File

@ -18,26 +18,26 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0)
assert.CurrentViewName("files")
assert.CurrentLine(Contains("myfile"))
assert.CurrentView().Name("files")
assert.CurrentView().SelectedLine(Contains("myfile"))
// stage the file
input.PrimaryAction()
input.Enter()
assert.CurrentViewName("stagingSecondary")
assert.CurrentView().Name("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"))
assert.View("stagingSecondary").Content(Contains("+myfile content"))
assert.View("stagingSecondary").Content(Contains("+with a second line"))
assert.View("staging").Content(NotContains("+myfile content"))
assert.View("staging").Content(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"))
assert.View("stagingSecondary").Content(NotContains("+myfile content"))
assert.View("stagingSecondary").Content(Contains("+with a second line"))
assert.View("staging").Content(Contains("+myfile content"))
assert.View("staging").Content(NotContains("+with a second line"))
input.Press(keys.Files.CommitChanges)
commitMessage := "my commit message"

View File

@ -19,36 +19,36 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
assert.CommitCount(0)
// stage the file
assert.CurrentViewName("files")
assert.CurrentLine(Contains("myfile"))
assert.CurrentView().Name("files")
assert.CurrentView().SelectedLine(Contains("myfile"))
input.PrimaryAction()
input.Enter()
assert.CurrentViewName("stagingSecondary")
assert.CurrentView().Name("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"))
assert.View("stagingSecondary").Content(Contains("+myfile content"))
assert.View("stagingSecondary").Content(Contains("+with a second line"))
assert.View("staging").Content(NotContains("+myfile content"))
assert.View("staging").Content(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"))
assert.View("stagingSecondary").Content(NotContains("+myfile content"))
assert.View("stagingSecondary").Content(Contains("+with a second line"))
assert.View("staging").Content(Contains("+myfile content"))
assert.View("staging").Content(NotContains("+with a second line"))
input.Press(keys.Files.CommitChangesWithoutHook)
assert.InCommitMessagePanel()
assert.CurrentViewContent(Contains("WIP"))
assert.CurrentView().Content(Contains("WIP"))
commitMessage := ": my commit message"
input.Type(commitMessage)
input.Confirm()
assert.CommitCount(1)
assert.HeadCommitMessage(Equals("WIP" + commitMessage))
assert.CurrentViewName("stagingSecondary")
assert.CurrentView().Name("stagingSecondary")
// TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
},

View File

@ -20,15 +20,14 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(0)
assert.CurrentViewName("files")
assert.CurrentLine(Contains("myfile"))
assert.CurrentView().Name("files").SelectedLine(Contains("myfile"))
input.Enter()
assert.CurrentViewName("staging")
assert.ViewContent("stagingSecondary", NotContains("+myfile content"))
assert.CurrentView().Name("staging")
assert.View("stagingSecondary").Content(NotContains("+myfile content"))
// stage the first line
input.PrimaryAction()
assert.ViewContent("staging", NotContains("+myfile content"))
assert.ViewContent("stagingSecondary", Contains("+myfile content"))
assert.View("staging").Content(NotContains("+myfile content"))
assert.View("stagingSecondary").Content(Contains("+myfile content"))
input.Press(keys.Files.CommitChanges)
assert.InCommitMessagePanel()