fix rgba css generation, add some tests to automatically verify that themes are

generated properly
This commit is contained in:
Henry Jameson 2020-01-27 04:20:13 +02:00
parent d7e7f47b66
commit 7c074b8741
8 changed files with 116 additions and 84 deletions

View file

@ -0,0 +1,28 @@
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 => {
if ((k === 'a' && v.hasOwnProperty('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)
})
})
})