split-test-badge.spec.tsx 5.9 KB

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