logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

theme_data.spec.js (3240B)


  1. import { getLayersArray, topoSort } from 'src/services/theme_data/theme_data.service.js'
  2. describe('Theme Data utility functions', () => {
  3. describe('getLayersArray', () => {
  4. const fixture = {
  5. layer1: null,
  6. layer2: 'layer1',
  7. layer3a: 'layer2',
  8. layer3b: 'layer2'
  9. }
  10. it('should expand layers properly (3b)', () => {
  11. const out = getLayersArray('layer3b', fixture)
  12. expect(out).to.eql(['layer1', 'layer2', 'layer3b'])
  13. })
  14. it('should expand layers properly (3a)', () => {
  15. const out = getLayersArray('layer3a', fixture)
  16. expect(out).to.eql(['layer1', 'layer2', 'layer3a'])
  17. })
  18. it('should expand layers properly (2)', () => {
  19. const out = getLayersArray('layer2', fixture)
  20. expect(out).to.eql(['layer1', 'layer2'])
  21. })
  22. it('should expand layers properly (1)', () => {
  23. const out = getLayersArray('layer1', fixture)
  24. expect(out).to.eql(['layer1'])
  25. })
  26. })
  27. describe('topoSort', () => {
  28. const fixture1 = {
  29. layerA: [],
  30. layer1A: ['layerA'],
  31. layer2A: ['layer1A'],
  32. layerB: [],
  33. layer1B: ['layerB'],
  34. layer2B: ['layer1B'],
  35. layer3AB: ['layer2B', 'layer2A']
  36. }
  37. // Same thing but messed up order
  38. const fixture2 = {
  39. layer1A: ['layerA'],
  40. layer1B: ['layerB'],
  41. layer2A: ['layer1A'],
  42. layerB: [],
  43. layer3AB: ['layer2B', 'layer2A'],
  44. layer2B: ['layer1B'],
  45. layerA: []
  46. }
  47. it('should make a topologically sorted array', () => {
  48. const out = topoSort(fixture1, (node, inheritance) => inheritance[node])
  49. // This basically checks all ordering that matters
  50. expect(out.indexOf('layerA')).to.be.below(out.indexOf('layer1A'))
  51. expect(out.indexOf('layer1A')).to.be.below(out.indexOf('layer2A'))
  52. expect(out.indexOf('layerB')).to.be.below(out.indexOf('layer1B'))
  53. expect(out.indexOf('layer1B')).to.be.below(out.indexOf('layer2B'))
  54. expect(out.indexOf('layer2A')).to.be.below(out.indexOf('layer3AB'))
  55. expect(out.indexOf('layer2B')).to.be.below(out.indexOf('layer3AB'))
  56. })
  57. it('order in object shouldn\'t matter', () => {
  58. const out = topoSort(fixture2, (node, inheritance) => inheritance[node])
  59. // This basically checks all ordering that matters
  60. expect(out.indexOf('layerA')).to.be.below(out.indexOf('layer1A'))
  61. expect(out.indexOf('layer1A')).to.be.below(out.indexOf('layer2A'))
  62. expect(out.indexOf('layerB')).to.be.below(out.indexOf('layer1B'))
  63. expect(out.indexOf('layer1B')).to.be.below(out.indexOf('layer2B'))
  64. expect(out.indexOf('layer2A')).to.be.below(out.indexOf('layer3AB'))
  65. expect(out.indexOf('layer2B')).to.be.below(out.indexOf('layer3AB'))
  66. })
  67. it('dependentless nodes should be first', () => {
  68. const out = topoSort(fixture2, (node, inheritance) => inheritance[node])
  69. // This basically checks all ordering that matters
  70. expect(out.indexOf('layerA')).to.eql(0)
  71. expect(out.indexOf('layerB')).to.eql(1)
  72. })
  73. it('ignores cyclic dependencies', () => {
  74. const out = topoSort({ a: 'b', b: 'a', c: 'a' }, (node, inheritance) => [inheritance[node]])
  75. expect(out.indexOf('a')).to.be.below(out.indexOf('c'))
  76. })
  77. })
  78. })