优化代码
This commit is contained in:
1 parent
3553790475
commit
eda7e8bc96
23 files changed
+3113
-342
No files matched your search
@@ -0,0 +1,79 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"testing"
|
||||
|
||||
"fyne.io/fyne/v2/test"
|
||||
)
|
||||
|
||||
// nrgba 把颜色转成不透明的 NRGBA,便于直接比较。
|
||||
func nrgba(c color.Color) color.NRGBA {
|
||||
return color.NRGBAModel.Convert(c).(color.NRGBA)
|
||||
}
|
||||
|
||||
func TestBubbleColorsFollowTheme(t *testing.T) {
|
||||
test.NewApp()
|
||||
|
||||
applyThemeMode(ThemeContrast)
|
||||
darkBot := nrgba(colorFor(bubbleBot))
|
||||
darkErr := nrgba(colorFor(bubbleError))
|
||||
darkBorder := nrgba(borderFor(bubbleUser))
|
||||
darkStrong := nrgba(borderFor(bubbleError))
|
||||
|
||||
// 黑白主题:气泡底色应贴近纯黑,文字侧仍是纯白前景。
|
||||
if darkBot.R > 0x30 {
|
||||
t.Fatalf("黑白主题下助手气泡应贴近纯黑,实际 %v", darkBot)
|
||||
}
|
||||
if darkStrong.R != 0xFF {
|
||||
t.Fatalf("黑白主题下错误气泡描边应为纯白,实际 %v", darkStrong)
|
||||
}
|
||||
if darkBorder.R >= darkStrong.R {
|
||||
t.Fatalf("错误描边应比普通描边更亮:普通 %v,错误 %v", darkBorder, darkStrong)
|
||||
}
|
||||
|
||||
applyThemeMode(ThemeLight)
|
||||
lightBot := nrgba(colorFor(bubbleBot))
|
||||
lightErr := nrgba(colorFor(bubbleError))
|
||||
lightStrong := nrgba(borderFor(bubbleError))
|
||||
|
||||
if lightBot.R < 0xD0 {
|
||||
t.Fatalf("浅色主题下助手气泡应贴近纯白,实际 %v", lightBot)
|
||||
}
|
||||
if lightStrong.R != 0x00 {
|
||||
t.Fatalf("浅色主题下错误气泡描边应为纯黑,实际 %v", lightStrong)
|
||||
}
|
||||
if lightBot.R == darkBot.R {
|
||||
t.Fatal("切换主题后气泡底色应发生变化")
|
||||
}
|
||||
if lightErr.R == darkErr.R {
|
||||
t.Fatal("切换主题后错误气泡底色应发生变化")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatViewRethemeRepaintsBubbles(t *testing.T) {
|
||||
test.NewApp()
|
||||
applyThemeMode(ThemeContrast)
|
||||
|
||||
c := newChatView()
|
||||
b := newBubble("助手", bubbleBot)
|
||||
c.appendBubble(b)
|
||||
|
||||
before := nrgba(b.bg.FillColor)
|
||||
beforeStroke := nrgba(b.bg.StrokeColor)
|
||||
|
||||
applyThemeMode(ThemeLight)
|
||||
c.retheme()
|
||||
|
||||
after := nrgba(b.bg.FillColor)
|
||||
afterStroke := nrgba(b.bg.StrokeColor)
|
||||
if before == after {
|
||||
t.Fatalf("换肤后气泡底色应改变:%v -> %v", before, after)
|
||||
}
|
||||
if beforeStroke == afterStroke {
|
||||
t.Fatalf("换肤后气泡描边应改变:%v -> %v", beforeStroke, afterStroke)
|
||||
}
|
||||
if after != nrgba(colorFor(bubbleBot)) {
|
||||
t.Fatalf("换肤后底色应与当前主题一致:%v != %v", after, nrgba(colorFor(bubbleBot)))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user