Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/presentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Welcome
image_backend: docs
style:
border: hidden
theme: dark
---

![img|43x10](kyma_logo.png)
Expand Down Expand Up @@ -90,6 +91,7 @@ style:
title: Style usage
style:
border: hidden
theme: dracula
transition: swipeLeft
---

Expand All @@ -110,7 +112,8 @@ style:
----
---
title: Config
preset: dark
style:
theme: dracula
---
# Configuration
Expand Down Expand Up @@ -143,6 +146,8 @@ presets:
----
---
title: Global styles
style:
theme: dracula
---

# Global styles
Expand Down Expand Up @@ -175,6 +180,8 @@ presets:
----
---
title: Presets
style:
theme: dracula
---

# Presets
Expand Down Expand Up @@ -207,6 +214,8 @@ presets:
----
---
title: More ways to navigate
style:
theme: dracula
---

# More ways to navigate
Expand All @@ -221,6 +230,8 @@ title: More ways to navigate
title: Achievements
transition: swipeLeft
image_backend: docs
style:
theme: dracula
---

# Achievements
Expand Down
284 changes: 284 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import (
"path/filepath"
"testing"

glamourStyles "github.com/charmbracelet/glamour/styles"
"github.com/charmbracelet/lipgloss"
"github.com/goccy/go-yaml"
"github.com/spf13/viper"

"github.com/museslabs/kyma/internal/tui/transitions"
)

func TestLoad(t *testing.T) {
Expand Down Expand Up @@ -234,3 +239,282 @@ func TestCreateDefaultConfig(t *testing.T) {
)
}
}

func TestPrecedence(t *testing.T) {
tmpDir := t.TempDir()

testConfig := `global:
style:
border: rounded
border_color: "#FF0000"
layout: center
theme: dark
presets:
test:
style:
border: hidden
theme: notty
border_color: "#fff"
layout: center
`
testConfigPath := filepath.Join(tmpDir, "kyma.yaml")
if err := os.WriteFile(testConfigPath, []byte(testConfig), 0644); err != nil {
t.Fatalf("Failed to write test config: %v", err)
}

if err := Load(testConfigPath); err != nil {
t.Fatalf("Load() error = %v", err)
}

tests := []struct {
name string
properties string
want Properties
}{
{
name: "slide properties should override global ones",
properties: `style:
border: hidden
border_color: "#000"
layout: left
theme: dracula`,
want: Properties{
Title: "",
Style: StyleConfig{
Layout: func() *lipgloss.Style {
s := lipgloss.NewStyle().Align(lipgloss.Left, lipgloss.Left)
return &s
}(),
Border: func() *lipgloss.Border {
b := lipgloss.HiddenBorder()
return &b
}(),
BorderColor: "#000",
Theme: &GlamourTheme{
Style: *glamourStyles.DefaultStyles["dracula"],
Name: "dracula",
},
},
Transition: transitions.Get("none", transitions.Fps),
Notes: "",
ImageBackend: "chafa",
},
},
{
name: "border from default styles",
properties: `style:
border_color: "#000"
layout: left
theme: dracula`,
want: Properties{
Title: "",
Style: StyleConfig{
Layout: func() *lipgloss.Style {
s := lipgloss.NewStyle().Align(lipgloss.Left, lipgloss.Left)
return &s
}(),
Border: func() *lipgloss.Border {
b := lipgloss.RoundedBorder()
return &b
}(),
BorderColor: "#000",
Theme: &GlamourTheme{
Style: *glamourStyles.DefaultStyles["dracula"],
Name: "dracula",
},
},
Transition: transitions.Get("none", transitions.Fps),
Notes: "",
ImageBackend: "chafa",
},
},
{
name: "border color from default styles",
properties: `style:
border: hidden
layout: left
theme: dracula`,
want: Properties{
Title: "",
Style: StyleConfig{
Layout: func() *lipgloss.Style {
s := lipgloss.NewStyle().Align(lipgloss.Left, lipgloss.Left)
return &s
}(),
Border: func() *lipgloss.Border {
b := lipgloss.HiddenBorder()
return &b
}(),
BorderColor: "#FF0000",
Theme: &GlamourTheme{
Style: *glamourStyles.DefaultStyles["dracula"],
Name: "dracula",
},
},
Transition: transitions.Get("none", transitions.Fps),
Notes: "",
ImageBackend: "chafa",
},
},
{
name: "layout from default styles",
properties: `style:
border: hidden
border_color: "#000"
theme: dracula`,
want: Properties{
Title: "",
Style: StyleConfig{
Layout: func() *lipgloss.Style {
s := lipgloss.NewStyle().Align(lipgloss.Center, lipgloss.Center)
return &s
}(),
Border: func() *lipgloss.Border {
b := lipgloss.HiddenBorder()
return &b
}(),
BorderColor: "#000",
Theme: &GlamourTheme{
Style: *glamourStyles.DefaultStyles["dracula"],
Name: "dracula",
},
},
Transition: transitions.Get("none", transitions.Fps),
Notes: "",
ImageBackend: "chafa",
},
},
{
name: "theme from default styles",
properties: `style:
border: hidden
border_color: "#000"
layout: left`,
want: Properties{
Title: "",
Style: StyleConfig{
Layout: func() *lipgloss.Style {
s := lipgloss.NewStyle().Align(lipgloss.Left, lipgloss.Left)
return &s
}(),
Border: func() *lipgloss.Border {
b := lipgloss.HiddenBorder()
return &b
}(),
BorderColor: "#000",
Theme: &GlamourTheme{
Style: *glamourStyles.DefaultStyles["dark"],
Name: "dark",
},
},
Transition: transitions.Get("none", transitions.Fps),
Notes: "",
ImageBackend: "chafa",
},
},
{
name: "use a preset",
properties: `preset: test`,
want: Properties{
Title: "",
Style: StyleConfig{
Layout: func() *lipgloss.Style {
s := lipgloss.NewStyle().Align(lipgloss.Center, lipgloss.Center)
return &s
}(),
Border: func() *lipgloss.Border {
b := lipgloss.HiddenBorder()
return &b
}(),
BorderColor: "#fff",
Theme: &GlamourTheme{
Style: *glamourStyles.DefaultStyles["notty"],
Name: "notty",
},
},
Transition: transitions.Get("none", transitions.Fps),
Notes: "",
ImageBackend: "chafa",
},
},
{
name: "use a preset and override border",
properties: `preset: test
style:
border: rounded`,
want: Properties{
Title: "",
Style: StyleConfig{
Layout: func() *lipgloss.Style {
s := lipgloss.NewStyle().Align(lipgloss.Center, lipgloss.Center)
return &s
}(),
Border: func() *lipgloss.Border {
b := lipgloss.RoundedBorder()
return &b
}(),
BorderColor: "#fff",
Theme: &GlamourTheme{
Style: *glamourStyles.DefaultStyles["notty"],
Name: "notty",
},
},
Transition: transitions.Get("none", transitions.Fps),
Notes: "",
ImageBackend: "chafa",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var p Properties
if err := yaml.Unmarshal([]byte(tt.properties), &p); err != nil {
t.Fatalf("yaml.Unmarshal() error = %v", err)
}

if p.Title != tt.want.Title {
t.Errorf("p.Title = %s, want = %s", p.Title, tt.want.Title)
}

if p.Transition != tt.want.Transition {
t.Errorf("p.Transition = %s, want = %s", p.Transition, tt.want.Transition)
}

if p.Notes != tt.want.Notes {
t.Errorf("p.Notes = %s, want = %s", p.Notes, tt.want.Notes)
}

if p.ImageBackend != tt.want.ImageBackend {
t.Errorf("p.ImageBackend = %s, want = %s", p.ImageBackend, tt.want.ImageBackend)
}

if p.Style.BorderColor != tt.want.Style.BorderColor {
t.Errorf(
"p.Style.BorderColor = %s, want = %s",
p.Style.BorderColor,
tt.want.Style.BorderColor,
)
}

if *p.Style.Border != *tt.want.Style.Border {
t.Errorf("p.Style.Border = %v, want = %v", p.Style.Border, tt.want.Style.Border)
}

if *p.Style.Theme != *tt.want.Style.Theme {
t.Errorf("p.Style.Theme = %v, want = %v", p.Style.Theme, tt.want.Style.Theme)
}

if p.Style.Layout.GetAlignHorizontal() != tt.want.Style.Layout.GetAlignHorizontal() ||
p.Style.Layout.GetAlignVertical() != tt.want.Style.Layout.GetAlignVertical() {
t.Errorf(
"p.Style.Layout = %f, %f, want = %f, %f",
p.Style.Layout.GetAlignHorizontal(),
p.Style.Layout.GetAlignVertical(),
tt.want.Style.Layout.GetAlignHorizontal(),
tt.want.Style.Layout.GetAlignVertical(),
)
}
})
}
}
Loading