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