Skip to content

Commit

Permalink
Add integration test for local branch sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
hosaka authored and stefanhaller committed Dec 27, 2023
1 parent 36a29f2 commit 21334fa
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
68 changes: 68 additions & 0 deletions pkg/integration/tests/branch/sort_local_branches.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package branch

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var SortLocalBranches = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Sort local branches by recency, date or alphabetically",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
EmptyCommit("commit").
NewBranch("first").
EmptyCommitWithDate("commit", "2023-04-07 10:00:00").
NewBranch("second").
EmptyCommitWithDate("commit", "2023-04-07 12:00:00").
NewBranch("third").
EmptyCommitWithDate("commit", "2023-04-07 11:00:00").
Checkout("master")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
// sorted by recency by default
t.Views().Branches().
Focus().
Lines(
Contains("master").IsSelected(),
Contains("third"),
Contains("second"),
Contains("first"),
).
SelectNextItem() // to test that the selection jumps back to the top when sorting

t.Views().Branches().
Press(keys.Branches.SortOrder)

t.ExpectPopup().Menu().Title(Equals("Sort order")).
Select(Contains("-committerdate")).
Confirm()

t.Views().Branches().
IsFocused().
Lines(
Contains("master").IsSelected(),
Contains("second"),
Contains("third"),
Contains("first"),
)

t.Views().Branches().
Press(keys.Branches.SortOrder)

t.ExpectPopup().Menu().Title(Equals("Sort order")).
Select(Contains("refname")).
Confirm()

t.Views().Branches().
IsFocused().
Lines(
Contains("master").IsSelected(),
Contains("first"),
Contains("second"),
Contains("third"),
)
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var tests = []*components.IntegrationTest{
branch.ResetToUpstream,
branch.SetUpstream,
branch.ShowDivergenceFromUpstream,
branch.SortLocalBranches,
branch.SortRemoteBranches,
branch.Suggestions,
branch.UnsetUpstream,
Expand Down

0 comments on commit 21334fa

Please sign in to comment.