utils_tests.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /** @odoo-module **/
  2. import weUtils from 'web_editor.utils';
  3. QUnit.module('web_editor', {}, function () {
  4. QUnit.module('utils', {}, function () {
  5. QUnit.module('Utils functions');
  6. // Test weUtils
  7. QUnit.test('compare CSS property values', async function (assert) {
  8. assert.expect(86);
  9. let $div = $(`<div>abc</div>`);
  10. let currentProperty = 'font-size';
  11. function compare(expected, value1, value2, property = currentProperty, $target = $div) {
  12. // Comparisons are done in both directions if values are different.
  13. assert.strictEqual(weUtils.areCssValuesEqual(value1, value2, property, $target), expected,
  14. `'${value1}' should be ${expected ? 'equal to' : 'different from'} '${value2}'`
  15. );
  16. if (value1 !== value2) {
  17. assert.strictEqual(weUtils.areCssValuesEqual(value2, value1, property, $target), expected,
  18. `'${value2}' should be ${expected ? 'equal to' : 'different from'} '${value1}'`
  19. );
  20. }
  21. }
  22. compare(true, '', '');
  23. compare(true, 'auto', 'auto');
  24. compare(true, '', 'auto');
  25. compare(true, '15px', '15px');
  26. compare(true, '15.0px', '15px');
  27. compare(true, '15 px', '15px');
  28. compare(false, '15px', '25px');
  29. compare(false, '15px', '');
  30. compare(false, '15px', 'auto');
  31. compare(true, '15px', '1.5e+1px');
  32. compare(true, '15px', '1.5e1px');
  33. compare(true, '15px', '150e-1px');
  34. currentProperty = 'background-size';
  35. compare(true, '', '');
  36. compare(true, 'auto', 'auto');
  37. compare(true, '', 'auto');
  38. compare(true, '15px', '15px');
  39. compare(true, '15.0px', '15px');
  40. compare(false, '15px', '25px');
  41. compare(false, '15px', '');
  42. compare(false, '15px', 'auto');
  43. compare(true, '', 'auto auto');
  44. compare(true, 'auto', 'auto auto');
  45. compare(true, 'auto auto', 'auto auto');
  46. compare(true, '15px 15px', '15px 15px');
  47. compare(false, '15px 25px', '15px 15px');
  48. compare(false, '25px 15px', '15px 15px');
  49. compare(true, 'auto 15px', 'auto 15px');
  50. compare(true, '15px auto', '15px auto');
  51. compare(true, '15px', '15px auto');
  52. compare(false, 'auto 25px', 'auto 15px');
  53. compare(false, '25px auto', '15px auto');
  54. compare(false, '25px', '15px auto');
  55. compare(true, '15px 15px', '1.5e+1px 1.5e+1px');
  56. compare(true, '15px 15px', '1.5e1px 1.5e1px');
  57. compare(true, '15px 15px', '150e-1px 150e-1px');
  58. currentProperty = 'color';
  59. compare(true, '', '');
  60. compare(false, '', '#123456');
  61. compare(true, '#123456', '#123456');
  62. compare(false, '#123456', '#654321');
  63. compare(true, 'rgb(255, 0, 0)', '#FF0000');
  64. compare(false, 'rgb(255, 0, 0)', '#EE0000');
  65. currentProperty = 'background-image';
  66. compare(true, '', '');
  67. compare(false, '', 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)');
  68. compare(true, 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)', 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)');
  69. compare(false, 'linear-gradient(0deg, rgb(10, 0, 0) 0%, rgb(1, 1, 1) 100%)', 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)');
  70. compare(false, 'linear-gradient(10deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)', 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)');
  71. compare(false, 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(10, 1, 1) 100%)', 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)');
  72. compare(false, 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(9, 9, 9) 50%, rgb(1, 1, 1) 100%)', 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)');
  73. compare(true, 'linear-gradient(0deg, #000000 0%, #010101 100%)', 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)');
  74. compare(false, 'linear-gradient(0deg, #FF0000 0%, #010101 100%)', 'linear-gradient(0deg, rgb(0, 0, 0) 0%, rgb(1, 1, 1) 100%)');
  75. });
  76. });
  77. });