split-test-badge.spec.tsx 5.7 KB

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