constructSelector.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. id: 'ID1',
  10. role: 'button',
  11. tag: 'button',
  12. testid: 'button-test',
  13. title: 'cool title',
  14. },
  15. fullSelector:
  16. 'button#ID1.classA[role="button"][aria="View More"][data-test-id="button-test"][alt="view more"][title="cool title"]',
  17. selector:
  18. 'button#ID1.classA[role="button"][aria="View More"][data-test-id="button-test"][alt="view more"][title="cool title"]',
  19. },
  20. {
  21. element: {
  22. alt: '',
  23. aria_label: '',
  24. class: ['', ''],
  25. id: '',
  26. role: '',
  27. tag: 'a',
  28. testid: '',
  29. title: '',
  30. },
  31. fullSelector: 'a[role=""][aria=""][data-test-id=""][alt=""][title=""]',
  32. selector: 'a',
  33. },
  34. {
  35. element: {
  36. alt: '',
  37. aria_label: '',
  38. class: ['classA', ''],
  39. id: '',
  40. role: '',
  41. tag: 'a',
  42. testid: '',
  43. title: '',
  44. },
  45. fullSelector: 'a.classA[role=""][aria=""][data-test-id=""][alt=""][title=""]',
  46. selector: 'a.classA',
  47. },
  48. {
  49. element: {
  50. alt: '',
  51. aria_label: '',
  52. class: ['classA', ''],
  53. id: 'ID2',
  54. role: '',
  55. tag: 'a',
  56. testid: '',
  57. title: '',
  58. },
  59. fullSelector: 'a#ID2.classA[role=""][aria=""][data-test-id=""][alt=""][title=""]',
  60. selector: 'a#ID2.classA',
  61. },
  62. {
  63. element: {
  64. alt: '',
  65. aria_label: '',
  66. class: ['classA', 'classB'],
  67. id: 'ID2',
  68. role: '',
  69. tag: 'a',
  70. testid: '',
  71. title: '',
  72. },
  73. fullSelector:
  74. 'a#ID2.classA.classB[role=""][aria=""][data-test-id=""][alt=""][title=""]',
  75. selector: 'a#ID2.classA.classB',
  76. },
  77. {
  78. element: {
  79. alt: '',
  80. aria_label: 'hello',
  81. class: ['classA', 'classB'],
  82. id: 'ID2',
  83. role: '',
  84. tag: 'a',
  85. testid: '',
  86. title: '',
  87. },
  88. fullSelector:
  89. 'a#ID2.classA.classB[role=""][aria="hello"][data-test-id=""][alt=""][title=""]',
  90. selector: 'a#ID2.classA.classB[aria="hello"]',
  91. },
  92. {
  93. element: {
  94. alt: '',
  95. aria_label: 'hello',
  96. class: [''],
  97. id: 'ID2',
  98. role: '',
  99. tag: 'a',
  100. testid: '',
  101. title: '',
  102. },
  103. fullSelector: 'a#ID2[role=""][aria="hello"][data-test-id=""][alt=""][title=""]',
  104. selector: 'a#ID2[aria="hello"]',
  105. },
  106. ])(
  107. 'should construct the correct trimmed selector and full selector, for each element in the list',
  108. ({element, fullSelector, selector}) => {
  109. expect(constructSelector(element)).toStrictEqual({fullSelector, selector});
  110. }
  111. );
  112. });