pleroma-fe/test/unit/specs/services/theme_data/sanity_checks.spec.js

29 lines
1019 B
JavaScript
Raw Normal View History

import { getColors } from 'src/services/theme_data/theme_data.service.js'
const checkColors = (output) => {
expect(output).to.have.property('colors')
Object.entries(output.colors).forEach(([key, v]) => {
expect(v, key).to.be.an('object')
expect(v, key).to.include.all.keys('r', 'g', 'b')
'rgba'.split('').forEach(k => {
2022-07-31 09:36:02 +00:00
if ((k === 'a' && Object.prototype.hasOwnProperty.call(v, 'a')) || k !== 'a') {
expect(v[k], key + '.' + k).to.be.a('number')
expect(v[k], key + '.' + k).to.be.least(0)
expect(v[k], key + '.' + k).to.be.most(k === 'a' ? 1 : 255)
}
})
})
}
describe('Theme Data utility functions', () => {
const context = require.context('static/themes/', false, /\.json$/)
context.keys().forEach((key) => {
it(`Should render all colors for ${key} properly`, () => {
const { theme, source } = context(key)
const data = source || theme
const colors = getColors(data.colors, data.opacity, 1)
checkColors(colors)
})
})
})