constructSelector.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import constructSelector from 'sentry/views/replays/deadRageClick/constructSelector';
  2. describe('constructSelector', () => {
  3. it.each([
  4. {
  5. element: {
  6. alt: 'view more',
  7. aria_label: 'View More',
  8. class: ['classA'],
  9. component_name: 'TestButton',
  10. id: 'ID1',
  11. role: 'button',
  12. tag: 'button',
  13. testid: 'button-test',
  14. title: 'cool title',
  15. },
  16. fullSelector:
  17. 'button#ID1.classA[role="button"][aria="View More"][data-test-id="button-test"][alt="view more"][title="cool title"][data-sentry-component="TestButton"]',
  18. selector:
  19. 'TestButton#ID1[role="button"][aria="View More"][data-test-id="button-test"][alt="view more"][title="cool title"]',
  20. },
  21. {
  22. element: {
  23. alt: '',
  24. aria_label: '',
  25. class: ['', ''],
  26. component_name: '',
  27. id: '',
  28. role: '',
  29. tag: 'a',
  30. testid: '',
  31. title: '',
  32. },
  33. fullSelector:
  34. 'a[role=""][aria=""][data-test-id=""][alt=""][title=""][data-sentry-component=""]',
  35. selector: 'a',
  36. },
  37. {
  38. element: {
  39. alt: '',
  40. aria_label: '',
  41. class: ['classA', ''],
  42. component_name: '',
  43. id: '',
  44. role: '',
  45. tag: 'a',
  46. testid: '',
  47. title: '',
  48. },
  49. fullSelector:
  50. 'a.classA[role=""][aria=""][data-test-id=""][alt=""][title=""][data-sentry-component=""]',
  51. selector: 'a.classA',
  52. },
  53. {
  54. element: {
  55. alt: '',
  56. aria_label: '',
  57. class: ['classA', ''],
  58. component_name: '',
  59. id: 'ID2',
  60. role: '',
  61. tag: 'a',
  62. testid: '',
  63. title: '',
  64. },
  65. fullSelector:
  66. 'a#ID2.classA[role=""][aria=""][data-test-id=""][alt=""][title=""][data-sentry-component=""]',
  67. selector: 'a#ID2.classA',
  68. },
  69. {
  70. element: {
  71. alt: '',
  72. aria_label: '',
  73. class: ['classA', 'classB'],
  74. component_name: 'TestButton',
  75. id: 'ID2',
  76. role: '',
  77. tag: 'a',
  78. testid: '',
  79. title: '',
  80. },
  81. fullSelector:
  82. 'a#ID2.classA.classB[role=""][aria=""][data-test-id=""][alt=""][title=""][data-sentry-component="TestButton"]',
  83. selector: 'TestButton#ID2',
  84. },
  85. {
  86. element: {
  87. alt: '',
  88. aria_label: 'hello',
  89. class: ['classA', 'classB'],
  90. component_name: '',
  91. id: 'ID2',
  92. role: '',
  93. tag: 'a',
  94. testid: '',
  95. title: '',
  96. },
  97. fullSelector:
  98. 'a#ID2.classA.classB[role=""][aria="hello"][data-test-id=""][alt=""][title=""][data-sentry-component=""]',
  99. selector: 'a#ID2.classA.classB[aria="hello"]',
  100. },
  101. {
  102. element: {
  103. alt: '',
  104. aria_label: 'hello',
  105. component_name: 'TestHello',
  106. class: [''],
  107. id: 'ID2',
  108. role: '',
  109. tag: 'a',
  110. testid: '',
  111. title: '',
  112. },
  113. fullSelector:
  114. 'a#ID2[role=""][aria="hello"][data-test-id=""][alt=""][title=""][data-sentry-component="TestHello"]',
  115. selector: 'TestHello#ID2[aria="hello"]',
  116. },
  117. ])(
  118. 'should construct the correct trimmed selector and full selector, for each element in the list',
  119. ({element, fullSelector, selector}) => {
  120. expect(constructSelector(element)).toStrictEqual({
  121. fullSelector,
  122. selector,
  123. });
  124. }
  125. );
  126. });