sanity_checks.spec.js 1019 B

12345678910111213141516171819202122232425262728
  1. import { getColors } from 'src/services/theme_data/theme_data.service.js'
  2. const checkColors = (output) => {
  3. expect(output).to.have.property('colors')
  4. Object.entries(output.colors).forEach(([key, v]) => {
  5. expect(v, key).to.be.an('object')
  6. expect(v, key).to.include.all.keys('r', 'g', 'b')
  7. 'rgba'.split('').forEach(k => {
  8. if ((k === 'a' && Object.prototype.hasOwnProperty.call(v, 'a')) || k !== 'a') {
  9. expect(v[k], key + '.' + k).to.be.a('number')
  10. expect(v[k], key + '.' + k).to.be.least(0)
  11. expect(v[k], key + '.' + k).to.be.most(k === 'a' ? 1 : 255)
  12. }
  13. })
  14. })
  15. }
  16. describe('Theme Data utility functions', () => {
  17. const context = require.context('static/themes/', false, /\.json$/)
  18. context.keys().forEach((key) => {
  19. it(`Should render all colors for ${key} properly`, () => {
  20. const { theme, source } = context(key)
  21. const data = source || theme
  22. const colors = getColors(data.colors, data.opacity, 1)
  23. checkColors(colors)
  24. })
  25. })
  26. })