fix rgba css generation, add some tests to automatically verify that themes are
generated properly
This commit is contained in:
parent
d7e7f47b66
commit
7c074b8741
@ -35,6 +35,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
alias: {
|
alias: {
|
||||||
'vue$': 'vue/dist/vue.runtime.common',
|
'vue$': 'vue/dist/vue.runtime.common',
|
||||||
|
'static': path.resolve(__dirname, '../static'),
|
||||||
'src': path.resolve(__dirname, '../src'),
|
'src': path.resolve(__dirname, '../src'),
|
||||||
'assets': path.resolve(__dirname, '../src/assets'),
|
'assets': path.resolve(__dirname, '../src/assets'),
|
||||||
'components': path.resolve(__dirname, '../src/components')
|
'components': path.resolve(__dirname, '../src/components')
|
||||||
|
@ -171,7 +171,7 @@ export const mixrgb = (a, b) => {
|
|||||||
* @returns {String} CSS rgba() color
|
* @returns {String} CSS rgba() color
|
||||||
*/
|
*/
|
||||||
export const rgba2css = function (rgba) {
|
export const rgba2css = function (rgba) {
|
||||||
return `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, ${rgba.a})`
|
return `rgba(${Math.floor(rgba.r)}, ${Math.floor(rgba.g)}, ${Math.floor(rgba.b)}, .5)`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -353,7 +353,7 @@ export const getColors = (sourceColors, sourceOpacity, mod) => SLOT_ORDERED.redu
|
|||||||
if (dependencySlot && sourceColors[dependencySlot] === 'transparent') {
|
if (dependencySlot && sourceColors[dependencySlot] === 'transparent') {
|
||||||
outputColor.a = 0
|
outputColor.a = 0
|
||||||
} else {
|
} else {
|
||||||
outputColor.a = sourceOpacity[opacitySlot] || OPACITIES[opacitySlot].defaultValue || 1
|
outputColor.a = Number(sourceOpacity[opacitySlot]) || OPACITIES[opacitySlot].defaultValue || 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (opacitySlot) {
|
if (opacitySlot) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"_pleroma_theme_version": 2,
|
"_pleroma_theme_version": 2,
|
||||||
"name": "Redmond XX SE",
|
"name": "Redmond XX SE",
|
||||||
"theme": {
|
"source": {
|
||||||
"shadows": {
|
"shadows": {
|
||||||
"panel": [
|
"panel": [
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"_pleroma_theme_version": 2,
|
"_pleroma_theme_version": 2,
|
||||||
"name": "Redmond XX",
|
"name": "Redmond XX",
|
||||||
"theme": {
|
"source": {
|
||||||
"shadows": {
|
"shadows": {
|
||||||
"panel": [
|
"panel": [
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"_pleroma_theme_version": 2,
|
"_pleroma_theme_version": 2,
|
||||||
"name": "Redmond XXI",
|
"name": "Redmond XXI",
|
||||||
"theme": {
|
"source": {
|
||||||
"shadows": {
|
"shadows": {
|
||||||
"panel": [
|
"panel": [
|
||||||
{
|
{
|
||||||
|
28
test/unit/specs/services/theme_data/sanity_checks.spec.js
Normal file
28
test/unit/specs/services/theme_data/sanity_checks.spec.js
Normal 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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -1,5 +1,6 @@
|
|||||||
import { getLayersArray, topoSort } from 'src/services/theme_data/theme_data.service.js'
|
import { getLayersArray, topoSort } from 'src/services/theme_data/theme_data.service.js'
|
||||||
|
|
||||||
|
describe('Theme Data utility functions', () => {
|
||||||
describe('getLayersArray', () => {
|
describe('getLayersArray', () => {
|
||||||
const fixture = {
|
const fixture = {
|
||||||
layer1: null,
|
layer1: null,
|
||||||
@ -85,3 +86,5 @@ describe('topoSort', () => {
|
|||||||
expect(out.indexOf('a')).to.be.below(out.indexOf('c'))
|
expect(out.indexOf('a')).to.be.below(out.indexOf('c'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user