mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-26 17:30:27 -04:00
Demonstrate that the reflog's date column is as wide as the visible lines need
The reflog panel renders only the lines that are on screen too, so the expanded panel's date column is only as wide as gui.shortTimeFormat while nothing but entries from today is visible, and the message of every entry jumps to the left. A reflog reaches back in time, so scrolling crosses that boundary soon enough. GetReflogCommitListDisplayStrings had no tests at all, so cover the two shapes it can return along the way. This file is deliberately left un-gofumpt'd: gofumpt indents the body of the commented-out block by a tab, which would fill the diff of the commit that swaps the two blocks with whitespace-only changes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0720a05ae4
commit
7cf7b51467
@@ -0,0 +1,121 @@
|
||||
package presentation
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/jesseduffield/generics/set"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/samber/lo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/xo/terminfo"
|
||||
)
|
||||
|
||||
func TestGetReflogCommitListDisplayStrings(t *testing.T) {
|
||||
scenarios := []struct {
|
||||
testName string
|
||||
commitOpts []models.NewCommitOpts
|
||||
fullDescription bool
|
||||
timeFormat string
|
||||
shortTimeFormat string
|
||||
now time.Time
|
||||
startIdx int
|
||||
endIdx int
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
testName: "no commits",
|
||||
commitOpts: []models.NewCommitOpts{},
|
||||
startIdx: 0,
|
||||
endIdx: 1,
|
||||
now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC),
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
testName: "some commits",
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "checkout: moving from master to mybranch", Hash: "hash1"},
|
||||
{Name: "commit: make a change", Hash: "hash2"},
|
||||
},
|
||||
startIdx: 0,
|
||||
endIdx: 2,
|
||||
now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
hash1 checkout: moving from master to mybranch
|
||||
hash2 commit: make a change
|
||||
`),
|
||||
},
|
||||
{
|
||||
testName: "full description",
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit: today", Hash: "hash1", UnixTimestamp: 1577844184},
|
||||
{Name: "commit: a while ago", Hash: "hash2", UnixTimestamp: 1576844184},
|
||||
},
|
||||
fullDescription: true,
|
||||
timeFormat: "2006-01-02",
|
||||
shortTimeFormat: "3:04PM",
|
||||
startIdx: 0,
|
||||
endIdx: 2,
|
||||
now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
hash1 2:03AM commit: today
|
||||
hash2 2019-12-20 commit: a while ago
|
||||
`),
|
||||
},
|
||||
{
|
||||
testName: "only showing commits from today",
|
||||
commitOpts: []models.NewCommitOpts{
|
||||
{Name: "commit: today", Hash: "hash1", UnixTimestamp: 1577844184},
|
||||
{Name: "commit: a while ago", Hash: "hash2", UnixTimestamp: 1576844184},
|
||||
},
|
||||
fullDescription: true,
|
||||
timeFormat: "2006-01-02",
|
||||
shortTimeFormat: "3:04PM",
|
||||
startIdx: 0,
|
||||
endIdx: 1,
|
||||
now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC),
|
||||
/* EXPECTED:
|
||||
expected: formatExpected(`
|
||||
hash1 2:03AM commit: today
|
||||
`),
|
||||
ACTUAL: */
|
||||
expected: formatExpected(`
|
||||
hash1 2:03AM commit: today
|
||||
`),
|
||||
},
|
||||
}
|
||||
|
||||
oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelNone)
|
||||
defer color.ForceSetColorLevel(oldColorLevel)
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
hashPool := &utils.StringPool{}
|
||||
|
||||
commits := lo.Map(s.commitOpts,
|
||||
func(opts models.NewCommitOpts, _ int) *models.Commit { return models.NewCommit(hashPool, opts) })
|
||||
|
||||
result := GetReflogCommitListDisplayStrings(
|
||||
commits,
|
||||
s.startIdx,
|
||||
s.endIdx,
|
||||
s.fullDescription,
|
||||
set.New[string](),
|
||||
"",
|
||||
s.now,
|
||||
s.timeFormat,
|
||||
s.shortTimeFormat,
|
||||
false,
|
||||
)
|
||||
|
||||
renderedLines, _ := utils.RenderDisplayStrings(result, nil)
|
||||
renderedResult := strings.Join(renderedLines, "\n")
|
||||
t.Logf("\n%s", renderedResult)
|
||||
|
||||
assert.EqualValues(t, s.expected, renderedResult)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user