iss_deserializer.spec.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { deserialize } from 'src/services/theme_data/iss_deserializer.js'
  2. import { serialize } from 'src/services/theme_data/iss_serializer.js'
  3. const componentsContext = require.context('src', true, /\.style.js(on)?$/)
  4. describe('ISS (de)serialization', () => {
  5. componentsContext.keys().forEach(key => {
  6. const component = componentsContext(key).default
  7. it(`(De)serialization of component ${component.name} works`, () => {
  8. const normalized = component.defaultRules.map(x => ({ component: component.name, ...x }))
  9. const serialized = serialize(normalized)
  10. const deserialized = deserialize(serialized)
  11. // for some reason comparing objects directly fails the assert
  12. expect(JSON.stringify(deserialized, null, 2)).to.equal(JSON.stringify(normalized, null, 2))
  13. })
  14. })
  15. /*
  16. // Debug snippet
  17. const onlyComponent = componentsContext('./components/panel_header.style.js').default
  18. it.only(`(De)serialization of component ${onlyComponent.name} works`, () => {
  19. const normalized = onlyComponent.defaultRules.map(x => ({ component: onlyComponent.name, ...x }))
  20. console.log('BEGIN INPUT ================')
  21. console.log(normalized)
  22. console.log('END INPUT ==================')
  23. const serialized = serialize(normalized)
  24. console.log('BEGIN SERIAL ===============')
  25. console.log(serialized)
  26. console.log('END SERIAL =================')
  27. const deserialized = deserialize(serialized)
  28. console.log('BEGIN DESERIALIZED =========')
  29. console.log(serialized)
  30. console.log('END DESERIALIZED ===========')
  31. // for some reason comparing objects directly fails the assert
  32. expect(JSON.stringify(deserialized, null, 2)).to.equal(JSON.stringify(normalized, null, 2))
  33. })
  34. /* */
  35. })