toolbar.spec.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { Toolbar } from '@/features/ide-react/components/toolbar/toolbar'
  2. import {
  3. EditorProviders,
  4. makeEditorProvider,
  5. } from '../../../helpers/editor-providers'
  6. import { Cobranding } from '@ol-types/cobranding'
  7. import partnerLogoUrl from './cobranding-logo.png'
  8. describe('<Toolbar />', function () {
  9. describe('cobranding', function () {
  10. beforeEach(function () {
  11. const cobranding: Cobranding = {
  12. logoImgUrl: partnerLogoUrl,
  13. brandVariationName: 'brand variation name',
  14. brandVariationId: 1000,
  15. brandId: 2000,
  16. brandVariationHomeUrl: 'https://brand.example.com',
  17. publishGuideHtml: 'string',
  18. partner: 'partner name',
  19. brandedMenu: true,
  20. submitBtnHtml: 'submit to\n partner',
  21. submitBtnHtmlNoBreaks: 'submit to partner',
  22. }
  23. cy.mount(
  24. <EditorProviders
  25. providers={{ EditorProvider: makeEditorProvider({ cobranding }) }}
  26. >
  27. <Toolbar />
  28. </EditorProviders>
  29. )
  30. })
  31. it('displays the cobranding logo', function () {
  32. cy.get(`img[src="${partnerLogoUrl}"]`).should('be.visible')
  33. })
  34. it('shows the branded submit button', function () {
  35. cy.findByRole('button', { name: 'submit to partner' }).should(
  36. 'be.visible'
  37. )
  38. })
  39. })
  40. describe('no cobranding', function () {
  41. beforeEach(function () {
  42. cy.mount(
  43. <EditorProviders
  44. providers={{
  45. EditorProvider: makeEditorProvider({ cobranding: undefined }),
  46. }}
  47. >
  48. <Toolbar />
  49. </EditorProviders>
  50. )
  51. })
  52. it('does not display a cobranding logo', function () {
  53. cy.get('.ide-redesign-toolbar-cobranding-logo').should('not.exist')
  54. })
  55. it('does not show a submit button', function () {
  56. cy.findByRole('button', { name: 'Submit' }).should('not.exist')
  57. })
  58. })
  59. it('clicking the logo takes you to the home page', function () {
  60. cy.mount(
  61. <EditorProviders projectName="My title">
  62. <Toolbar />
  63. </EditorProviders>
  64. )
  65. cy.findByLabelText('Overleaf logo')
  66. // We can't click the link in component tests, so just look at the
  67. // parent directly
  68. .parent()
  69. .should('be.visible')
  70. .should('have.attr', 'href', '/project')
  71. })
  72. describe('project title menu', function () {
  73. beforeEach(function () {
  74. cy.mount(
  75. <EditorProviders
  76. projectName="My title"
  77. providers={{
  78. EditorProvider: makeEditorProvider({
  79. renameProject: cy.stub().as('rename-project'),
  80. }),
  81. }}
  82. >
  83. <Toolbar />
  84. </EditorProviders>
  85. )
  86. })
  87. it('displays the project title dropdown', function () {
  88. cy.findByRole('button', { name: 'Project title options' })
  89. .should('be.visible')
  90. .should('contain.text', 'My title')
  91. .click()
  92. cy.findByRole('menu')
  93. .should('exist')
  94. .within(() => {
  95. cy.findByRole('menuitem', { name: 'Download as PDF' }).should('exist')
  96. cy.findByRole('menuitem', {
  97. name: 'Download as source (.zip)',
  98. }).should('exist')
  99. cy.findByRole('menuitem', { name: 'Make a copy' }).should('exist')
  100. cy.findByRole('menuitem', { name: 'Rename' }).should('exist')
  101. })
  102. })
  103. it('allows the project to be renamed', function () {
  104. cy.findByRole('button', { name: 'Project title options' }).click()
  105. cy.findByRole('menuitem', { name: 'Rename' }).click()
  106. cy.findByRole('textbox')
  107. .should('be.visible')
  108. .should('have.value', 'My title')
  109. .type('New title{enter}')
  110. cy.get('@rename-project').should('have.been.calledWith', 'New title')
  111. })
  112. it('should show modal when copying project', function () {
  113. cy.findByRole('button', { name: 'Project title options' }).click()
  114. cy.findByRole('menuitem', { name: 'Make a copy' }).click()
  115. cy.findByRole('dialog')
  116. .should('be.visible')
  117. .should('contain.text', 'Copy project')
  118. })
  119. it('should show modal when pressing submit', function () {
  120. cy.findByRole('button', { name: 'Project title options' }).click()
  121. cy.findByRole('menuitem', { name: 'Submit' }).click()
  122. cy.findByRole('dialog')
  123. .should('be.visible')
  124. .should('contain.text', 'Submit')
  125. })
  126. })
  127. describe('history toggle', function () {
  128. it('Should show history button', function () {
  129. cy.mount(
  130. <EditorProviders
  131. projectName="My title"
  132. providers={{
  133. EditorProvider: makeEditorProvider({
  134. isRestrictedTokenMember: false,
  135. }),
  136. }}
  137. >
  138. <Toolbar />
  139. </EditorProviders>
  140. )
  141. cy.findByRole('button', { name: 'History' }).should('be.visible').click()
  142. })
  143. it('Should not show history button to restricted token members', function () {
  144. cy.mount(
  145. <EditorProviders
  146. projectName="My title"
  147. providers={{
  148. EditorProvider: makeEditorProvider({
  149. isRestrictedTokenMember: true,
  150. }),
  151. }}
  152. >
  153. <Toolbar />
  154. </EditorProviders>
  155. )
  156. cy.findByRole('button', { name: 'History' }).should('not.exist')
  157. })
  158. })
  159. it('should show share button', function () {
  160. cy.mount(
  161. <EditorProviders projectName="My title">
  162. <Toolbar />
  163. </EditorProviders>
  164. )
  165. cy.findByRole('button', { name: 'Share' }).should('be.visible').click()
  166. cy.findByRole('dialog')
  167. .should('be.visible')
  168. .should('contain.text', 'Share Project')
  169. })
  170. it('should show layout button', function () {
  171. cy.mount(
  172. <EditorProviders projectName="My title">
  173. <Toolbar />
  174. </EditorProviders>
  175. )
  176. cy.findByRole('button', { name: 'Layout options' })
  177. .should('be.visible')
  178. .click()
  179. cy.findByRole('menu')
  180. .should('exist')
  181. .within(() => {
  182. cy.findByRole('menuitem', { name: 'Split view' }).should('exist')
  183. cy.findByRole('menuitem', { name: 'Editor only' }).should('exist')
  184. cy.findByRole('menuitem', { name: 'PDF only' }).should('exist')
  185. cy.findByRole('menuitem', { name: 'Open PDF in separate tab' }).should(
  186. 'exist'
  187. )
  188. })
  189. })
  190. describe('for non-owner', function () {
  191. it('should disable rename option', function () {
  192. cy.mount(
  193. <EditorProviders permissionsLevel="readOnly">
  194. <Toolbar />
  195. </EditorProviders>
  196. )
  197. cy.findByRole('button', { name: 'Project title options' }).click()
  198. // FIXME: This should really be a button rather than a link
  199. cy.findByRole('menuitem', { name: 'Rename' }).should(
  200. 'have.class',
  201. 'disabled'
  202. )
  203. })
  204. })
  205. describe('menu bar', function () {
  206. beforeEach(function () {
  207. cy.mount(
  208. <EditorProviders>
  209. <Toolbar />
  210. </EditorProviders>
  211. )
  212. })
  213. it('should have a menu bar role', function () {
  214. cy.findByRole('menubar').should('be.visible')
  215. })
  216. it('should show file, view & help', function () {
  217. cy.findByRole('menubar').within(() => {
  218. cy.findByRole('button', { name: 'File' }).should('be.visible')
  219. cy.findByRole('button', { name: 'View' }).should('be.visible')
  220. cy.findByRole('button', { name: 'Help' }).should('be.visible')
  221. })
  222. })
  223. // TODO: Test all the dynamic items
  224. })
  225. })