diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-12-26 11:12:56 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-12-26 12:20:13 +1100 |
commit | 9a6f21ce429fedd949fdf9853c6ebf4892f858fd (patch) | |
tree | d8ee0c4ad1e993319caf53e0554186f6103fb1d7 /pkg/integration/tests | |
parent | fa0414777fcf266a05b777e2e8b7d487fd56f376 (diff) |
cleaner test assertions
Diffstat (limited to 'pkg/integration/tests')
30 files changed, 237 insertions, 218 deletions
diff --git a/pkg/integration/tests/bisect/basic.go b/pkg/integration/tests/bisect/basic.go index eb44fa2ab..58fcb8896 100644 --- a/pkg/integration/tests/bisect/basic.go +++ b/pkg/integration/tests/bisect/basic.go @@ -34,39 +34,40 @@ var Basic = NewIntegrationTest(NewIntegrationTestArgs{ input.SwitchToCommitsWindow() - assert.CurrentLine(Contains("commit 10")) + assert.CurrentView().SelectedLine(Contains("commit 10")) input.NavigateToListItem(Contains("commit 09")) markCommitAsBad() - assert.ViewContent("information", Contains("bisecting")) + assert.View("information").Content(Contains("bisecting")) - assert.CurrentViewName("commits") - assert.CurrentLine(Contains("<-- bad")) + assert.CurrentView().Name("commits") + assert.CurrentView().SelectedLine(Contains("<-- bad")) input.NavigateToListItem(Contains("commit 02")) markCommitAsGood() // lazygit will land us in the commit between our good and bad commits. - assert.CurrentViewName("commits") - assert.CurrentLine(Contains("commit 05")) - assert.CurrentLine(Contains("<-- current")) + assert.CurrentView(). + Name("commits"). + SelectedLine(Contains("commit 05")). + SelectedLine(Contains("<-- current")) markCommitAsBad() - assert.CurrentViewName("commits") - assert.CurrentLine(Contains("commit 04")) - assert.CurrentLine(Contains("<-- current")) + assert.CurrentView(). + Name("commits"). + SelectedLine(Contains("commit 04")). + SelectedLine(Contains("<-- current")) markCommitAsGood() // commit 5 is the culprit because we marked 4 as good and 5 as bad. input.Alert(Equals("Bisect complete"), MatchesRegexp("(?s)commit 05.*Do you want to reset")) - assert.CurrentViewName("commits") - assert.CurrentViewContent(Contains("commit 04")) - assert.ViewContent("information", NotContains("bisecting")) + assert.CurrentView().Name("commits").Content(Contains("commit 04")) + assert.View("information").Content(NotContains("bisecting")) }, }) diff --git a/pkg/integration/tests/bisect/from_other_branch.go b/pkg/integration/tests/bisect/from_other_branch.go index 8c00f9d31..a523a4e3e 100644 --- a/pkg/integration/tests/bisect/from_other_branch.go +++ b/pkg/integration/tests/bisect/from_other_branch.go @@ -24,13 +24,13 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{ assert *Assert, keys config.KeybindingConfig, ) { - assert.ViewContent("information", Contains("bisecting")) + assert.View("information").Content(Contains("bisecting")) assert.AtLeastOneCommit() input.SwitchToCommitsWindow() - assert.ViewTopLines("commits", + assert.CurrentView().Name("commits").TopLines( MatchesRegexp(`<-- bad.*commit 08`), MatchesRegexp(`<-- current.*commit 07`), MatchesRegexp(`\?.*commit 06`), @@ -44,11 +44,10 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{ input.Alert(Equals("Bisect complete"), MatchesRegexp(`(?s)commit 08.*Do you want to reset`)) - assert.ViewContent("information", NotContains("bisecting")) + assert.View("information").Content(NotContains("bisecting")) // back in master branch which just had the one commit - assert.CurrentViewName("commits") - assert.CurrentViewLines( + assert.CurrentView().Name("commits").Lines( Contains("only commit on master"), ) }, diff --git a/pkg/integration/tests/branch/checkout_by_name.go b/pkg/integration/tests/branch/checkout_by_name.go index 652a1c58e..d8af26ee9 100644 --- a/pkg/integration/tests/branch/checkout_by_name.go +++ b/pkg/integration/tests/branch/checkout_by_name.go @@ -19,9 +19,8 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesWindow() - assert.CurrentViewName("localBranches") - assert.CurrentViewLines( + assert.CurrentView().Name("localBranches").Lines( Contains("master"), Contains("@"), ) @@ -33,13 +32,12 @@ var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{ input.Alert(Equals("Branch not found"), Equals("Branch not found. Create a new branch named new-branch?")) - assert.CurrentViewName("localBranches") - assert.CurrentViewLines( - MatchesRegexp(`\*.*new-branch`), - Contains("master"), - Contains("@"), - ) - - assert.CurrentLine(Contains("new-branch")) + assert.CurrentView().Name("localBranches"). + Lines( + MatchesRegexp(`\*.*new-branch`), + Contains("master"), + Contains("@"), + ). + SelectedLine(Contains("new-branch")) }, }) diff --git a/pkg/integration/tests/branch/delete.go b/pkg/integration/tests/branch/delete.go index 55e9b6aa5..a873ebaef 100644 --- a/pkg/integration/tests/branch/delete.go +++ b/pkg/integration/tests/branch/delete.go @@ -18,9 +18,8 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesWindow() - assert.CurrentViewName("localBranches") - assert.CurrentViewLines( + assert.CurrentView().Name("localBranches").Lines( MatchesRegexp(`\*.*branch-two`), MatchesRegexp(`branch-one`), MatchesRegexp(`master`), @@ -34,11 +33,11 @@ var Delete = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Universal.Remove) input.AcceptConfirmation(Equals("Delete Branch"), Contains("Are you sure you want to delete the branch 'branch-one'?")) - assert.CurrentViewName("localBranches") - assert.CurrentViewLines( - MatchesRegexp(`\*.*branch-two`), - MatchesRegexp(`master`), - ) - assert.CurrentLineIdx(1) + assert.CurrentView().Name("localBranches"). + Lines( + MatchesRegexp(`\*.*branch-two`), + MatchesRegexp(`master`), + ). + SelectedLineIdx(1) }, }) diff --git a/pkg/integration/tests/branch/rebase.go b/pkg/integration/tests/branch/rebase.go index 8e60bd876..2b158e5e4 100644 --- a/pkg/integration/tests/branch/rebase.go +++ b/pkg/integration/tests/branch/rebase.go @@ -16,17 +16,15 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesWindow() - assert.CurrentViewName("localBranches") + assert.CurrentView().Name("localBranches") - assert.ViewLines( - "localBranches", + assert.View("localBranches").Lines( Contains("first-change-branch"), Contains("second-change-branch"), Contains("original-branch"), ) - assert.ViewTopLines( - "commits", + assert.View("commits").TopLines( Contains("first change"), Contains("original"), ) @@ -35,27 +33,24 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Branches.RebaseBranch) input.AcceptConfirmation(Equals("Rebasing"), Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")) - input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) - assert.CurrentViewName("files") - assert.CurrentLine(Contains("file")) + assert.CurrentView().Name("files").SelectedLine(Contains("file")) // not using Confirm() convenience method because I suspect we might change this // keybinding to something more bespoke input.Press(keys.Universal.Confirm) - assert.CurrentViewName("mergeConflicts") + assert.CurrentView().Name("mergeConflicts") input.PrimaryAction() - assert.ViewContent("information", Contains("rebasing")) + assert.View("information").Content(Contains("rebasing")) input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) - assert.ViewContent("information", NotContains("rebasing")) + assert.View("information").Content(NotContains("rebasing")) - assert.ViewTopLines( - "commits", + assert.View("commits").TopLines( Contains("second-change-branch unrelated change"), Contains("second change"), Contains("original"), diff --git a/pkg/integration/tests/branch/rebase_and_drop.go b/pkg/integration/tests/branch/rebase_and_drop.go index cb113997b..5d62ed551 100644 --- a/pkg/integration/tests/branch/rebase_and_drop.go +++ b/pkg/integration/tests/branch/rebase_and_drop.go @@ -19,17 +19,14 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesWindow() - assert.CurrentViewName("localBranches") - assert.ViewLines( - "localBranches", + assert.CurrentView().Name("localBranches").Lines( Contains("first-change-branch"), Contains("second-change-branch"), Contains("original-branch"), ) - assert.ViewTopLines( - "commits", + assert.View("commits").TopLines( Contains("to keep"), Contains("to remove"), Contains("first change"), @@ -41,26 +38,29 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ input.AcceptConfirmation(Equals("Rebasing"), Contains("Are you sure you want to rebase 'first-change-branch' on top of 'second-change-branch'?")) - assert.ViewContent("information", Contains("rebasing")) + assert.View("information").Content(Contains("rebasing")) input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) - assert.CurrentViewName("files") - assert.CurrentLine(Contains("file")) + assert.CurrentView(). + Name("files"). + SelectedLine(Contains("file")) input.SwitchToCommitsWindow() - assert.ViewTopLines( - "commits", - MatchesRegexp(`pick.*to keep`), - MatchesRegexp(`pick.*to remove`), - MatchesRegexp("YOU ARE HERE.*second-change-branch unrelated change"), - MatchesRegexp("second change"), - MatchesRegexp("original"), - ) - assert.CurrentLineIdx(0) + assert.CurrentView(). + Name("commits"). + TopLines( + MatchesRegexp(`pick.*to keep`), + MatchesRegexp(`pick.*to remove`), + MatchesRegexp("YOU ARE HERE.*second-change-branch unrelated change"), + MatchesRegexp("second change"), + MatchesRegexp("original"), + ). + SelectedLineIdx(0) + input.NextItem() input.Press(keys.Universal.Remove) - assert.CurrentLine(MatchesRegexp(`drop.*to remove`)) + assert.CurrentView().SelectedLine(MatchesRegexp(`drop.*to remove`)) input.SwitchToFilesWindow() @@ -68,15 +68,14 @@ var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ // keybinding to something more bespoke input.Press(keys.Universal.Confirm) - assert.CurrentViewName("mergeConflicts") + assert.CurrentView().Name("mergeConflicts") input.PrimaryAction() input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) - assert.ViewContent("information", NotContains("rebasing")) + assert.View("information").Content(NotContains("rebasing")) - assert.ViewTopLines( - "commits", + assert.View("commits").TopLines( Contains("to keep"), Contains("second-change-branch unrelated change"), Contains("second change"), diff --git a/pkg/integration/tests/branch/reset.go b/pkg/integration/tests/branch/reset.go index 4895a2cd8..d7b2db5a3 100644 --- a/pkg/integration/tests/branch/reset.go +++ b/pkg/integration/tests/branch/reset.go @@ -21,15 +21,14 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{ shell.EmptyCommit("current-branch commit") }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { - assert.ViewLines("commits", + assert.View("commits").Lines( Contains("current-branch commit"), Contains("root commit"), ) input.SwitchToBranchesWindow() - assert.CurrentViewName("localBranches") - assert.CurrentViewLines( + assert.CurrentView().Name("localBranches").Lines( Contains("current-branch"), Contains("other-branch"), ) @@ -40,12 +39,11 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{ input.Menu(Contains("reset to other-branch"), Contains("hard reset")) // ensure that we've returned from the menu before continuing - assert.CurrentViewName("localBranches") + assert.CurrentView().Name("localBranches") // assert that we now have the expected commits in the commit panel input.SwitchToCommitsWindow() - assert.CurrentViewName("commits") - assert.CurrentViewLines( + assert.CurrentView().Name("commits").Lines( Contains("other-branch commit"), Contains("root commit"), ) diff --git a/pkg/integration/tests/branch/suggestions.go b/pkg/integration/tests/branch/suggestions.go index 98cc3cf47..22c276556 100644 --- a/pkg/integration/tests/branch/suggestions.go +++ b/pkg/integration/tests/branch/suggestions.go @@ -22,7 +22,7 @@ var Suggestions = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesWindow() - assert.CurrentViewName("localBranches") + assert.CurrentView().Name("localBranches") input.Press(keys.Branches.CheckoutBranchByName) diff --git a/pkg/integration/tests/cherry_pick/cherry_pick.go b/pkg/integration/tests/cherry_pick/cherry_pick.go index 6d11b9a7e..7ca89f402 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick.go @@ -25,9 +25,8 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesWindow() - assert.CurrentViewName("localBranches") - assert.CurrentViewLines( + assert.CurrentView().Name("localBranches").Lines( Contains("first-branch"), Contains("second-branch"), Contains("master"), @@ -37,8 +36,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ input.Enter() - assert.CurrentViewName("subCommits") - assert.CurrentViewLines( + assert.CurrentView().Name("subCommits").Lines( Contains("four"), Contains("three"), Contains("base"), @@ -46,15 +44,14 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ // copy commits 'four' and 'three' input.Press(keys.Commits.CherryPickCopy) - assert.ViewContent("information", Contains("1 commit copied")) + assert.View("information").Content(Contains("1 commit copied")) input.NextItem() input.Press(keys.Commits.CherryPickCopy) - assert.ViewContent("information", Contains("2 commits copied")) + assert.View("information").Content(Contains("2 commits copied")) input.SwitchToCommitsWindow() - assert.CurrentViewName("commits") - assert.CurrentViewLines( + assert.CurrentView().Name("commits").Lines( Contains("two"), Contains("one"), Contains("base"), @@ -63,8 +60,7 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ input.Press(keys.Commits.PasteCommits) input.Alert(Equals("Cherry-Pick"), Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")) - assert.CurrentViewName("commits") - assert.CurrentViewLines( + assert.CurrentView().Name("commits").Lines( Contains("four"), Contains("three"), Contains("two"), @@ -72,8 +68,8 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ Contains("base"), ) - assert.ViewContent("information", Contains("2 commits copied")) + assert.View("information").Content(Contains("2 commits copied")) input.Press(keys.Universal.Return) - assert.ViewContent("information", NotContains("commits copied")) + assert.View("information").Content(NotContains("commits copied")) }, }) diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go index 4095a563f..3dfb995e2 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_conflicts.go @@ -16,9 +16,7 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { input.SwitchToBranchesWindow() - assert.CurrentViewName("localBranches") - - assert.CurrentViewLines( + assert.CurrentView().Name("localBranches").Lines( Contains("first-change-branch"), Contains("second-change-branch"), Contains("original-branch"), @@ -28,24 +26,21 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ input.Enter() - assert.CurrentViewName("subCommits") - - assert.CurrentViewTopLines( + assert.CurrentView().Name("subCommits").TopLines( Contains("second-change-branch unrelated change"), Contains("second change"), ) input.Press(keys.Commits.CherryPickCopy) - assert.ViewContent("information", Contains("1 commit copied")) + assert.View("information").Content(Contains("1 commit copied")) input.NextItem() input.Press(keys.Commits.CherryPickCopy) - assert.ViewContent("information", Contains("2 commits copied")) + assert.View("information").Content(Contains("2 commits copied")) input.SwitchToCommitsWindow() - assert.CurrentViewName("commits") - assert.CurrentViewTopLines( + assert.CurrentView().Name("commits").TopLines( Contains("first change"), ) @@ -54,27 +49,26 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ input.AcceptConfirmation(Equals("Auto-merge failed"), Contains("Conflicts!")) - assert.CurrentViewName("files") - assert.CurrentLine(Contains("file")) + assert.CurrentView().Name("files") + assert.CurrentView().SelectedLine(Contains("file")) // not using Confirm() convenience method because I suspect we might change this // keybinding to something more bespoke input.Press(keys.Universal.Confirm) - assert.CurrentViewName("mergeConflicts") + assert.CurrentView().Name("mergeConflicts") // picking 'Second change' input.NextItem() input.PrimaryAction() input.AcceptConfirmation(Equals("continue"), Contains("all merge conflicts resolved. Continue?")) - assert.CurrentViewName("files") + assert.CurrentView().Name("files") assert.WorkingTreeFileCount(0) input.SwitchToCommitsWindow() - assert.CurrentViewName("commits") - assert.CurrentViewTopLines( + assert.CurrentView().Name("commits").TopLines( Contains("second-change-branch unrelated change"), Contains("second change"), Contains("first change"), @@ -83,11 +77,12 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{ // because we picked 'Second change' when resolving the conflict, // we now see this commit as having replaced First Change with Second Change, // as opposed to replacing 'Original' with 'Second change' - assert.MainViewContent(Contains("-First Change")) - assert.MainViewContent(Contains("+Second Change")) + assert.MainView(). + Content(Contains("-First Change")). + Content(Contains("+Second Change")) - assert.ViewContent("information", Contains("2 commits copied")) + assert.View("information").Content(Contains("2 commits copied")) input.Press(keys.Universal.Return) - assert.ViewContent("information", NotContains("commits copied")) + assert.View("information").Content(NotContains("commits copied")) }, }) diff --git a/pkg/integration/tests/commit/commit_multiline.go b/pkg/integration/tests/commit/commit_multiline.go index 51e060ec3..79085926b 100644 --- a/pkg/integration/tests/commit/commit_multiline.go +++ b/pkg/integration/tests/commit/commit_multiline.go @@ -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")) }, }) diff --git a/pkg/integration/tests/commit/new_branch.go b/pkg/integration/tests/commit/new_branch.go index 349fff8ee..55887676b 100644 --- a/pkg/integration/tests/commit/new_branch.go +++ b/pkg/integration/tests/commit/new_branch.go @@ -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"), ) diff --git a/pkg/integration/tests/commit/revert.go b/pkg/integration/tests/commit/revert.go index 448501763..c62124994 100644 --- a/pkg/integration/tests/commit/revert.go +++ b/pkg/integration/tests/commit/revert.go @@ -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") }, }) diff --git a/pkg/integration/tests/commit/staged.go b/pkg/integration/tests/commit/staged.go index b39ab1b38..b018d9dfe 100644 --- a/pkg/integration/tests/commit/staged.go +++ b/pkg/integration/tests/commit/staged.go @@ -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 |