72 lines
3.4 KiB
JavaScript
72 lines
3.4 KiB
JavaScript
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
const fs = require('node:fs')
|
|
const path = require('node:path')
|
|
const { parse, compileStyle } = require('@vue/compiler-sfc')
|
|
const { parseDOM } = require('htmlparser2')
|
|
const { compile, selectAll, selectOne } = require('css-select')
|
|
const postcss = require('postcss')
|
|
|
|
const filename = path.resolve(__dirname, '../src/views/fans/yeji.vue')
|
|
const scope = 'data-v-yeji-test'
|
|
const { descriptor, errors } = parse(fs.readFileSync(filename, 'utf8'), { filename })
|
|
assert.deepEqual(errors, [])
|
|
const compiled = descriptor.styles.map(block => {
|
|
const file = block.src ? path.resolve(path.dirname(filename), block.src) : filename
|
|
const source = block.src ? fs.readFileSync(file, 'utf8') : block.content
|
|
const result = compileStyle({ filename: file, source, scoped: block.scoped, id: scope, preprocessLang: block.lang })
|
|
assert.deepEqual(result.errors, [])
|
|
return postcss.parse(result.code)
|
|
})
|
|
|
|
function fixture(mode, dark = false) {
|
|
const dom = parseDOM(`<html data-admin-ui="${mode}" class="${dark ? 'dark' : ''}"><body>${descriptor.template.content}</body></html>`)
|
|
for (const el of selectAll('body *', dom)) el.attribs[scope] = ''
|
|
return dom
|
|
}
|
|
|
|
function overrides(node) {
|
|
assert.ok(node)
|
|
const props = {}
|
|
for (const sheet of compiled.slice(1)) sheet.walkRules(rule => {
|
|
if (compile(rule.selector)(node)) rule.walkDecls(d => { props[d.prop] = d.value })
|
|
})
|
|
return props
|
|
}
|
|
|
|
test('V2 light: the title is text on the shell canvas and aligns with the filter card', () => {
|
|
const dom = fixture('v2')
|
|
const at = selector => overrides(selectOne(selector, dom))
|
|
assert.equal(at('.yeji-page').padding, '0')
|
|
assert.equal(at('.yeji-masthead__inner').background, 'transparent')
|
|
assert.equal(at('.yeji-masthead__inner')['box-shadow'], 'none')
|
|
assert.equal(at('.yeji-masthead__inner').padding, '4px 0 0')
|
|
assert.equal(at('.yeji-masthead__title').color, 'var(--zyt-ink)')
|
|
assert.equal(at('.yeji-masthead__desc').color, 'var(--zyt-text)')
|
|
assert.ok(selectOne('.filter-actions el-button[type="primary"].filter-btn--query', dom))
|
|
assert.equal(at('.yeji-page')['--yj-brand'], 'var(--zyt-primary)')
|
|
assert.equal(at('.filter-btn--query').color, 'var(--el-button-text-color)')
|
|
})
|
|
|
|
test('department / leaderboard headers and totals are solid neutral surfaces without changing pinned-column geometry', () => {
|
|
const dom = fixture('v2')
|
|
for (const selector of ['thead th.col-dept', 'thead th.col-rank', '.total-row td.col-dept', '.total-row td.col-completed']) {
|
|
const properties = overrides(selectOne(selector, dom))
|
|
assert.equal(properties.background, 'var(--zyt-surface-subtle)', selector)
|
|
assert.equal(properties.position, undefined, selector)
|
|
assert.equal(properties.left, undefined, selector)
|
|
}
|
|
const sticky = []
|
|
compiled[0].walkDecls('position', d => { if (d.value === 'sticky') sticky.push(d.parent.selector) })
|
|
assert.ok(sticky.some(s => s.includes('thead th.col-dept')))
|
|
assert.ok(sticky.some(s => s.includes('thead th.col-rank')))
|
|
})
|
|
|
|
test('the light-shell overrides have no matches in classic or V2 dark', () => {
|
|
for (const dom of [fixture('legacy'), fixture('v2', true)]) {
|
|
for (const sheet of compiled.slice(1)) sheet.walkRules(rule => {
|
|
assert.equal(selectAll(rule.selector, dom).length, 0, rule.selector)
|
|
})
|
|
}
|
|
})
|