beef up skin tests

mine
derailed 2019-06-07 23:25:21 -06:00
parent 641058bdac
commit 408bafc197
5 changed files with 99 additions and 48 deletions

View File

@ -223,54 +223,9 @@ func newMenu() *Menu {
}
// NewStyles creates a new default config.
func NewStyles() (*Styles, error) {
func NewStyles(p string) (*Styles, error) {
s := &Styles{Style: newStyle()}
err := s.load(K9sStylesFile)
return s, err
}
// Ensure default styles are applied in not in stylesheet.
func (s *Styles) ensure() {
if s.Style == nil {
s.Style = newStyle()
}
if s.Style.Info == nil {
s.Style.Info = newInfo()
}
if s.Style.Border == nil {
s.Style.Border = newBorder()
}
if s.Style.Table == nil {
s.Style.Table = newTable()
}
if s.Style.Menu == nil {
s.Style.Menu = newMenu()
}
if s.Style.Crumb == nil {
s.Style.Crumb = newCrumb()
}
if s.Style.Status == nil {
s.Style.Status = newStatus()
}
if s.Style.Title == nil {
s.Style.Title = newTitle()
}
if s.Style.Yaml == nil {
s.Style.Yaml = newYaml()
}
if s.Style.Log == nil {
s.Style.Log = newLog()
}
return s, s.load(p)
}
// FgColor returns the foreground color.
@ -298,7 +253,6 @@ func (s *Styles) load(path string) error {
if cfg.Style != nil {
s.Style = cfg.Style
}
s.ensure()
return nil
}

View File

@ -0,0 +1,51 @@
package config
import (
"testing"
"github.com/derailed/tview"
"github.com/gdamore/tcell"
"github.com/stretchr/testify/assert"
)
func TestSkinNone(t *testing.T) {
s, err := NewStyles("test_assets/empty_skin.yml")
assert.Nil(t, err)
s.Update()
assert.Equal(t, "cadetblue", s.Style.FgColor)
assert.Equal(t, "black", s.Style.BgColor)
assert.Equal(t, "black", s.Style.Table.BgColor)
assert.Equal(t, tcell.ColorCadetBlue, s.FgColor())
assert.Equal(t, tcell.ColorBlack, s.BgColor())
assert.Equal(t, tcell.ColorBlack, tview.Styles.PrimitiveBackgroundColor)
assert.Equal(t, tcell.ColorPink, AsColor("blah"))
assert.Equal(t, tcell.ColorWhite, AsColor("white"))
}
func TestSkin(t *testing.T) {
s, err := NewStyles("test_assets/black_and_wtf.yml")
assert.Nil(t, err)
s.Update()
assert.Equal(t, "white", s.Style.FgColor)
assert.Equal(t, "black", s.Style.BgColor)
assert.Equal(t, "black", s.Style.Table.BgColor)
assert.Equal(t, tcell.ColorWhite, s.FgColor())
assert.Equal(t, tcell.ColorBlack, s.BgColor())
assert.Equal(t, tcell.ColorBlack, tview.Styles.PrimitiveBackgroundColor)
assert.Equal(t, tcell.ColorPink, AsColor("blah"))
assert.Equal(t, tcell.ColorWhite, AsColor("white"))
}
func TestSkinNotExits(t *testing.T) {
_, err := NewStyles("test_assets/blee.yml")
assert.NotNil(t, err)
}
func TestSkinBoarked(t *testing.T) {
_, err := NewStyles("test_assets/skin_boarked.yml")
assert.NotNil(t, err)
}

View File

@ -0,0 +1,39 @@
k9s:
fgColor: white
bgColor: black
logoColor: white
info:
fgColor: navajowhite
sectionColor: white
border:
fgColor: white
focusColor: white
menu:
fgColor: white
keyColor: white
numKeyColor: navajowhite
crumb:
fgColor: black
bgColor: navajowhite
activeColor: whitesmoke
table:
fgColor: white
bgColor: black
cursorColor: white
header:
fgColor: darkgray
bgColor: black
sorterColor: white
status:
newColor: ghostwhite
modifyColor: navajowhite
addColor: darkslategray
errorColor: whitesmoke
highlightcolor: dimgray
killColor: slategray
completedColor: gray
title:
fgColor: ghostwhite
highlightColor: navajowhite
counterColor: navajowhite
filterColor: slategray

View File

@ -0,0 +1,7 @@
k9s:
fgColor: blee
bgColor: black
logoColor: white
info:
- fgColor: fred
- sectionColor: white