Skip to content

Commit

Permalink
✅ Improve theme tests
Browse files Browse the repository at this point in the history
Themes were only being tested against dark. Switching to adaptive
colours made the default unset mode become light. Add tests to check
adaptive, light and dark.
  • Loading branch information
mikelorant committed Jan 28, 2023
1 parent e72b269 commit fe3e526
Showing 1 changed file with 54 additions and 25 deletions.
79 changes: 54 additions & 25 deletions internal/ui/theme/theme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@ import (

func TestNew(t *testing.T) {
tests := []struct {
name string
ids []string
name string
colour config.Colour
ids []string
}{
{
name: "ids",
name: "adaptive",
colour: config.ColourAdaptive,
ids: []string{
"builtin_dark",
"dracula",
"gruvbox_dark",
"nord",
"retrowave",
"solarized_dark_higher_contrast",
"tokyo_night",
},
},
{
name: "dark",
colour: config.ColourDark,
ids: []string{
"builtin_dark",
"dracula",
Expand All @@ -25,11 +40,22 @@ func TestNew(t *testing.T) {
"tokyo_night",
},
},
{
name: "light",
colour: config.ColourLight,
ids: []string{
"builtin_light",
"builtin_solarized_light",
"builtin_tango_light",
"gruvbox_light",
"tokyo_night_light",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
th := theme.New(config.ColourAdaptive)
th := theme.New(tt.colour)

var ids []string
for i := 0; i < len(th.ListTints()); i++ {
Expand All @@ -49,32 +75,32 @@ func TestNextTint(t *testing.T) {
}{
{
name: "first",
id: "builtin_dark",
id: "builtin_light",
},
{
name: "one",
count: 1,
id: "dracula",
id: "builtin_solarized_light",
},
{
name: "three",
count: 3,
id: "nord",
id: "gruvbox_light",
},
{
name: "last",
count: 6,
id: "tokyo_night",
count: 4,
id: "tokyo_night_light",
},
{
name: "last_plus_one",
count: 7,
id: "builtin_dark",
count: 5,
id: "builtin_light",
},
{
name: "last_plus_two",
count: 8,
id: "dracula",
count: 6,
id: "builtin_solarized_light",
},
}

Expand All @@ -99,13 +125,11 @@ func TestListTints(t *testing.T) {
{
name: "default",
want: []string{
"builtin_dark",
"dracula",
"gruvbox_dark",
"nord",
"retrowave",
"solarized_dark_higher_contrast",
"tokyo_night",
"builtin_light",
"builtin_solarized_light",
"builtin_tango_light",
"gruvbox_light",
"tokyo_night_light",
},
},
}
Expand All @@ -128,13 +152,13 @@ func TestGetTint(t *testing.T) {
}{
{
name: "valid",
id: "builtin_dark",
want: "builtin_dark",
id: "builtin_light",
want: "builtin_light",
},
{
name: "invalid",
id: "invalid",
want: "builtin_dark",
want: "builtin_light",
},
}

Expand Down Expand Up @@ -163,15 +187,18 @@ func TestSetTint(t *testing.T) {
}{
{
name: "valid",
id: "dracula",
id: "builtin_tango_light",
want: want{
id: "dracula",
id: "builtin_tango_light",
ok: true,
},
},
{
name: "invalid",
id: "test",
want: want{
id: "builtin_light",
},
},
}

Expand All @@ -182,6 +209,8 @@ func TestSetTint(t *testing.T) {
ok := th.SetTint(tt.id)
if !tt.want.ok {
assert.False(t, ok)
got := th.GetTint()
assert.Equal(t, tt.want.id, got)
return
}
assert.True(t, ok)
Expand Down

0 comments on commit fe3e526

Please sign in to comment.