split-test-badge.spec.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import SplitTestBadge from '../../../../frontend/js/shared/components/split-test-badge'
  2. import { EditorProviders } from '../../helpers/editor-providers'
  3. describe('split test badge', function () {
  4. it('renders an alpha badge with the url and tooltip text', function () {
  5. cy.window().then(win => {
  6. win.metaAttributesCache.set('ol-splitTestVariants', {
  7. 'cypress-test': 'active',
  8. })
  9. win.metaAttributesCache.set('ol-splitTestInfo', {
  10. 'cypress-test': {
  11. phase: 'alpha',
  12. badgeInfo: {
  13. url: '/alpha/participate',
  14. tooltipText: 'This is an alpha feature',
  15. },
  16. },
  17. })
  18. })
  19. cy.mount(
  20. <EditorProviders>
  21. <SplitTestBadge
  22. splitTestName="cypress-test"
  23. displayOnVariants={['active']}
  24. />
  25. </EditorProviders>
  26. )
  27. cy.findByRole('link', { name: /this is an alpha feature/i })
  28. .should('have.attr', 'href', '/alpha/participate')
  29. .find('.badge')
  30. .contains('α')
  31. })
  32. it('does not render the alpha badge when user is not assigned to the variant', function () {
  33. cy.window().then(win => {
  34. win.metaAttributesCache.set('ol-splitTestVariants', {
  35. 'cypress-test': 'default',
  36. })
  37. win.metaAttributesCache.set('ol-splitTestInfo', {
  38. 'cypress-test': {
  39. phase: 'alpha',
  40. badgeInfo: {
  41. url: '/alpha/participate',
  42. tooltipText: 'This is an alpha feature',
  43. },
  44. },
  45. })
  46. })
  47. cy.mount(
  48. <EditorProviders>
  49. <SplitTestBadge
  50. splitTestName="cypress-test"
  51. displayOnVariants={['active']}
  52. />
  53. </EditorProviders>
  54. )
  55. cy.get('.badge').should('not.exist')
  56. })
  57. it('renders a beta badge with the url and tooltip text', function () {
  58. cy.window().then(win => {
  59. win.metaAttributesCache.set('ol-splitTestVariants', {
  60. 'cypress-test': 'active',
  61. })
  62. win.metaAttributesCache.set('ol-splitTestInfo', {
  63. 'cypress-test': {
  64. phase: 'beta',
  65. badgeInfo: {
  66. url: '/beta/participate',
  67. tooltipText: 'This is a beta feature',
  68. },
  69. },
  70. })
  71. })
  72. cy.mount(
  73. <EditorProviders>
  74. <SplitTestBadge
  75. splitTestName="cypress-test"
  76. displayOnVariants={['active']}
  77. />
  78. </EditorProviders>
  79. )
  80. cy.findByRole('link', { name: /this is a beta feature/i })
  81. .should('have.attr', 'href', '/beta/participate')
  82. .find('.badge')
  83. .contains('β')
  84. })
  85. it('does not render the beta badge when user is not assigned to the variant', function () {
  86. cy.window().then(win => {
  87. win.metaAttributesCache.set('ol-splitTestVariants', {
  88. 'cypress-test': 'default',
  89. })
  90. win.metaAttributesCache.set('ol-splitTestInfo', {
  91. 'cypress-test': {
  92. phase: 'beta',
  93. badgeInfo: {
  94. url: '/beta/participate',
  95. tooltipText: 'This is a beta feature',
  96. },
  97. },
  98. })
  99. })
  100. cy.mount(
  101. <EditorProviders>
  102. <SplitTestBadge
  103. splitTestName="cypress-test"
  104. displayOnVariants={['active']}
  105. />
  106. </EditorProviders>
  107. )
  108. cy.get('.badge').should('not.exist')
  109. })
  110. it('renders an info badge with the url and tooltip text', function () {
  111. cy.window().then(win => {
  112. win.metaAttributesCache.set('ol-splitTestVariants', {
  113. 'cypress-test': 'active',
  114. })
  115. win.metaAttributesCache.set('ol-splitTestInfo', {
  116. 'cypress-test': {
  117. phase: 'release',
  118. badgeInfo: {
  119. url: '/feedback/form',
  120. tooltipText: 'This is a new feature',
  121. },
  122. },
  123. })
  124. })
  125. cy.mount(
  126. <EditorProviders>
  127. <SplitTestBadge
  128. splitTestName="cypress-test"
  129. displayOnVariants={['active']}
  130. />
  131. </EditorProviders>
  132. )
  133. cy.findByRole('link', { name: /this is a new feature/i })
  134. .should('have.attr', 'href', '/feedback/form')
  135. .find('.info-badge')
  136. })
  137. it('does not render the info badge when user is not assigned to the variant', function () {
  138. cy.window().then(win => {
  139. win.metaAttributesCache.set('ol-splitTestVariants', {
  140. 'cypress-test': 'default',
  141. })
  142. win.metaAttributesCache.set('ol-splitTestInfo', {
  143. 'cypress-test': {
  144. phase: 'release',
  145. badgeInfo: {
  146. url: '/feedback/form',
  147. tooltipText: 'This is a new feature',
  148. },
  149. },
  150. })
  151. })
  152. cy.mount(
  153. <EditorProviders>
  154. <SplitTestBadge
  155. splitTestName="cypress-test"
  156. displayOnVariants={['active']}
  157. />
  158. </EditorProviders>
  159. )
  160. cy.get('.badge').should('not.exist')
  161. })
  162. it('does not render the badge when no split test info is available', function () {
  163. cy.window().then(win => {
  164. win.metaAttributesCache.set('ol-splitTestVariants', {
  165. 'cypress-test': 'active',
  166. })
  167. win.metaAttributesCache.set('ol-splitTestInfo', {})
  168. })
  169. cy.mount(
  170. <EditorProviders>
  171. <SplitTestBadge
  172. splitTestName="cypress-test"
  173. displayOnVariants={['active']}
  174. />
  175. </EditorProviders>
  176. )
  177. cy.get('.badge').should('not.exist')
  178. })
  179. it('default badge url and text are used when not provided', function () {
  180. cy.window().then(win => {
  181. win.metaAttributesCache.set('ol-splitTestVariants', {
  182. 'cypress-test': 'active',
  183. })
  184. win.metaAttributesCache.set('ol-splitTestInfo', {
  185. 'cypress-test': {
  186. phase: 'release',
  187. },
  188. })
  189. })
  190. cy.mount(
  191. <EditorProviders>
  192. <SplitTestBadge
  193. splitTestName="cypress-test"
  194. displayOnVariants={['active']}
  195. />
  196. </EditorProviders>
  197. )
  198. cy.findByRole('link', {
  199. name: /we are testing this new feature.*click to give feedback/i,
  200. })
  201. .should('have.attr', 'href', '/beta/participate')
  202. .find('.info-badge')
  203. })
  204. })