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

41 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-09-19 17:37:14 +00:00
import { deserialize } from 'src/services/theme_data/iss_deserializer.js'
2024-09-19 23:05:25 +00:00
import { serialize } from 'src/services/theme_data/iss_serializer.js'
2024-09-20 09:50:05 +00:00
const componentsContext = require.context('src', true, /\.style.js(on)?$/)
2024-09-19 17:37:14 +00:00
2024-09-20 11:25:36 +00:00
describe('ISS (de)serialization', () => {
2024-09-20 09:50:05 +00:00
componentsContext.keys().forEach(key => {
const component = componentsContext(key).default
it(`(De)serialization of component ${component.name} works`, () => {
const normalized = component.defaultRules.map(x => ({ component: component.name, ...x }))
2024-09-19 23:05:25 +00:00
const serialized = serialize(normalized)
const deserialized = deserialize(serialized)
2024-09-19 17:37:14 +00:00
2024-09-19 23:07:27 +00:00
// for some reason comparing objects directly fails the assert
2024-09-20 09:50:05 +00:00
expect(JSON.stringify(deserialized, null, 2)).to.equal(JSON.stringify(normalized, null, 2))
2024-09-19 17:37:14 +00:00
})
})
2024-09-20 09:50:05 +00:00
/*
// Debug snippet
const onlyComponent = componentsContext('./components/panel_header.style.js').default
it(`(De)serialization of component ${onlyComponent.name} works`, () => {
const normalized = onlyComponent.defaultRules.map(x => ({ component: onlyComponent.name, ...x }))
console.log('BEGIN INPUT ================')
console.log(normalized)
console.log('END INPUT ==================')
const serialized = serialize(normalized)
console.log('BEGIN SERIAL ===============')
console.log(serialized)
console.log('END SERIAL =================')
const deserialized = deserialize(serialized)
console.log('BEGIN DESERIALIZED =========')
console.log(serialized)
console.log('END DESERIALIZED ===========')
// for some reason comparing objects directly fails the assert
expect(JSON.stringify(deserialized, null, 2)).to.equal(JSON.stringify(normalized, null, 2))
})
*/
2024-09-19 17:37:14 +00:00
})