Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

82 righe
2.2 KiB

  1. /* global describe, it, before */
  2. import chai from 'chai';
  3. import {
  4. makeDataAttributeString,
  5. getCSSString,
  6. buildCSSRule,
  7. removeCSSRule
  8. } from '../src/utils.js';
  9. chai.expect();
  10. const expect = chai.expect;
  11. describe('#utils', () => {
  12. describe('makeDataAttributeString', () => {
  13. it('should return the correct data-attr string', () => {
  14. const props = {
  15. isHeader: 1,
  16. colIndex: 0,
  17. rowIndex: 4
  18. };
  19. expect(makeDataAttributeString(props))
  20. .to.be.equal('data-is-header="1" data-col-index="0" data-row-index="4"');
  21. });
  22. });
  23. describe('getCSSString', () => {
  24. it('should return CSS key value pairs', () => {
  25. const style = {
  26. width: '2px',
  27. height: '4px',
  28. 'margin-top': '3px'
  29. };
  30. expect(getCSSString(style))
  31. .to.be.equal('width: 2px; height: 4px; margin-top: 3px;');
  32. });
  33. });
  34. describe('buildCSSRule', () => {
  35. it('should return CSS rule string with updated properties', () => {
  36. const rule = '.test';
  37. const style = {
  38. width: '2px',
  39. height: '4px',
  40. 'margin-top': '3px'
  41. };
  42. const ruleString = buildCSSRule(rule, style);
  43. expect(ruleString)
  44. .to.be.equal('.test { width: 2px; height: 4px; margin-top: 3px; }');
  45. const updatedRuleString = buildCSSRule(rule, { width: '5px' }, ruleString);
  46. expect(updatedRuleString)
  47. .to.be.equal('.test { width: 5px; height: 4px; margin-top: 3px; }');
  48. const updatedRuleString2 = buildCSSRule(rule, { height: '19px' }, updatedRuleString);
  49. expect(updatedRuleString2)
  50. .to.be.equal('.test { width: 5px; height: 19px; margin-top: 3px; }');
  51. const updatedRuleString3 = buildCSSRule('.test2', { height: '45px' }, updatedRuleString2);
  52. expect(updatedRuleString3)
  53. .to.be.equal('.test { width: 5px; height: 19px; margin-top: 3px; }.test2 { height: 45px; }');
  54. });
  55. });
  56. describe('removeCSSRule', () => {
  57. it('should remove the css rule based on the selector', () => {
  58. const rule = '.test';
  59. const cssRuleString = `.test {margin-top: 2px;} .test2 {color: blue;}`;
  60. expect(removeCSSRule(rule, cssRuleString))
  61. .to.be.equal('.test2 {color: blue;}');
  62. })
  63. })
  64. });