1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-01 00:54:58 +02:00

combine assert and input structs, clean up interface

This commit is contained in:
Jesse Duffield
2022-12-27 16:27:36 +11:00
parent c5c9f5bb94
commit b166b8f776
47 changed files with 1021 additions and 912 deletions

View File

@ -14,19 +14,21 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{
shell.CreateFile("myfile", "myfile content")
shell.CreateFile("myfile2", "myfile2 content")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.Model().CommitCount(0)
Run: func(shell *Shell, input *Input, keys config.KeybindingConfig) {
input.Model().CommitCount(0)
input.PrimaryAction()
input.NextItem()
input.PrimaryAction()
input.Press(keys.Files.CommitChanges)
input.Views().Files().
IsFocused().
PressPrimaryAction(). // stage file
SelectNextItem().
PressPrimaryAction(). // stage other file
Press(keys.Files.CommitChanges)
commitMessage := "my commit message"
input.CommitMessagePanel().Type(commitMessage).Confirm()
input.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
assert.Model().CommitCount(1)
assert.Model().HeadCommitMessage(Equals(commitMessage))
input.Model().CommitCount(1)
input.Model().HeadCommitMessage(Equals(commitMessage))
},
})

View File

@ -13,18 +13,20 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{
SetupRepo: func(shell *Shell) {
shell.CreateFile("myfile", "myfile content")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.Model().CommitCount(0)
Run: func(shell *Shell, input *Input, keys config.KeybindingConfig) {
input.Model().CommitCount(0)
input.PrimaryAction()
input.Press(keys.Files.CommitChanges)
input.Views().Files().
IsFocused().
PressPrimaryAction().
Press(keys.Files.CommitChanges)
input.CommitMessagePanel().Type("first line").AddNewline().AddNewline().Type("third line").Confirm()
input.ExpectCommitMessagePanel().Type("first line").AddNewline().AddNewline().Type("third line").Confirm()
assert.Model().CommitCount(1)
assert.Model().HeadCommitMessage(Equals("first line"))
input.Model().CommitCount(1)
input.Model().HeadCommitMessage(Equals("first line"))
input.SwitchToCommitsView()
assert.Views().Main().Content(MatchesRegexp("first line\n\\s*\n\\s*third line"))
input.Views().Commits().Focus()
input.Views().Main().Content(MatchesRegexp("first line\n\\s*\n\\s*third line"))
},
})

View File

@ -16,25 +16,25 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{
EmptyCommit("commit 2").
EmptyCommit("commit 3")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.Model().CommitCount(3)
Run: func(shell *Shell, input *Input, keys config.KeybindingConfig) {
input.Model().CommitCount(3)
input.SwitchToCommitsView()
assert.Views().Current().Lines(
Contains("commit 3"),
Contains("commit 2"),
Contains("commit 1"),
)
input.NextItem()
input.Press(keys.Universal.New)
input.Views().Commits().
Focus().
Lines(
Contains("commit 3"),
Contains("commit 2"),
Contains("commit 1"),
).
SelectNextItem().
Press(keys.Universal.New)
branchName := "my-branch-name"
input.Prompt().Title(Equals("New Branch Name")).Type(branchName).Confirm()
input.ExpectPrompt().Title(Contains("New Branch Name")).Type(branchName).Confirm()
assert.Model().CurrentBranchName(branchName)
input.Model().CurrentBranchName(branchName)
assert.Views().ByName("commits").Lines(
input.Views().Commits().Lines(
Contains("commit 2"),
Contains("commit 1"),
)

View File

@ -15,28 +15,28 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{
shell.GitAddAll()
shell.Commit("first commit")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.Model().CommitCount(1)
Run: func(shell *Shell, input *Input, keys config.KeybindingConfig) {
input.Model().CommitCount(1)
input.SwitchToCommitsView()
input.Views().Commits().
Focus().
Lines(
Contains("first commit"),
).
Press(keys.Commits.RevertCommit)
assert.Views().Current().Lines(
Contains("first commit"),
)
input.Press(keys.Commits.RevertCommit)
input.Confirmation().
input.ExpectConfirmation().
Title(Equals("Revert commit")).
Content(MatchesRegexp(`Are you sure you want to revert \w+?`)).
Confirm()
assert.Views().Current().Name("commits").
input.Views().Commits().IsFocused().
Lines(
Contains("Revert \"first commit\"").IsSelected(),
Contains("first commit"),
)
assert.Views().Main().Content(Contains("-myfile content"))
assert.FileSystem().PathNotPresent("myfile")
input.Views().Main().Content(Contains("-myfile content"))
input.FileSystem().PathNotPresent("myfile")
},
})

View File

@ -15,38 +15,41 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{
CreateFile("myfile", "myfile content\nwith a second line").
CreateFile("myfile2", "myfile2 content")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.Model().CommitCount(0)
Run: func(shell *Shell, input *Input, keys config.KeybindingConfig) {
input.Model().CommitCount(0)
assert.Views().Current().Name("files")
assert.Views().Current().SelectedLine(Contains("myfile"))
// stage the file
input.PrimaryAction()
input.Enter()
assert.Views().Current().Name("stagingSecondary")
input.Views().Files().
IsFocused().
SelectedLine(Contains("myfile")).
PressPrimaryAction(). // stage the file
PressEnter()
input.Views().StagingSecondary().IsFocused()
// we start with both lines having been staged
assert.Views().ByName("stagingSecondary").Content(Contains("+myfile content"))
assert.Views().ByName("stagingSecondary").Content(Contains("+with a second line"))
assert.Views().ByName("staging").Content(DoesNotContain("+myfile content"))
assert.Views().ByName("staging").Content(DoesNotContain("+with a second line"))
input.Views().StagingSecondary().Content(Contains("+myfile content"))
input.Views().StagingSecondary().Content(Contains("+with a second line"))
input.Views().Staging().Content(DoesNotContain("+myfile content"))
input.Views().Staging().Content(DoesNotContain("+with a second line"))
// unstage the selected line
input.PrimaryAction()
input.Views().StagingSecondary().
PressPrimaryAction()
// the line should have been moved to the main view
assert.Views().ByName("stagingSecondary").Content(DoesNotContain("+myfile content"))
assert.Views().ByName("stagingSecondary").Content(Contains("+with a second line"))
assert.Views().ByName("staging").Content(Contains("+myfile content"))
assert.Views().ByName("staging").Content(DoesNotContain("+with a second line"))
input.Views().StagingSecondary().Content(DoesNotContain("+myfile content"))
input.Views().StagingSecondary().Content(Contains("+with a second line"))
input.Views().Staging().Content(Contains("+myfile content"))
input.Views().Staging().Content(DoesNotContain("+with a second line"))
input.Views().StagingSecondary().
Press(keys.Files.CommitChanges)
input.Press(keys.Files.CommitChanges)
commitMessage := "my commit message"
input.Type(commitMessage)
input.Confirm()
input.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
assert.Model().CommitCount(1)
assert.Model().HeadCommitMessage(Equals(commitMessage))
assert.Views().Current().Name("stagingSecondary")
input.Model().CommitCount(1)
input.Model().HeadCommitMessage(Equals(commitMessage))
input.Views().StagingSecondary().IsFocused()
// TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
},

View File

@ -15,38 +15,41 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{
CreateFile("myfile", "myfile content\nwith a second line").
CreateFile("myfile2", "myfile2 content")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.Model().CommitCount(0)
Run: func(shell *Shell, input *Input, keys config.KeybindingConfig) {
input.Model().CommitCount(0)
// stage the file
assert.Views().Current().Name("files")
assert.Views().Current().SelectedLine(Contains("myfile"))
input.PrimaryAction()
input.Enter()
assert.Views().Current().Name("stagingSecondary")
input.Views().Files().
IsFocused().
SelectedLine(Contains("myfile")).
PressPrimaryAction().
PressEnter()
// we start with both lines having been staged
assert.Views().ByName("stagingSecondary").Content(
input.Views().StagingSecondary().Content(
Contains("+myfile content").Contains("+with a second line"),
)
assert.Views().ByName("staging").Content(
input.Views().Staging().Content(
DoesNotContain("+myfile content").DoesNotContain("+with a second line"),
)
// unstage the selected line
input.PrimaryAction()
input.Views().StagingSecondary().
IsFocused().
PressPrimaryAction()
// the line should have been moved to the main view
assert.Views().ByName("stagingSecondary").Content(DoesNotContain("+myfile content").Contains("+with a second line"))
assert.Views().ByName("staging").Content(Contains("+myfile content").DoesNotContain("+with a second line"))
input.Press(keys.Files.CommitChangesWithoutHook)
input.Views().Staging().Content(Contains("+myfile content").DoesNotContain("+with a second line"))
input.Views().StagingSecondary().
Content(DoesNotContain("+myfile content").Contains("+with a second line")).
Press(keys.Files.CommitChangesWithoutHook)
commitMessage := ": my commit message"
input.CommitMessagePanel().InitialText(Contains("WIP")).Type(commitMessage).Confirm()
input.ExpectCommitMessagePanel().InitialText(Contains("WIP")).Type(commitMessage).Confirm()
assert.Model().CommitCount(1)
assert.Model().HeadCommitMessage(Equals("WIP" + commitMessage))
assert.Views().Current().Name("stagingSecondary")
input.Model().CommitCount(1)
input.Model().HeadCommitMessage(Equals("WIP" + commitMessage))
input.Views().StagingSecondary().IsFocused()
// TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
},

View File

@ -5,7 +5,7 @@ import (
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
// TODO: find out why we can't use assert.SelectedLine() on the staging/stagingSecondary views.
// TODO: find out why we can't use input.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",
@ -17,26 +17,35 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{
CreateFile("myfile", "myfile content\nwith a second line").
CreateFile("myfile2", "myfile2 content")
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.Model().CommitCount(0)
Run: func(shell *Shell, input *Input, keys config.KeybindingConfig) {
input.Model().CommitCount(0)
input.Views().Files().
IsFocused().
SelectedLine(Contains("myfile")).
PressEnter()
input.Views().Staging().
IsFocused()
input.Views().StagingSecondary().Content(DoesNotContain("+myfile content"))
assert.Views().Current().Name("files").SelectedLine(Contains("myfile"))
input.Enter()
assert.Views().Current().Name("staging")
assert.Views().ByName("stagingSecondary").Content(DoesNotContain("+myfile content"))
// stage the first line
input.PrimaryAction()
assert.Views().ByName("staging").Content(DoesNotContain("+myfile content"))
assert.Views().ByName("stagingSecondary").Content(Contains("+myfile content"))
input.Views().Staging().
PressPrimaryAction()
input.Press(keys.Files.CommitChanges)
input.Views().Staging().Content(DoesNotContain("+myfile content"))
input.Views().StagingSecondary().Content(Contains("+myfile content"))
input.Views().Staging().
Press(keys.Files.CommitChanges)
commitMessage := "my commit message"
input.CommitMessagePanel().Type(commitMessage).Confirm()
input.ExpectCommitMessagePanel().Type(commitMessage).Confirm()
assert.Model().CommitCount(1)
assert.Model().HeadCommitMessage(Equals(commitMessage))
assert.Views().Current().Name("staging")
input.Model().CommitCount(1)
input.Model().HeadCommitMessage(Equals(commitMessage))
input.Views().Staging().IsFocused()
// TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed)
},