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_data3.spec.js (4769B)


  1. import {
  2. getAllPossibleCombinations
  3. } from 'src/services/theme_data/iss_utils.js'
  4. import {
  5. init
  6. } from 'src/services/theme_data/theme_data_3.service.js'
  7. import {
  8. basePaletteKeys
  9. } from 'src/services/theme_data/theme2_to_theme3.js'
  10. describe('Theme Data 3', () => {
  11. describe('getAllPossibleCombinations', () => {
  12. it('test simple 3 values case', () => {
  13. const out = getAllPossibleCombinations([1, 2, 3]).map(x => x.sort((a, b) => a - b))
  14. expect(out).to.eql([
  15. [1], [2], [3],
  16. [1, 2], [1, 3], [2, 3],
  17. [1, 2, 3]
  18. ])
  19. })
  20. it('test simple 4 values case', () => {
  21. const out = getAllPossibleCombinations([1, 2, 3, 4]).map(x => x.sort((a, b) => a - b))
  22. expect(out).to.eql([
  23. [1], [2], [3], [4],
  24. [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4],
  25. [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4],
  26. [1, 2, 3, 4]
  27. ])
  28. })
  29. it('test massive 5 values case, using strings', () => {
  30. const out = getAllPossibleCombinations(['a', 'b', 'c', 'd', 'e']).map(x => x.sort((a, b) => a - b))
  31. expect(out).to.eql([
  32. // 1
  33. ['a'], ['b'], ['c'], ['d'], ['e'],
  34. // 2
  35. ['a', 'b'], ['a', 'c'], ['a', 'd'], ['a', 'e'],
  36. ['b', 'c'], ['b', 'd'], ['b', 'e'],
  37. ['c', 'd'], ['c', 'e'],
  38. ['d', 'e'],
  39. // 3
  40. ['a', 'b', 'c'], ['a', 'b', 'd'], ['a', 'b', 'e'],
  41. ['a', 'c', 'd'], ['a', 'c', 'e'],
  42. ['a', 'd', 'e'],
  43. ['b', 'c', 'd'], ['b', 'c', 'e'],
  44. ['b', 'd', 'e'],
  45. ['c', 'd', 'e'],
  46. // 4
  47. ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'e'],
  48. ['a', 'b', 'd', 'e'],
  49. ['a', 'c', 'd', 'e'],
  50. ['b', 'c', 'd', 'e'],
  51. // 5
  52. ['a', 'b', 'c', 'd', 'e']
  53. ])
  54. })
  55. })
  56. describe('init', function () {
  57. this.timeout(5000)
  58. it('Test initialization without anything', () => {
  59. const out = init({ inputRuleset: [], ultimateBackgroundColor: '#DEADAF' })
  60. expect(out).to.have.property('eager')
  61. expect(out).to.have.property('lazy')
  62. expect(out).to.have.property('staticVars')
  63. expect(out.lazy).to.be.an('array')
  64. expect(out.lazy).to.have.lengthOf.above(1)
  65. expect(out.eager).to.be.an('array')
  66. expect(out.eager).to.have.lengthOf.above(1)
  67. expect(out.staticVars).to.be.an('object')
  68. // check backwards compat/generic stuff
  69. basePaletteKeys.forEach(key => {
  70. expect(out.staticVars).to.have.property(key)
  71. })
  72. })
  73. it('Test initialization with a basic palette', () => {
  74. const out = init({
  75. inputRuleset: [{
  76. component: 'Root',
  77. directives: {
  78. '--bg': 'color | #008080',
  79. '--fg': 'color | #00C0A0'
  80. }
  81. }],
  82. ultimateBackgroundColor: '#DEADAF'
  83. })
  84. expect(out.staticVars).to.have.property('bg').equal('#008080')
  85. expect(out.staticVars).to.have.property('fg').equal('#00C0A0')
  86. const panelRule = out.eager.filter(x => {
  87. if (x.component !== 'Panel') return false
  88. return true
  89. })[0]
  90. expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked', { r: 0, g: 128, b: 128 })
  91. })
  92. it('Test initialization with opacity', () => {
  93. const out = init({
  94. inputRuleset: [{
  95. component: 'Root',
  96. directives: {
  97. '--bg': 'color | #008080'
  98. }
  99. }, {
  100. component: 'Panel',
  101. directives: {
  102. opacity: 0.5
  103. }
  104. }],
  105. onlyNormalState: true,
  106. ultimateBackgroundColor: '#DEADAF'
  107. })
  108. expect(out.staticVars).to.have.property('bg').equal('#008080')
  109. const panelRule = out.eager.filter(x => {
  110. if (x.component !== 'Panel') return false
  111. return true
  112. })[0]
  113. expect(panelRule).to.have.nested.deep.property('dynamicVars.background', { r: 0, g: 128, b: 128, a: 0.5 })
  114. expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked')
  115. // Somewhat incorrect since we don't do gamma correction
  116. // real expectancy should be this:
  117. /*
  118. expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.r').that.is.closeTo(147.0, 0.01)
  119. expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.g').that.is.closeTo(143.2, 0.01)
  120. expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.b').that.is.closeTo(144.0, 0.01)
  121. */
  122. expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.r').that.is.closeTo(111, 0.01)
  123. expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.g').that.is.closeTo(150.5, 0.01)
  124. expect(panelRule).to.have.nested.deep.property('dynamicVars.stacked.b').that.is.closeTo(151.5, 0.01)
  125. })
  126. })
  127. })