Skip to content

Commit

Permalink
make it all required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidzr committed Aug 20, 2024
1 parent ed3e896 commit 76051ff
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 142 deletions.
132 changes: 24 additions & 108 deletions master/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,12 @@ resource_manager:
}

func TestPickVariation(t *testing.T) {
userConfig := MediaAssetVariations{
LightHorizontal: "light-horizontal",
LightVeritical: "light-vertical",
DarkHorizontal: "dark-horizontal",
DarkVeritical: "dark-vertical",
}
tests := []struct {
name string
variations MediaAssetVariations
Expand All @@ -899,136 +905,46 @@ func TestPickVariation(t *testing.T) {
expected string
}{
{
name: "Light Horizontal prioritized",
variations: MediaAssetVariations{
LightHorizontal: "light-horizontal",
LightVeritical: "light-vertical",
DarkHorizontal: "dark-horizontal",
DarkVeritical: "dark-vertical",
},
name: "Light Horizontal prioritized",
variations: userConfig,
mode: "",
orientation: "",
expected: "light-horizontal",
},
{
name: "Light Vertical when Light Horizontal is empty",
variations: MediaAssetVariations{
LightHorizontal: "",
LightVeritical: "light-vertical",
DarkHorizontal: "dark-horizontal",
DarkVeritical: "dark-vertical",
},
name: "Light Horizontal prioritized",
variations: userConfig,
mode: "",
orientation: "vertical",
expected: "light-vertical",
},
{
name: "Dark Horizontal when mode is dark",
variations: MediaAssetVariations{
LightHorizontal: "light-horizontal",
LightVeritical: "light-vertical",
DarkHorizontal: "dark-horizontal",
DarkVeritical: "dark-vertical",
},
mode: "dark",
orientation: "",
expected: "dark-horizontal",
},
{
name: "Dark Vertical when mode is dark and orientation is vertical",
variations: MediaAssetVariations{
LightHorizontal: "light-horizontal",
LightVeritical: "light-vertical",
DarkHorizontal: "dark-horizontal",
DarkVeritical: "dark-vertical",
},
mode: "dark",
orientation: "vertical",
expected: "dark-vertical",
},
{
name: "Fallback to Light Horizontal if no matches",
variations: MediaAssetVariations{
LightHorizontal: "light-horizontal",
LightVeritical: "",
DarkHorizontal: "",
DarkVeritical: "",
},
mode: "dark",
orientation: "vertical",
orientation: "horizontal",
expected: "light-horizontal",
},
{
name: "Fallback to Light Horizontal if no matches",
variations: MediaAssetVariations{
LightHorizontal: "",
LightVeritical: "light-vertical",
DarkHorizontal: "",
DarkVeritical: "",
},
name: "Light Horizontal prioritized",
variations: userConfig,
mode: "",
orientation: "",
orientation: "vertical",
expected: "light-vertical",
},
{
name: "Fallback to Light Horizontal if no matches",
variations: MediaAssetVariations{
LightHorizontal: "",
LightVeritical: "light-vertical",
DarkHorizontal: "",
DarkVeritical: "",
},
name: "Light Horizontal prioritized",
variations: userConfig,
mode: "light",
orientation: "",
expected: "light-vertical",
expected: "light-horizontal",
},
{
name: "Fallback to Light Horizontal if no matches",
variations: MediaAssetVariations{
LightHorizontal: "",
LightVeritical: "light-vertical",
DarkHorizontal: "",
DarkVeritical: "",
},
name: "Light Horizontal prioritized",
variations: userConfig,
mode: "dark",
orientation: "",
expected: "light-vertical",
expected: "dark-horizontal",
},
{
name: "Fallback to Light Horizontal if no matches",
variations: MediaAssetVariations{
LightHorizontal: "",
LightVeritical: "light-vertical",
DarkHorizontal: "",
DarkVeritical: "",
},
mode: "light",
name: "Light Horizontal prioritized",
variations: userConfig,
mode: "dark",
orientation: "vertical",
expected: "light-vertical",
},
{
name: "Fallback to Light Horizontal if no matches",
variations: MediaAssetVariations{
LightHorizontal: "",
LightVeritical: "light-vertical",
DarkHorizontal: "",
DarkVeritical: "",
},
mode: "light",
orientation: "",
expected: "light-vertical",
},
{
name: "Empty variations fallback to empty string",
variations: MediaAssetVariations{
LightHorizontal: "",
LightVeritical: "",
DarkHorizontal: "",
DarkVeritical: "",
},
mode: "",
orientation: "",
expected: "",
expected: "dark-vertical",
},
}

Expand Down
53 changes: 19 additions & 34 deletions master/internal/config/ui_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,36 @@ func (m MediaAssetVariations) PickVariation(mode, orientation string) string {
orientationHorizontal = "horizontal"
orientationVertical = "vertical"
)
if mode == "" || mode == "light" {
if orientation == "" || orientation == orientationHorizontal {
if m.LightHorizontal != "" {
return m.LightHorizontal
}
switch mode {
case "dark":
switch orientation {
case orientationVertical:
return m.DarkVeritical
default:
return m.DarkHorizontal
}
if orientation == "" || orientation == orientationVertical {
if m.LightVeritical != "" {
return m.LightVeritical
}
if m.LightHorizontal != "" {
return m.LightHorizontal
}
default:
switch orientation {
case orientationVertical:
return m.LightVeritical
default:
return m.LightHorizontal
}
}

if mode == "dark" {
if orientation == "" || orientation == orientationHorizontal {
if m.DarkHorizontal != "" {
return m.DarkHorizontal
}
}
if orientation == "" || orientation == orientationVertical {
if m.DarkVeritical != "" {
return m.DarkVeritical
}
if m.DarkHorizontal != "" {
return m.DarkHorizontal
}
}
}

return m.LightHorizontal
}

// UICustomizationConfig holds the configuration for customizing the UI.
type UICustomizationConfig struct {
// LogoPath is the path to variation of custom logo to use in the web UI.
LogoPath MediaAssetVariations `json:"logo_path"`
LogoPath *MediaAssetVariations `json:"logo_path"`
}

// Validate checks if the paths in UICustomizationConfig are valid filesystem paths and reachable.
func (u UICustomizationConfig) Validate() []error {
var errs []error
if u.LogoPath == nil {
return errs
}

paths := map[string]string{
"LightHorizontal": u.LogoPath.LightHorizontal,
Expand All @@ -76,6 +62,7 @@ func (u UICustomizationConfig) Validate() []error {

for name, path := range paths {
if path == "" {
errs = append(errs, errors.New(name+" path is not set"))
continue
}
license.RequireLicense("UI Customization")
Expand All @@ -95,7 +82,5 @@ func (u UICustomizationConfig) Validate() []error {

// HasCustomLogo returns whether the UI customization has a custom logo.
func (u UICustomizationConfig) HasCustomLogo() bool {
// If one exists, we're good
return u.LogoPath.LightHorizontal != "" || u.LogoPath.LightVeritical != "" ||
u.LogoPath.DarkHorizontal != "" || u.LogoPath.DarkVeritical != ""
return u.LogoPath != nil
}

0 comments on commit 76051ff

Please sign in to comment.