updateTextNode.test.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. // do not use react-testing-library in plugins
  20. /* eslint-disable jest-dom/prefer-to-have-attribute */
  21. /* eslint-disable jest-dom/prefer-to-have-text-content */
  22. /* eslint-disable jest-dom/prefer-to-have-style */
  23. import updateTextNode from '../../../src/dimension/svg/updateTextNode';
  24. import createTextNode from '../../../src/dimension/svg/createTextNode';
  25. describe('updateTextNode(node, options)', () => {
  26. it('handles empty options', () => {
  27. const node = updateTextNode(createTextNode());
  28. expect(node.getAttribute('class')).toEqual('');
  29. expect(node.style.font).toEqual('');
  30. expect(node.style.fontWeight).toEqual('');
  31. expect(node.style.fontSize).toEqual('');
  32. expect(node.style.fontStyle).toEqual('');
  33. expect(node.style.fontFamily).toEqual('');
  34. expect(node.style.letterSpacing).toEqual('');
  35. expect(node.textContent).toEqual('');
  36. });
  37. it('handles setting class', () => {
  38. const node = updateTextNode(createTextNode(), { className: 'abc' });
  39. expect(node.getAttribute('class')).toEqual('abc');
  40. expect(node.style.font).toEqual('');
  41. expect(node.style.fontWeight).toEqual('');
  42. expect(node.style.fontSize).toEqual('');
  43. expect(node.style.fontStyle).toEqual('');
  44. expect(node.style.fontFamily).toEqual('');
  45. expect(node.style.letterSpacing).toEqual('');
  46. expect(node.textContent).toEqual('');
  47. });
  48. it('handles setting text', () => {
  49. const node = updateTextNode(createTextNode(), { text: 'abc' });
  50. expect(node.getAttribute('class')).toEqual('');
  51. expect(node.style.font).toEqual('');
  52. expect(node.style.fontWeight).toEqual('');
  53. expect(node.style.fontSize).toEqual('');
  54. expect(node.style.fontStyle).toEqual('');
  55. expect(node.style.fontFamily).toEqual('');
  56. expect(node.style.letterSpacing).toEqual('');
  57. expect(node.textContent).toEqual('abc');
  58. });
  59. it('handles setting font', () => {
  60. const node = updateTextNode(createTextNode(), {
  61. style: {
  62. font: 'italic 30px Lobster 700',
  63. },
  64. });
  65. expect(node.getAttribute('class')).toEqual('');
  66. expect(node.style.fontWeight).toEqual('700');
  67. expect(node.style.fontSize).toEqual('30px');
  68. expect(node.style.fontStyle).toEqual('italic');
  69. expect(node.style.fontFamily).toEqual('Lobster');
  70. expect(node.style.letterSpacing).toEqual('');
  71. expect(node.textContent).toEqual('');
  72. });
  73. it('handles setting specific font style', () => {
  74. const node = updateTextNode(createTextNode(), {
  75. style: {
  76. fontFamily: 'Lobster',
  77. fontStyle: 'italic',
  78. fontWeight: '700',
  79. fontSize: '30px',
  80. letterSpacing: 1.1,
  81. },
  82. });
  83. expect(node.getAttribute('class')).toEqual('');
  84. expect(node.style.fontWeight).toEqual('700');
  85. expect(node.style.fontSize).toEqual('30px');
  86. expect(node.style.fontStyle).toEqual('italic');
  87. expect(node.style.fontFamily).toEqual('Lobster');
  88. expect(node.style.letterSpacing).toEqual('1.1');
  89. expect(node.textContent).toEqual('');
  90. });
  91. });
  92. /* eslint-enable jest-dom/prefer-to-have-attribute */
  93. /* eslint-enable jest-dom/prefer-to-have-text-content */
  94. /* eslint-enable jest-dom/prefer-to-have-style */