diff --git a/pkg/gui/presentation/authors/authors_test.go b/pkg/gui/presentation/authors/authors_test.go index d7c651031..d01fddbf4 100644 --- a/pkg/gui/presentation/authors/authors_test.go +++ b/pkg/gui/presentation/authors/authors_test.go @@ -3,8 +3,11 @@ package authors import ( "testing" + "github.com/gookit/color" + "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/stretchr/testify/assert" + "github.com/xo/terminfo" ) func TestGetInitials(t *testing.T) { @@ -41,3 +44,23 @@ func TestAuthorWithLength(t *testing.T) { assert.Equal(t, s.expectedOutput, utils.Decolorise(AuthorWithLength(s.authorName, s.length))) } } + +func TestAuthorColorsFollowTheConfig(t *testing.T) { + oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions) + defer color.ForceSetColorLevel(oldColorLevel) + t.Cleanup(func() { SetCustomAuthors(nil) }) + + SetCustomAuthors(map[string]string{"Jane Doe": "red"}) + assert.Equal(t, style.FgRed.Sprint("JD"), ShortAuthor("Jane Doe")) + assert.Equal(t, style.FgRed.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8)) + + SetCustomAuthors(map[string]string{"Jane Doe": "blue"}) + /* EXPECTED: + assert.Equal(t, style.FgBlue.Sprint("JD"), ShortAuthor("Jane Doe")) + ACTUAL: */ + assert.Equal(t, style.FgRed.Sprint("JD"), ShortAuthor("Jane Doe")) + /* EXPECTED: + assert.Equal(t, style.FgBlue.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8)) + ACTUAL: */ + assert.Equal(t, style.FgRed.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8)) +} diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go index 3c3ce0044..8a93faf1a 100644 --- a/pkg/gui/presentation/commits_test.go +++ b/pkg/gui/presentation/commits_test.go @@ -10,6 +10,9 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/common" + "github.com/jesseduffield/lazygit/pkg/gui/presentation/authors" + "github.com/jesseduffield/lazygit/pkg/gui/presentation/graph" + "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" "github.com/stefanhaller/git-todo-parser/todo" @@ -620,3 +623,27 @@ func TestGetCommitListDisplayStrings(t *testing.T) { } } } + +func TestGraphColorsFollowTheAuthorColors(t *testing.T) { + oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions) + defer color.ForceSetColorLevel(oldColorLevel) + t.Cleanup(func() { authors.SetCustomAuthors(nil) }) + + hashPool := &utils.StringPool{} + commits := []*models.Commit{ + models.NewCommit(hashPool, models.NewCommitOpts{Hash: "authorcolors1", AuthorName: "Jane Doe", Parents: []string{"authorcolors2"}}), + models.NewCommit(hashPool, models.NewCommitOpts{Hash: "authorcolors2", AuthorName: "Jane Doe"}), + } + renderGraph := func() string { + return strings.Join(graph.RenderAux(loadPipesets(commits), commits, nil), "\n") + } + + authors.SetCustomAuthors(map[string]string{"Jane Doe": "red"}) + assert.Contains(t, renderGraph(), style.FgRed.Sprint("○")) + + authors.SetCustomAuthors(map[string]string{"Jane Doe": "blue"}) + /* EXPECTED: + assert.Contains(t, renderGraph(), style.FgBlue.Sprint("○")) + ACTUAL: */ + assert.Contains(t, renderGraph(), style.FgRed.Sprint("○")) +}