feat(short-drama-agent-front): 新增全局主题和左右布局切换
This commit is contained in:
1 parent
db9aea1694
commit
27ee9fd4ff
10 files changed
+709
-41
No files matched your search
@@ -9,7 +9,7 @@ afterEach(() => {
|
||||
scope = undefined
|
||||
localStorage.clear()
|
||||
delete document.documentElement.dataset.theme
|
||||
document.documentElement.style.colorScheme = ''
|
||||
document.documentElement.removeAttribute('style')
|
||||
vi.unstubAllGlobals()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
@@ -152,6 +152,45 @@ describe('微信风格明暗主题', () => {
|
||||
expect(contrast(tokens['accent-text']!, tokens.selected!)).toBeGreaterThanOrEqual(4.5)
|
||||
})
|
||||
|
||||
it('主色同步到 Naive 和业务样式,刷新后与明暗偏好分别恢复', async () => {
|
||||
const state = setup()
|
||||
state.accent.value = 'blue'
|
||||
await nextTick()
|
||||
const root = document.documentElement
|
||||
const blue = state.overrides.value.common!.primaryColor!
|
||||
expect(blue).not.toBe('#07c160')
|
||||
expect(root.style.getPropertyValue('--app-accent')).toBe(blue)
|
||||
expect(root.style.getPropertyValue('--app-button-primary')).toBe(state.overrides.value.Button?.colorPrimary)
|
||||
expect(state.overrides.value.common?.successColor).toBe('#087c42')
|
||||
state.preference.value = 'dark'
|
||||
await nextTick()
|
||||
const darkBlue = state.overrides.value.common!.primaryColor
|
||||
expect(darkBlue).not.toBe(blue)
|
||||
scope!.stop()
|
||||
const restored = setup()
|
||||
expect(restored.accent.value).toBe('blue')
|
||||
expect(restored.isDark.value).toBe(true)
|
||||
expect(restored.overrides.value.common?.primaryColor).toBe(darkBlue)
|
||||
expect(restored.overrides.value.common?.successColor).toBe('#5cd693')
|
||||
restored.accent.value = 'green'
|
||||
await nextTick()
|
||||
expect(root.style.getPropertyValue('--app-accent')).toBe('#07c160')
|
||||
})
|
||||
|
||||
it.each([false, true])('明暗模式 %s 下所有预设的按钮白字和选中文字对比度充足', dark => {
|
||||
const state = setup(dark)
|
||||
for (const accent of ['blue', 'violet', 'pink', 'yellow', 'indigo', 'green', 'zinc'] as const) {
|
||||
state.accent.value = accent
|
||||
const { Button, Menu } = state.overrides.value
|
||||
for (const background of [Button!.colorPrimary, Button!.colorHoverPrimary, Button!.colorPressedPrimary]) {
|
||||
expect(contrast(String(Button!.textColorPrimary), String(background))).toBeGreaterThanOrEqual(4.5)
|
||||
}
|
||||
expect(contrast(String(Menu!.itemTextColorActive), String(Menu!.itemColorActive))).toBeGreaterThanOrEqual(
|
||||
4.5
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('系统切换时浏览器主题色与页面同步', async () => {
|
||||
const meta = document.createElement('meta')
|
||||
meta.name = 'theme-color'
|
||||
|
||||
Reference in new issue
Block a user