From ed93e0a2b0943379470049d2a25e4fb828179b97 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 27 Dec 2022 22:52:20 +1100 Subject: [PATCH] remove dependency on model --- pkg/gui/gui_driver.go | 4 - pkg/integration/components/git.go | 28 +++++++ pkg/integration/components/model.go | 84 ------------------- pkg/integration/components/shell.go | 11 +++ pkg/integration/components/test.go | 8 +- pkg/integration/components/test_driver.go | 14 +--- pkg/integration/components/test_test.go | 6 -- pkg/integration/components/view.go | 45 +++++++++- pkg/integration/tests/bisect/basic.go | 2 - .../tests/bisect/from_other_branch.go | 2 - pkg/integration/tests/branch/suggestions.go | 2 +- .../cherry_pick/cherry_pick_conflicts.go | 2 +- pkg/integration/tests/commit/commit.go | 10 ++- .../tests/commit/commit_multiline.go | 9 +- pkg/integration/tests/commit/new_branch.go | 10 +-- pkg/integration/tests/commit/revert.go | 2 - pkg/integration/tests/commit/staged.go | 10 ++- .../tests/commit/staged_without_hooks.go | 10 ++- pkg/integration/tests/commit/unstaged.go | 10 ++- .../tests/config/remote_named_star.go | 6 +- .../tests/custom_commands/basic.go | 3 +- .../tests/custom_commands/form_prompts.go | 10 ++- .../custom_commands/menu_from_command.go | 11 ++- .../menu_from_commands_output.go | 5 +- .../tests/custom_commands/multiple_prompts.go | 11 ++- .../tests/file/dir_with_untracked_file.go | 5 +- pkg/integration/tests/file/discard_changes.go | 4 +- .../tests/interactive_rebase/amend_merge.go | 18 ++-- pkg/integration/tests/misc/confirm_on_quit.go | 2 - pkg/integration/tests/stash/stash.go | 16 +++- .../stash/stash_including_untracked_files.go | 17 +++- pkg/integration/types/types.go | 1 - 32 files changed, 200 insertions(+), 178 deletions(-) create mode 100644 pkg/integration/components/git.go delete mode 100644 pkg/integration/components/model.go diff --git a/pkg/gui/gui_driver.go b/pkg/gui/gui_driver.go index 268d53f1d..cf1e3bbb4 100644 --- a/pkg/gui/gui_driver.go +++ b/pkg/gui/gui_driver.go @@ -49,10 +49,6 @@ func (self *GuiDriver) CurrentContext() types.Context { return self.gui.c.CurrentContext() } -func (self *GuiDriver) Model() *types.Model { - return self.gui.State.Model -} - func (self *GuiDriver) Fail(message string) { self.gui.g.Close() // need to give the gui time to close diff --git a/pkg/integration/components/git.go b/pkg/integration/components/git.go new file mode 100644 index 000000000..b9b3dcc46 --- /dev/null +++ b/pkg/integration/components/git.go @@ -0,0 +1,28 @@ +package components + +import ( + "fmt" + "strings" +) + +type Git struct { + *assertionHelper + shell *Shell +} + +func (self *Git) CurrentBranchName(expectedName string) *Git { + return self.assert("git rev-parse --abbrev-ref HEAD", expectedName) +} + +func (self *Git) assert(cmdStr string, expected string) *Git { + self.assertWithRetries(func() (bool, string) { + output, err := self.shell.runCommandWithOutput(cmdStr) + if err != nil { + return false, fmt.Sprintf("Unexpected error running command: `%s`. Error: %s", cmdStr, err.Error()) + } + actual := strings.TrimSpace(output) + return actual == expected, fmt.Sprintf("Expected current branch name to be '%s', but got '%s'", expected, actual) + }) + + return self +} diff --git a/pkg/integration/components/model.go b/pkg/integration/components/model.go deleted file mode 100644 index 368c50852..000000000 --- a/pkg/integration/components/model.go +++ /dev/null @@ -1,84 +0,0 @@ -package components - -import ( - "fmt" - - integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types" -) - -type Model struct { - *assertionHelper - gui integrationTypes.GuiDriver -} - -func (self *Model) WorkingTreeFileCount(expectedCount int) *Model { - self.assertWithRetries(func() (bool, string) { - actualCount := len(self.gui.Model().Files) - - return actualCount == expectedCount, fmt.Sprintf( - "Expected %d changed working tree files, but got %d", - expectedCount, actualCount, - ) - }) - - return self -} - -func (self *Model) CommitCount(expectedCount int) *Model { - self.assertWithRetries(func() (bool, string) { - actualCount := len(self.gui.Model().Commits) - - return actualCount == expectedCount, fmt.Sprintf( - "Expected %d commits present, but got %d", - expectedCount, actualCount, - ) - }) - - return self -} - -func (self *Model) StashCount(expectedCount int) *Model { - self.assertWithRetries(func() (bool, string) { - actualCount := len(self.gui.Model().StashEntries) - - return actualCount == expectedCount, fmt.Sprintf( - "Expected %d stash entries, but got %d", - expectedCount, actualCount, - ) - }) - - return self -} - -func (self *Model) AtLeastOneCommit() *Model { - self.assertWithRetries(func() (bool, string) { - actualCount := len(self.gui.Model().Commits) - - return actualCount > 0, "Expected at least one commit present" - }) - - return self -} - -func (self *Model) HeadCommitMessage(matcher *matcher) *Model { - self.assertWithRetries(func() (bool, string) { - return len(self.gui.Model().Commits) > 0, "Expected at least one commit to be present" - }) - - self.matchString(matcher, "Unexpected commit message.", - func() string { - return self.gui.Model().Commits[0].Name - }, - ) - - return self -} - -func (self *Model) CurrentBranchName(expectedViewName string) *Model { - self.assertWithRetries(func() (bool, string) { - actual := self.gui.CheckedOutRef().Name - return actual == expectedViewName, fmt.Sprintf("Expected current branch name to be '%s', but got '%s'", expectedViewName, actual) - }) - - return self -} diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 3fd63c8cc..f54d0fa5a 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -38,6 +38,17 @@ func (self *Shell) RunCommand(cmdStr string) *Shell { return self } +func (self *Shell) runCommandWithOutput(cmdStr string) (string, error) { + args := str.ToArgv(cmdStr) + cmd := secureexec.Command(args[0], args[1:]...) + cmd.Env = os.Environ() + cmd.Dir = self.dir + + output, err := cmd.CombinedOutput() + + return string(output), err +} + func (self *Shell) RunShellCommand(cmdStr string) *Shell { cmd := secureexec.Command("sh", "-c", cmdStr) cmd.Env = os.Environ() diff --git a/pkg/integration/components/test.go b/pkg/integration/components/test.go index 0b36a12d9..9291cf329 100644 --- a/pkg/integration/components/test.go +++ b/pkg/integration/components/test.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/env" integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -89,9 +90,12 @@ func (self *IntegrationTest) SetupRepo(shell *Shell) { self.setupRepo(shell) } -// I want access to all contexts, the model, the ability to press a key, the ability to log, func (self *IntegrationTest) Run(gui integrationTypes.GuiDriver) { - shell := NewShell("/tmp/lazygit-test", func(errorMsg string) { gui.Fail(errorMsg) }) + // we pass the --pass arg to lazygit when running an integration test, and that + // ends up stored in the following env var + repoPath := env.GetGitWorkTreeEnv() + + shell := NewShell(repoPath, func(errorMsg string) { gui.Fail(errorMsg) }) keys := gui.Keys() testDriver := NewTestDriver(gui, shell, keys, KeyPressDelay()) diff --git a/pkg/integration/components/test_driver.go b/pkg/integration/components/test_driver.go index f2604d211..a314c9fd3 100644 --- a/pkg/integration/components/test_driver.go +++ b/pkg/integration/components/test_driver.go @@ -8,7 +8,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types" - "github.com/samber/lo" ) type TestDriver struct { @@ -220,9 +219,9 @@ func (self *TestDriver) Views() *Views { return &Views{t: self} } -// for making assertions on the lazygit model -func (self *TestDriver) Model() *Model { - return &Model{assertionHelper: self.assertionHelper, gui: self.gui} +// for making assertions through git itself +func (self *TestDriver) Git() *Git { + return &Git{assertionHelper: self.assertionHelper, shell: self.shell} } // for making assertions on the file system @@ -235,10 +234,3 @@ func (self *TestDriver) FileSystem() *FileSystem { func (self *TestDriver) Fail(message string) { self.assertionHelper.fail(message) } - -func (self *TestDriver) NotInPopup() { - self.assertWithRetries(func() (bool, string) { - viewName := self.gui.CurrentContext().GetView().Name() - return !lo.Contains([]string{"menu", "confirmation", "commitMessage"}, viewName), fmt.Sprintf("Unexpected popup view present: %s view", viewName) - }) -} diff --git a/pkg/integration/components/test_test.go b/pkg/integration/components/test_test.go index ccab35dc8..6c2f15b4b 100644 --- a/pkg/integration/components/test_test.go +++ b/pkg/integration/components/test_test.go @@ -30,10 +30,6 @@ func (self *fakeGuiDriver) CurrentContext() types.Context { return nil } -func (self *fakeGuiDriver) Model() *types.Model { - return &types.Model{Commits: []*models.Commit{}} -} - func (self *fakeGuiDriver) Fail(message string) { self.failureMessage = message } @@ -66,7 +62,6 @@ func TestAssertionFailure(t *testing.T) { Run: func(t *TestDriver, keys config.KeybindingConfig) { t.press("a") t.press("b") - t.Model().CommitCount(2) }, }) driver := &fakeGuiDriver{} @@ -93,7 +88,6 @@ func TestSuccess(t *testing.T) { Run: func(t *TestDriver, keys config.KeybindingConfig) { t.press("a") t.press("b") - t.Model().CommitCount(0) }, }) driver := &fakeGuiDriver{} diff --git a/pkg/integration/components/view.go b/pkg/integration/components/view.go index 479c419cc..f809c3a4a 100644 --- a/pkg/integration/components/view.go +++ b/pkg/integration/components/view.go @@ -2,6 +2,7 @@ package components import ( "fmt" + "strings" "github.com/jesseduffield/gocui" ) @@ -28,6 +29,10 @@ func (self *View) Title(expected *matcher) *View { // This method is convenient when you have a list of commits but you only want to // assert on the first couple of commits. func (self *View) TopLines(matchers ...*matcher) *View { + if len(matchers) < 1 { + self.t.fail("TopLines method requires at least one matcher. If you are trying to assert that there are no lines, use .IsEmpty()") + } + self.t.assertWithRetries(func() (bool, string) { lines := self.getView().BufferLines() return len(lines) >= len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected at least %d, got %d", len(matchers), len(lines)) @@ -39,10 +44,7 @@ func (self *View) TopLines(matchers ...*matcher) *View { // asserts that the view has lines matching the given matchers. One matcher must be passed for each line. // If you only care about the top n lines, use the TopLines method instead. func (self *View) Lines(matchers ...*matcher) *View { - self.t.assertWithRetries(func() (bool, string) { - lines := self.getView().BufferLines() - return len(lines) == len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected %d, got %d", len(matchers), len(lines)) - }) + self.LineCount(len(matchers)) return self.assertLines(matchers...) } @@ -184,6 +186,41 @@ func (self *View) NavigateToListItem(matcher *matcher) *View { return self } +// returns true if the view is a list view and it contains no items +func (self *View) IsEmpty() *View { + self.t.assertWithRetries(func() (bool, string) { + actual := strings.TrimSpace(self.getView().Buffer()) + return actual == "", fmt.Sprintf("%s: Unexpected content in view: expected no content. Content: %s", self.context, actual) + }) + + return self +} + +func (self *View) LineCount(expectedCount int) *View { + if expectedCount == 0 { + return self.IsEmpty() + } + + self.t.assertWithRetries(func() (bool, string) { + lines := self.getView().BufferLines() + return len(lines) == expectedCount, fmt.Sprintf("unexpected number of lines in view. Expected %d, got %d", expectedCount, len(lines)) + }) + + self.t.assertWithRetries(func() (bool, string) { + lines := self.getView().BufferLines() + + // if the view has a single blank line (often the case) we want to treat that as having no lines + if len(lines) == 1 && expectedCount == 1 { + actual := strings.TrimSpace(self.getView().Buffer()) + return actual == "", fmt.Sprintf("unexpected number of lines in view. Expected %d, got 0", expectedCount) + } + + return len(lines) == expectedCount, fmt.Sprintf("unexpected number of lines in view. Expected %d, got %d", expectedCount, len(lines)) + }) + + return self +} + // for when you want to make some assertion unrelated to the current view // without breaking the method chain func (self *View) Tap(f func()) *View { diff --git a/pkg/integration/tests/bisect/basic.go b/pkg/integration/tests/bisect/basic.go index 8294f61a4..5092f2f0a 100644 --- a/pkg/integration/tests/bisect/basic.go +++ b/pkg/integration/tests/bisect/basic.go @@ -29,8 +29,6 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectMenu().Title(Equals("Bisect")).Select(MatchesRegexp(`mark .* as good`)).Confirm() } - t.Model().AtLeastOneCommit() - t.Views().Commits(). Focus(). SelectedLine(Contains("commit 10")). diff --git a/pkg/integration/tests/bisect/from_other_branch.go b/pkg/integration/tests/bisect/from_other_branch.go index 13e7e8055..7c2307bd6 100644 --- a/pkg/integration/tests/bisect/from_other_branch.go +++ b/pkg/integration/tests/bisect/from_other_branch.go @@ -21,8 +21,6 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{ Run: func(t *TestDriver, keys config.KeybindingConfig) { t.Views().Information().Content(Contains("bisecting")) - t.Model().AtLeastOneCommit() - t.Views().Commits(). Focus(). TopLines( diff --git a/pkg/integration/tests/branch/suggestions.go b/pkg/integration/tests/branch/suggestions.go index 65c64fa6d..0671578ed 100644 --- a/pkg/integration/tests/branch/suggestions.go +++ b/pkg/integration/tests/branch/suggestions.go @@ -34,6 +34,6 @@ var Suggestions = NewIntegrationTest(NewIntegrationTestArgs{ SelectFirstSuggestion(). Confirm() - t.Model().CurrentBranchName("branch-to-checkout") + t.Git().CurrentBranchName("branch-to-checkout") }, }) diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go index 5eef30b50..c41de78b3 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go @@ -70,7 +70,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ Content(Contains("all merge conflicts resolved. Continue?")). Confirm() - t.Model().WorkingTreeFileCount(0) + t.Views().Files().IsEmpty() t.Views().Commits(). Focus(). diff --git a/pkg/integration/tests/commit/commit.go b/pkg/integration/tests/commit/commit.go index 5950545e7..dc0615c87 100644 --- a/pkg/integration/tests/commit/commit.go +++ b/pkg/integration/tests/commit/commit.go @@ -15,7 +15,8 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{ shell.CreateFile("myfile2", "myfile2 content") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(0) + t.Views().Commits(). + IsEmpty() t.Views().Files(). IsFocused(). @@ -28,8 +29,9 @@ var Commit = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectCommitMessagePanel().Type(commitMessage).Confirm() - t.Model(). - CommitCount(1). - HeadCommitMessage(Equals(commitMessage)) + t.Views().Commits(). + Lines( + Contains(commitMessage), + ) }, }) diff --git a/pkg/integration/tests/commit/commit_multiline.go b/pkg/integration/tests/commit/commit_multiline.go index 11876e09a..1a5175146 100644 --- a/pkg/integration/tests/commit/commit_multiline.go +++ b/pkg/integration/tests/commit/commit_multiline.go @@ -14,7 +14,8 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{ shell.CreateFile("myfile", "myfile content") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(0) + t.Views().Commits(). + IsEmpty() t.Views().Files(). IsFocused(). @@ -23,8 +24,10 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectCommitMessagePanel().Type("first line").AddNewline().AddNewline().Type("third line").Confirm() - t.Model().CommitCount(1) - t.Model().HeadCommitMessage(Equals("first line")) + t.Views().Commits(). + Lines( + Contains("first line"), + ) t.Views().Commits().Focus() t.Views().Main().Content(MatchesRegexp("first line\n\\s*\n\\s*third line")) diff --git a/pkg/integration/tests/commit/new_branch.go b/pkg/integration/tests/commit/new_branch.go index 6f528ff4c..16ae79b35 100644 --- a/pkg/integration/tests/commit/new_branch.go +++ b/pkg/integration/tests/commit/new_branch.go @@ -17,22 +17,20 @@ var NewBranch = NewIntegrationTest(NewIntegrationTestArgs{ EmptyCommit("commit 3") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(3) - t.Views().Commits(). Focus(). - SelectNextItem(). Lines( - Contains("commit 3"), - Contains("commit 2").IsSelected(), + Contains("commit 3").IsSelected(), + Contains("commit 2"), Contains("commit 1"), ). + SelectNextItem(). Press(keys.Universal.New). Tap(func() { branchName := "my-branch-name" t.ExpectPrompt().Title(Contains("New Branch Name")).Type(branchName).Confirm() - t.Model().CurrentBranchName(branchName) + t.Git().CurrentBranchName(branchName) }). Lines( Contains("commit 2"), diff --git a/pkg/integration/tests/commit/revert.go b/pkg/integration/tests/commit/revert.go index bee657380..0f9c3fb9e 100644 --- a/pkg/integration/tests/commit/revert.go +++ b/pkg/integration/tests/commit/revert.go @@ -16,8 +16,6 @@ var Revert = NewIntegrationTest(NewIntegrationTestArgs{ shell.Commit("first commit") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(1) - t.Views().Commits(). Focus(). Lines( diff --git a/pkg/integration/tests/commit/staged.go b/pkg/integration/tests/commit/staged.go index d0698192a..d5c5dc84e 100644 --- a/pkg/integration/tests/commit/staged.go +++ b/pkg/integration/tests/commit/staged.go @@ -16,7 +16,8 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{ CreateFile("myfile2", "myfile2 content") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(0) + t.Views().Commits(). + IsEmpty() t.Views().Files(). IsFocused(). @@ -47,8 +48,11 @@ var Staged = NewIntegrationTest(NewIntegrationTestArgs{ commitMessage := "my commit message" t.ExpectCommitMessagePanel().Type(commitMessage).Confirm() - t.Model().CommitCount(1) - t.Model().HeadCommitMessage(Equals(commitMessage)) + t.Views().Commits(). + Lines( + Contains(commitMessage), + ) + t.Views().StagingSecondary().IsFocused() // TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed) diff --git a/pkg/integration/tests/commit/staged_without_hooks.go b/pkg/integration/tests/commit/staged_without_hooks.go index 8a6b0d3d0..32cd8df06 100644 --- a/pkg/integration/tests/commit/staged_without_hooks.go +++ b/pkg/integration/tests/commit/staged_without_hooks.go @@ -16,7 +16,8 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{ CreateFile("myfile2", "myfile2 content") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(0) + t.Views().Commits(). + IsEmpty() // stage the file t.Views().Files(). @@ -47,8 +48,11 @@ var StagedWithoutHooks = NewIntegrationTest(NewIntegrationTestArgs{ commitMessage := ": my commit message" t.ExpectCommitMessagePanel().InitialText(Contains("WIP")).Type(commitMessage).Confirm() - t.Model().CommitCount(1) - t.Model().HeadCommitMessage(Equals("WIP" + commitMessage)) + t.Views().Commits(). + Lines( + Contains("WIP" + commitMessage), + ) + t.Views().StagingSecondary().IsFocused() // TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed) diff --git a/pkg/integration/tests/commit/unstaged.go b/pkg/integration/tests/commit/unstaged.go index 3e0d68617..a3792e1b7 100644 --- a/pkg/integration/tests/commit/unstaged.go +++ b/pkg/integration/tests/commit/unstaged.go @@ -18,7 +18,8 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{ CreateFile("myfile2", "myfile2 content") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(0) + t.Views().Commits(). + IsEmpty() t.Views().Files(). IsFocused(). @@ -41,8 +42,11 @@ var Unstaged = NewIntegrationTest(NewIntegrationTestArgs{ commitMessage := "my commit message" t.ExpectCommitMessagePanel().Type(commitMessage).Confirm() - t.Model().CommitCount(1) - t.Model().HeadCommitMessage(Equals(commitMessage)) + t.Views().Commits(). + Lines( + Contains(commitMessage), + ) + t.Views().Staging().IsFocused() // TODO: assert that the staging panel has been refreshed (it currently does not get correctly refreshed) diff --git a/pkg/integration/tests/config/remote_named_star.go b/pkg/integration/tests/config/remote_named_star.go index 0306427ca..735389667 100644 --- a/pkg/integration/tests/config/remote_named_star.go +++ b/pkg/integration/tests/config/remote_named_star.go @@ -17,6 +17,10 @@ var RemoteNamedStar = NewIntegrationTest(NewIntegrationTestArgs{ SetupConfig: func(cfg *config.AppConfig) {}, Run: func(t *TestDriver, keys config.KeybindingConfig) { // here we're just asserting that we haven't panicked upon starting lazygit - t.Model().AtLeastOneCommit() + t.Views().Commits(). + Lines( + Anything(), + Anything(), + ) }, }) diff --git a/pkg/integration/tests/custom_commands/basic.go b/pkg/integration/tests/custom_commands/basic.go index a73fab5a9..ce500b9a6 100644 --- a/pkg/integration/tests/custom_commands/basic.go +++ b/pkg/integration/tests/custom_commands/basic.go @@ -22,9 +22,8 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{ } }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().WorkingTreeFileCount(0) - t.Views().Files(). + IsEmpty(). IsFocused(). Press("a"). Lines( diff --git a/pkg/integration/tests/custom_commands/form_prompts.go b/pkg/integration/tests/custom_commands/form_prompts.go index b35455368..c843232ee 100644 --- a/pkg/integration/tests/custom_commands/form_prompts.go +++ b/pkg/integration/tests/custom_commands/form_prompts.go @@ -56,9 +56,8 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{ } }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().WorkingTreeFileCount(0) - t.Views().Files(). + IsEmpty(). IsFocused(). Press("a") @@ -71,8 +70,11 @@ var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{ Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")). Confirm() - t.Model().WorkingTreeFileCount(1) - t.Views().Files().SelectedLine(Contains("my file")) + t.Views().Files(). + Lines( + Contains("my file").IsSelected(), + ) + t.Views().Main().Content(Contains(`"BAR"`)) }, }) diff --git a/pkg/integration/tests/custom_commands/menu_from_command.go b/pkg/integration/tests/custom_commands/menu_from_command.go index 580022521..71a6a5c15 100644 --- a/pkg/integration/tests/custom_commands/menu_from_command.go +++ b/pkg/integration/tests/custom_commands/menu_from_command.go @@ -43,7 +43,9 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{ } }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().WorkingTreeFileCount(0) + t.Views().Files(). + IsEmpty() + t.Views().Branches(). Focus(). Press("a") @@ -52,9 +54,12 @@ var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPrompt().Title(Equals("Description")).Type(" my branch").Confirm() - t.Model().WorkingTreeFileCount(1) + t.Views().Files(). + Focus(). + Lines( + Contains("output.txt").IsSelected(), + ) - t.Views().Files().Focus().SelectedLine(Contains("output.txt")) t.Views().Main().Content(Contains("bar Branch: #feature/foo my branch feature/foo")) }, }) diff --git a/pkg/integration/tests/custom_commands/menu_from_commands_output.go b/pkg/integration/tests/custom_commands/menu_from_commands_output.go index a9a899341..b4b649efd 100644 --- a/pkg/integration/tests/custom_commands/menu_from_commands_output.go +++ b/pkg/integration/tests/custom_commands/menu_from_commands_output.go @@ -42,8 +42,7 @@ var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{ } }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CurrentBranchName("feature/bar") - t.Model().WorkingTreeFileCount(0) + t.Git().CurrentBranchName("feature/bar") t.Views().Branches(). Focus(). @@ -56,6 +55,6 @@ var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectMenu().Title(Equals("Branch:")).Select(Equals("master")).Confirm() - t.Model().CurrentBranchName("master") + t.Git().CurrentBranchName("master") }, }) diff --git a/pkg/integration/tests/custom_commands/multiple_prompts.go b/pkg/integration/tests/custom_commands/multiple_prompts.go index fa69169aa..519160b88 100644 --- a/pkg/integration/tests/custom_commands/multiple_prompts.go +++ b/pkg/integration/tests/custom_commands/multiple_prompts.go @@ -54,9 +54,8 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{ } }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().WorkingTreeFileCount(0) - t.Views().Files(). + IsEmpty(). IsFocused(). Press("a") @@ -69,8 +68,12 @@ var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{ Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")). Confirm() - t.Model().WorkingTreeFileCount(1) - t.Views().Files().SelectedLine(Contains("myfile")) + t.Views().Files(). + Focus(). + Lines( + Contains("myfile").IsSelected(), + ) + t.Views().Main().Content(Contains("BAR")) }, }) diff --git a/pkg/integration/tests/file/dir_with_untracked_file.go b/pkg/integration/tests/file/dir_with_untracked_file.go index e94d237d9..39da6e157 100644 --- a/pkg/integration/tests/file/dir_with_untracked_file.go +++ b/pkg/integration/tests/file/dir_with_untracked_file.go @@ -22,7 +22,10 @@ var DirWithUntrackedFile = NewIntegrationTest(NewIntegrationTestArgs{ shell.UpdateFile("dir/file", "baz") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(1) + t.Views().Commits(). + Lines( + Contains("first commit"), + ) t.Views().Main(). Content(DoesNotContain("error: Could not access")). diff --git a/pkg/integration/tests/file/discard_changes.go b/pkg/integration/tests/file/discard_changes.go index ab08ff9b9..e47695742 100644 --- a/pkg/integration/tests/file/discard_changes.go +++ b/pkg/integration/tests/file/discard_changes.go @@ -72,8 +72,6 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(3) - type statusFile struct { status string label string @@ -121,6 +119,6 @@ var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{ {status: "??", label: "new.txt", menuTitle: "new.txt"}, }) - t.Model().WorkingTreeFileCount(0) + t.Views().Files().IsEmpty() }, }) diff --git a/pkg/integration/tests/interactive_rebase/amend_merge.go b/pkg/integration/tests/interactive_rebase/amend_merge.go index 1f09af0de..7301f1806 100644 --- a/pkg/integration/tests/interactive_rebase/amend_merge.go +++ b/pkg/integration/tests/interactive_rebase/amend_merge.go @@ -28,10 +28,14 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{ CreateFileAndAdd(postMergeFilename, postMergeFileContent) }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(3) - mergeCommitMessage := "Merge branch 'feature-branch' into development-branch" - t.Model().HeadCommitMessage(Contains(mergeCommitMessage)) + + t.Views().Commits(). + Lines( + Contains(mergeCommitMessage), + Contains("new feature commit"), + Contains("initial commit"), + ) t.Views().Commits(). Focus(). @@ -43,8 +47,12 @@ var AmendMerge = NewIntegrationTest(NewIntegrationTestArgs{ Confirm() // assuring we haven't added a brand new commit - t.Model().CommitCount(3) - t.Model().HeadCommitMessage(Contains(mergeCommitMessage)) + t.Views().Commits(). + Lines( + Contains(mergeCommitMessage), + Contains("new feature commit"), + Contains("initial commit"), + ) // assuring the post-merge file shows up in the merge commit. t.Views().Main(). diff --git a/pkg/integration/tests/misc/confirm_on_quit.go b/pkg/integration/tests/misc/confirm_on_quit.go index 109ece2c9..b4124c4fc 100644 --- a/pkg/integration/tests/misc/confirm_on_quit.go +++ b/pkg/integration/tests/misc/confirm_on_quit.go @@ -14,8 +14,6 @@ var ConfirmOnQuit = NewIntegrationTest(NewIntegrationTestArgs{ }, SetupRepo: func(shell *Shell) {}, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().CommitCount(0) - t.Views().Files(). IsFocused(). Press(keys.Universal.Quit) diff --git a/pkg/integration/tests/stash/stash.go b/pkg/integration/tests/stash/stash.go index 4265e0c23..c627faaf8 100644 --- a/pkg/integration/tests/stash/stash.go +++ b/pkg/integration/tests/stash/stash.go @@ -16,17 +16,25 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{ shell.GitAddAll() }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().StashCount(0) - t.Model().WorkingTreeFileCount(1) + t.Views().Stash(). + IsEmpty() t.Views().Files(). + Lines( + Contains("file"), + ). Press(keys.Files.ViewStashOptions) t.ExpectMenu().Title(Equals("Stash options")).Select(MatchesRegexp("stash all changes$")).Confirm() t.ExpectPrompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm() - t.Model().StashCount(1) - t.Model().WorkingTreeFileCount(0) + t.Views().Stash(). + Lines( + Contains("my stashed file"), + ) + + t.Views().Files(). + IsEmpty() }, }) diff --git a/pkg/integration/tests/stash/stash_including_untracked_files.go b/pkg/integration/tests/stash/stash_including_untracked_files.go index d46d7fb1d..756f7948e 100644 --- a/pkg/integration/tests/stash/stash_including_untracked_files.go +++ b/pkg/integration/tests/stash/stash_including_untracked_files.go @@ -17,17 +17,26 @@ var StashIncludingUntrackedFiles = NewIntegrationTest(NewIntegrationTestArgs{ shell.GitAdd("file_1") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { - t.Model().StashCount(0) - t.Model().WorkingTreeFileCount(2) + t.Views().Stash(). + IsEmpty() t.Views().Files(). + Lines( + Contains("file_1"), + Contains("file_2"), + ). Press(keys.Files.ViewStashOptions) t.ExpectMenu().Title(Equals("Stash options")).Select(Contains("stash all changes including untracked files")).Confirm() t.ExpectPrompt().Title(Equals("Stash changes")).Type("my stashed file").Confirm() - t.Model().StashCount(1) - t.Model().WorkingTreeFileCount(0) + t.Views().Stash(). + Lines( + Contains("my stashed file"), + ) + + t.Views().Files(). + IsEmpty() }, }) diff --git a/pkg/integration/types/types.go b/pkg/integration/types/types.go index 4bc8569f7..5326054d2 100644 --- a/pkg/integration/types/types.go +++ b/pkg/integration/types/types.go @@ -20,7 +20,6 @@ type GuiDriver interface { PressKey(string) Keys() config.KeybindingConfig CurrentContext() types.Context - Model() *types.Model Fail(message string) // These two log methods are for the sake of debugging while testing. There's no need to actually // commit any logging.