test(gallery): 断言插件样式生效(图标无框无底色、工具组横排)
This commit is contained in:
1 parent
a4aaa547a7
commit
23f82dc728
1 file changed
+10
@@ -11,6 +11,8 @@ const vm = require('vm')
|
||||
const { JSDOM } = require('jsdom')
|
||||
|
||||
const src = fs.readFileSync(path.resolve(__dirname, '..', '..', 'iwb-plugins-desktop', 'gallery', 'src', 'index.js'), 'utf8')
|
||||
// 插件自带样式:图标按钮无外框、工具组横排,靠这份 CSS 保证(不依赖客户端 style.css)
|
||||
const pluginCss = fs.readFileSync(path.resolve(__dirname, '..', '..', 'iwb-plugins-desktop', 'gallery', 'styles.css'), 'utf8')
|
||||
|
||||
const wait = (ms) => new Promise((r) => setTimeout(r, ms))
|
||||
|
||||
@@ -43,6 +45,10 @@ async function boot ({ items, thumb, clock }) {
|
||||
remove: async () => ({ ok: true }),
|
||||
},
|
||||
}
|
||||
const styleTag = window.document.createElement('style')
|
||||
styleTag.textContent = pluginCss
|
||||
window.document.head.appendChild(styleTag)
|
||||
|
||||
registered[0].factory(ctx)
|
||||
const node = window.document.getElementById('host')
|
||||
mounted(node)
|
||||
@@ -94,6 +100,7 @@ async function boot ({ items, thumb, clock }) {
|
||||
|
||||
// 底部「刷新」按钮:随时强制重拉
|
||||
const tools = env.node.querySelector('.iwb-gal-tools')
|
||||
assert.strictEqual(env.window.getComputedStyle(tools).display, 'flex', '工具组应为横排 flex(否则图标会竖排)')
|
||||
assert.ok(tools, '底栏应有右侧工具组')
|
||||
const footBtns = Array.from(tools.querySelectorAll('button'))
|
||||
assert.strictEqual(footBtns.length, 2, '工具组应为刷新+设置两个图标,实际 ' + footBtns.length)
|
||||
@@ -104,6 +111,9 @@ async function boot ({ items, thumb, clock }) {
|
||||
// 图标按钮:不显示文字,只有 svg
|
||||
assert.strictEqual(btn.textContent.trim(), '', '刷新按钮不应再显示文字(窄栏会被挤成竖排)')
|
||||
assert.ok(btn.querySelector('svg'), '刷新按钮应有 svg 图标')
|
||||
const cs = env.window.getComputedStyle(btn)
|
||||
assert.strictEqual(cs.borderTopWidth, '0px', '图标按钮不应有外框(实际 ' + cs.borderTopWidth + ')')
|
||||
assert.strictEqual(cs.backgroundColor, 'rgba(0, 0, 0, 0)', '图标按钮不应有底色(实际 ' + cs.backgroundColor + ')')
|
||||
btn.dispatchEvent(new env.window.MouseEvent('click', { bubbles: true }))
|
||||
await wait(60)
|
||||
assert.strictEqual(env.calls.list, 3, '点「刷新」应重拉列表,实际 ' + env.calls.list)
|
||||
|
||||
Reference in new issue
Block a user