Skip to content

Commit

Permalink
[test] check unique colors for themes via test
Browse files Browse the repository at this point in the history
This avoids the check to be run on every instantiation.
It also revealed that the old check did not work properly and revealed
two duplicates in the ugly theme.
  • Loading branch information
toaster committed Jun 7, 2024
1 parent 548e638 commit f602dac
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 10 deletions.
Binary file modified container/testdata/doctabs/desktop/single_custom_theme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified container/testdata/doctabs/mobile/theme_ugly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 2 additions & 10 deletions test/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func NewTheme() fyne.Theme {
theme.ColorNameHeaderBackground: red(22),
theme.ColorNameInputBackground: red(30),
theme.ColorNameInputBorder: gray(10),
theme.ColorNameMenuBackground: red(30),
theme.ColorNameMenuBackground: red(50),
theme.ColorNameOnPrimary: red(200),
theme.ColorNameOverlayBackground: red(44),
theme.ColorNamePlaceHolder: blue(200),
theme.ColorNamePressed: blue(250),
theme.ColorNamePrimary: green(255),
theme.ColorNameScrollBar: blue(200),
theme.ColorNameScrollBar: blue(220),
theme.ColorNameSeparator: gray(30),
theme.ColorNameSelection: red(55),
theme.ColorNameShadow: blue(150),
Expand Down Expand Up @@ -136,14 +136,6 @@ func Theme() fyne.Theme {
}

func newConfigurableTheme(name string, colors map[fyne.ThemeColorName]color.Color, fonts map[fyne.TextStyle]fyne.Resource, sizes map[fyne.ThemeSizeName]float32) fyne.Theme {
seen := map[color.Color]fyne.ThemeColorName{}
for cn, c := range colors {
if seen[c] != "" {
// This panic will never happen on released code because it will happen on CI runs prior release.
panic(fmt.Sprintf("duplicate color value %#v for color %s already used for color %s in theme %s", c, cn, seen[c], name))
}
seen[c] = cn
}
return &configurableTheme{
colors: colors,
fonts: fonts,
Expand Down
32 changes: 32 additions & 0 deletions test/theme_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package test

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

"fyne.io/fyne/v2"
)

func Test_NewTheme_checkForUniqueColors(t *testing.T) {
th := NewTheme().(*configurableTheme)
seen := map[string]fyne.ThemeColorName{}
for cn, c := range th.colors {
r, g, b, a := c.RGBA()
key := fmt.Sprintf("%d %d %d %d", r, g, b, a)
assert.True(t, seen[key] == "", "color value %#v for color %s already used for color %s in theme %s", c, cn, seen[key], th.name)
seen[key] = cn
}
}

func Test_Theme_checkForUniqueColors(t *testing.T) {
th := Theme().(*configurableTheme)
seen := map[string]fyne.ThemeColorName{}
for cn, c := range th.colors {
r, g, b, a := c.RGBA()
key := fmt.Sprintf("%d %d %d %d", r, g, b, a)
assert.True(t, seen[key] == "", "color value %#v for color %s already used for color %s in theme %s", c, cn, seen[key], th.name)
seen[key] = cn
}
}
Binary file modified widget/testdata/list/list_theme_changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/menu/desktop/layout_theme_changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/menu/mobile/layout_theme_changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/desktop/theme_changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/mobile/theme_changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/table/theme_changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/tree/theme_changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f602dac

Please sign in to comment.