From 05e6afdb8e51f67096ff428c34cdb5622cb6f1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20Pr=C3=BCtz?= Date: Sat, 8 Jun 2024 16:19:48 +0200 Subject: [PATCH 1/8] [test] fix order of theme color definitions --- test/theme.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/theme.go b/test/theme.go index c00c2a5e99..d3350d0c68 100644 --- a/test/theme.go +++ b/test/theme.go @@ -34,8 +34,8 @@ func NewTheme() fyne.Theme { theme.ColorNameError: blue(255), theme.ColorNameFocus: red(66), theme.ColorNameForeground: gray(255), - theme.ColorNameHover: green(200), theme.ColorNameHeaderBackground: red(22), + theme.ColorNameHover: green(200), theme.ColorNameInputBackground: red(30), theme.ColorNameInputBorder: gray(10), theme.ColorNameMenuBackground: red(50), @@ -45,8 +45,8 @@ func NewTheme() fyne.Theme { theme.ColorNamePressed: blue(250), theme.ColorNamePrimary: green(255), theme.ColorNameScrollBar: blue(220), - theme.ColorNameSeparator: gray(30), theme.ColorNameSelection: red(55), + theme.ColorNameSeparator: gray(30), theme.ColorNameShadow: blue(150), }, fonts: map[fyne.TextStyle]fyne.Resource{ @@ -89,8 +89,8 @@ func Theme() fyne.Theme { theme.ColorNameError: color.NRGBA{R: 0xf4, G: 0x43, B: 0x36, A: 0xff}, theme.ColorNameFocus: color.NRGBA{R: 0x78, G: 0x3a, B: 0x3a, A: 0xff}, theme.ColorNameForeground: color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, - theme.ColorNameHover: color.NRGBA{R: 0x88, G: 0xff, B: 0xff, A: 0x22}, theme.ColorNameHeaderBackground: color.NRGBA{R: 0x25, G: 0x25, B: 0x25, A: 0xff}, + theme.ColorNameHover: color.NRGBA{R: 0x88, G: 0xff, B: 0xff, A: 0x22}, theme.ColorNameHyperlink: color.NRGBA{R: 0xff, G: 0xcc, B: 0x80, A: 0xff}, theme.ColorNameInputBackground: color.NRGBA{R: 0x66, G: 0x66, B: 0x66, A: 0xff}, theme.ColorNameInputBorder: color.NRGBA{R: 0x86, G: 0x86, B: 0x86, A: 0xff}, @@ -101,8 +101,8 @@ func Theme() fyne.Theme { theme.ColorNamePressed: color.NRGBA{R: 0x00, G: 0x00, B: 0x00, A: 0x33}, theme.ColorNamePrimary: color.NRGBA{R: 0xff, G: 0xc0, B: 0x80, A: 0xff}, theme.ColorNameScrollBar: color.NRGBA{R: 0x00, G: 0x00, B: 0x00, A: 0xaa}, - theme.ColorNameSeparator: color.NRGBA{R: 0x90, G: 0x90, B: 0x90, A: 0xff}, theme.ColorNameSelection: color.NRGBA{R: 0x78, G: 0x3a, B: 0x3a, A: 0x99}, + theme.ColorNameSeparator: color.NRGBA{R: 0x90, G: 0x90, B: 0x90, A: 0xff}, theme.ColorNameShadow: color.NRGBA{R: 0x00, G: 0x00, B: 0x00, A: 0x88}, }, fonts: map[fyne.TextStyle]fyne.Resource{ From d10b6c33c73f75962b2727965acd124d808f4b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20Pr=C3=BCtz?= Date: Sat, 8 Jun 2024 17:55:33 +0200 Subject: [PATCH 2/8] [test] refactor test theme tests to use a suite --- test/theme_test.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/test/theme_test.go b/test/theme_test.go index ea9620a5c3..ab2783a2a1 100644 --- a/test/theme_test.go +++ b/test/theme_test.go @@ -5,23 +5,31 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" "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_NewTheme(t *testing.T) { + suite.Run(t, &configurableThemeTestSuite{constructor: func() *configurableTheme { + return NewTheme().(*configurableTheme) + }}) +} + +func Test_Theme(t *testing.T) { + suite.Run(t, &configurableThemeTestSuite{constructor: func() *configurableTheme { + return Theme().(*configurableTheme) + }}) +} + +type configurableThemeTestSuite struct { + suite.Suite + constructor func() *configurableTheme } -func Test_Theme_checkForUniqueColors(t *testing.T) { - th := Theme().(*configurableTheme) +func (s *configurableThemeTestSuite) TestUniqueColorValues() { + t := s.T() + th := s.constructor() seen := map[string]fyne.ThemeColorName{} for cn, c := range th.colors { r, g, b, a := c.RGBA() From 29a74fdf30cff92c07d909cdf2e0b7f355f06fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20Pr=C3=BCtz?= Date: Sat, 8 Jun 2024 17:59:40 +0200 Subject: [PATCH 3/8] [test] add test for completeness of color definition in test themes This also adds the missing color definitions. --- test/theme.go | 5 +++++ test/theme_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/test/theme.go b/test/theme.go index d3350d0c68..d02a7158c0 100644 --- a/test/theme.go +++ b/test/theme.go @@ -36,6 +36,7 @@ func NewTheme() fyne.Theme { theme.ColorNameForeground: gray(255), theme.ColorNameHeaderBackground: red(22), theme.ColorNameHover: green(200), + theme.ColorNameHyperlink: blue(240), theme.ColorNameInputBackground: red(30), theme.ColorNameInputBorder: gray(10), theme.ColorNameMenuBackground: red(50), @@ -48,6 +49,8 @@ func NewTheme() fyne.Theme { theme.ColorNameSelection: red(55), theme.ColorNameSeparator: gray(30), theme.ColorNameShadow: blue(150), + theme.ColorNameSuccess: green(150), + theme.ColorNameWarning: red(100), }, fonts: map[fyne.TextStyle]fyne.Resource{ {}: theme.DefaultTextBoldFont(), @@ -104,6 +107,8 @@ func Theme() fyne.Theme { theme.ColorNameSelection: color.NRGBA{R: 0x78, G: 0x3a, B: 0x3a, A: 0x99}, theme.ColorNameSeparator: color.NRGBA{R: 0x90, G: 0x90, B: 0x90, A: 0xff}, theme.ColorNameShadow: color.NRGBA{R: 0x00, G: 0x00, B: 0x00, A: 0x88}, + theme.ColorNameSuccess: color.NRGBA{R: 0x00, G: 0x99, B: 0x00, A: 0xff}, + theme.ColorNameWarning: color.NRGBA{R: 0xee, G: 0xee, B: 0x00, A: 0xff}, }, fonts: map[fyne.TextStyle]fyne.Resource{ {}: theme.DefaultTextFont(), diff --git a/test/theme_test.go b/test/theme_test.go index ab2783a2a1..bc78ccd4b3 100644 --- a/test/theme_test.go +++ b/test/theme_test.go @@ -8,8 +8,37 @@ import ( "github.com/stretchr/testify/suite" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/theme" ) +// Try to keep these in sync with the existing color names at theme/colors.go. +var knownColorNames = []fyne.ThemeColorName{ + theme.ColorNameBackground, + theme.ColorNameButton, + theme.ColorNameDisabledButton, + theme.ColorNameDisabled, + theme.ColorNameError, + theme.ColorNameFocus, + theme.ColorNameForeground, + theme.ColorNameHeaderBackground, + theme.ColorNameHover, + theme.ColorNameHyperlink, + theme.ColorNameInputBackground, + theme.ColorNameInputBorder, + theme.ColorNameMenuBackground, + theme.ColorNameOnPrimary, + theme.ColorNameOverlayBackground, + theme.ColorNamePlaceHolder, + theme.ColorNamePressed, + theme.ColorNamePrimary, + theme.ColorNameScrollBar, + theme.ColorNameSelection, + theme.ColorNameSeparator, + theme.ColorNameShadow, + theme.ColorNameSuccess, + theme.ColorNameWarning, +} + func Test_NewTheme(t *testing.T) { suite.Run(t, &configurableThemeTestSuite{constructor: func() *configurableTheme { return NewTheme().(*configurableTheme) @@ -27,6 +56,14 @@ type configurableThemeTestSuite struct { constructor func() *configurableTheme } +func (s *configurableThemeTestSuite) TestAllColorsDefined() { + t := s.T() + th := s.constructor() + for _, cn := range knownColorNames { + assert.NotNil(t, th.Color(cn, theme.VariantDark), "undefined color %s in theme %s", cn, th.name) + } +} + func (s *configurableThemeTestSuite) TestUniqueColorValues() { t := s.T() th := s.constructor() From e9857e2b44d4f99bef39dfb7b465096bad0805e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20Pr=C3=BCtz?= Date: Sat, 8 Jun 2024 18:14:30 +0200 Subject: [PATCH 4/8] [test] make theme test independent from internal implementation --- test/theme_test.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/theme_test.go b/test/theme_test.go index bc78ccd4b3..0a9f877575 100644 --- a/test/theme_test.go +++ b/test/theme_test.go @@ -40,27 +40,30 @@ var knownColorNames = []fyne.ThemeColorName{ } func Test_NewTheme(t *testing.T) { - suite.Run(t, &configurableThemeTestSuite{constructor: func() *configurableTheme { - return NewTheme().(*configurableTheme) - }}) + suite.Run(t, &configurableThemeTestSuite{ + constructor: NewTheme, + name: "Ugly Test Theme", + }) } func Test_Theme(t *testing.T) { - suite.Run(t, &configurableThemeTestSuite{constructor: func() *configurableTheme { - return Theme().(*configurableTheme) - }}) + suite.Run(t, &configurableThemeTestSuite{ + constructor: Theme, + name: "Default Test Theme", + }) } type configurableThemeTestSuite struct { suite.Suite - constructor func() *configurableTheme + constructor func() fyne.Theme + name string } func (s *configurableThemeTestSuite) TestAllColorsDefined() { t := s.T() th := s.constructor() for _, cn := range knownColorNames { - assert.NotNil(t, th.Color(cn, theme.VariantDark), "undefined color %s in theme %s", cn, th.name) + assert.NotNil(t, th.Color(cn, theme.VariantDark), "undefined color %s in theme %s", cn, s.name) } } @@ -68,10 +71,11 @@ func (s *configurableThemeTestSuite) TestUniqueColorValues() { t := s.T() th := s.constructor() seen := map[string]fyne.ThemeColorName{} - for cn, c := range th.colors { + for _, cn := range knownColorNames { + c := th.Color(cn, theme.VariantDark) 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) + assert.True(t, seen[key] == "", "color value %#v for color %s already used for color %s in theme %s", c, cn, seen[key], s.name) seen[key] = cn } } From 4d089dad043ab0daa99ccd6b1923083ab165a6f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20Pr=C3=BCtz?= Date: Sat, 8 Jun 2024 18:20:11 +0200 Subject: [PATCH 5/8] [test] test theme colors for all known variants --- test/theme_test.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/test/theme_test.go b/test/theme_test.go index 0a9f877575..bf753ff175 100644 --- a/test/theme_test.go +++ b/test/theme_test.go @@ -39,6 +39,12 @@ var knownColorNames = []fyne.ThemeColorName{ theme.ColorNameWarning, } +// Try to keep this in sync with the existing variants at theme/theme.go +var knownVariants = []fyne.ThemeVariant{ + theme.VariantDark, + theme.VariantLight, +} + func Test_NewTheme(t *testing.T) { suite.Run(t, &configurableThemeTestSuite{ constructor: NewTheme, @@ -62,20 +68,29 @@ type configurableThemeTestSuite struct { func (s *configurableThemeTestSuite) TestAllColorsDefined() { t := s.T() th := s.constructor() - for _, cn := range knownColorNames { - assert.NotNil(t, th.Color(cn, theme.VariantDark), "undefined color %s in theme %s", cn, s.name) + for _, variant := range knownVariants { + for _, cn := range knownColorNames { + assert.NotNil(t, th.Color(cn, variant), "undefined color %s variant %d in theme %s", cn, variant, s.name) + } } } func (s *configurableThemeTestSuite) TestUniqueColorValues() { t := s.T() th := s.constructor() - seen := map[string]fyne.ThemeColorName{} - for _, cn := range knownColorNames { - c := th.Color(cn, theme.VariantDark) - 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], s.name) - seen[key] = cn + seenByVariant := map[fyne.ThemeVariant]map[string]fyne.ThemeColorName{} + for _, variant := range knownVariants { + seen := seenByVariant[variant] + if seen == nil { + seen = map[string]fyne.ThemeColorName{} + seenByVariant[variant] = seen + } + for _, cn := range knownColorNames { + c := th.Color(cn, theme.VariantDark) + 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 variant %d already used for color %s in theme %s", c, cn, variant, seen[key], s.name) + seen[key] = cn + } } } From 762e2bc12b8dfbcfe8386bef5dc650742944ffdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20Pr=C3=BCtz?= Date: Sat, 8 Jun 2024 18:41:47 +0200 Subject: [PATCH 6/8] [test] add test for known colors in markup renderer This adds the missing color names to the detection. --- test/markup_renderer.go | 4 ++++ test/markup_renderer_test.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/test/markup_renderer.go b/test/markup_renderer.go index ff37b46eee..81d1b42f40 100644 --- a/test/markup_renderer.go +++ b/test/markup_renderer.go @@ -406,17 +406,21 @@ func knownColor(c color.Color) string { nrgbaColor(theme.ForegroundColor()): "foreground", nrgbaColor(theme.Color(theme.ColorNameHeaderBackground)): "headerBackground", nrgbaColor(theme.HoverColor()): "hover", + nrgbaColor(theme.Color(theme.ColorNameHyperlink)): "hyperlink", nrgbaColor(theme.InputBackgroundColor()): "inputBackground", nrgbaColor(theme.InputBorderColor()): "inputBorder", nrgbaColor(theme.MenuBackgroundColor()): "menuBackground", nrgbaColor(theme.Color(theme.ColorNameOnPrimary)): "onPrimary", nrgbaColor(theme.OverlayBackgroundColor()): "overlayBackground", nrgbaColor(theme.PlaceHolderColor()): "placeholder", + nrgbaColor(theme.Color(theme.ColorNamePressed)): "pressed", nrgbaColor(theme.PrimaryColor()): "primary", nrgbaColor(theme.ScrollBarColor()): "scrollbar", nrgbaColor(theme.SelectionColor()): "selection", nrgbaColor(theme.Color(theme.ColorNameSeparator)): "separator", + nrgbaColor(theme.Color(theme.ColorNameSuccess)): "success", nrgbaColor(theme.ShadowColor()): "shadow", + nrgbaColor(theme.Color(theme.ColorNameWarning)): "warning", }[nrgbaColor(c)] } diff --git a/test/markup_renderer_test.go b/test/markup_renderer_test.go index c28c4f9fad..111b3a36f7 100644 --- a/test/markup_renderer_test.go +++ b/test/markup_renderer_test.go @@ -15,6 +15,12 @@ import ( "fyne.io/fyne/v2/widget" ) +func Test_knownColor(t *testing.T) { + for _, name := range knownColorNames { + assert.NotEmpty(t, knownColor(theme.Color(name)), "color name %s is not known", name) + } +} + func Test_snapshot(t *testing.T) { // content elements for name, tt := range map[string]struct { From ee7cd3966cf7c549ba32213220355687dc92e087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20Pr=C3=BCtz?= Date: Sun, 9 Jun 2024 16:25:50 +0200 Subject: [PATCH 7/8] fix file name in comment --- test/theme_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/theme_test.go b/test/theme_test.go index bf753ff175..603eece7ce 100644 --- a/test/theme_test.go +++ b/test/theme_test.go @@ -11,7 +11,7 @@ import ( "fyne.io/fyne/v2/theme" ) -// Try to keep these in sync with the existing color names at theme/colors.go. +// Try to keep these in sync with the existing color names at theme/color.go. var knownColorNames = []fyne.ThemeColorName{ theme.ColorNameBackground, theme.ColorNameButton, From 40aaa22c7d13f9983a36e04858852bd704014014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tilo=20Pr=C3=BCtz?= Date: Sun, 9 Jun 2024 16:25:01 +0200 Subject: [PATCH 8/8] add comments as reference to test lists of colors and variants --- theme/color.go | 1 + theme/theme.go | 1 + 2 files changed, 2 insertions(+) diff --git a/theme/color.go b/theme/color.go index a58abf0c49..f192c161b0 100644 --- a/theme/color.go +++ b/theme/color.go @@ -6,6 +6,7 @@ import ( "fyne.io/fyne/v2" ) +// Keep in mind to add new constants to the tests at test/theme_test.go. const ( // ColorRed is the red primary color name. // diff --git a/theme/theme.go b/theme/theme.go index 424746c3d6..b325a5cb1f 100644 --- a/theme/theme.go +++ b/theme/theme.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/v2/internal/cache" ) +// Keep in mind to add new constants to the tests at test/theme_test.go. const ( // VariantDark is the version of a theme that satisfies a user preference for a dark look. //