context-menu.spec.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import FileTreeRoot from '../../../../../frontend/js/features/file-tree/components/file-tree-root'
  2. import { EditorProviders } from '../../../helpers/editor-providers'
  3. describe('FileTree Context Menu Flow', function () {
  4. beforeEach(function () {
  5. cy.window().then(win => {
  6. win.metaAttributesCache.set('ol-user', { id: 'user1' })
  7. })
  8. })
  9. it('opens on contextMenu event', function () {
  10. const rootFolder = [
  11. {
  12. _id: 'root-folder-id',
  13. name: 'rootFolder',
  14. docs: [{ _id: '456def', name: 'main.tex' }],
  15. folders: [],
  16. fileRefs: [],
  17. },
  18. ]
  19. cy.mount(
  20. <EditorProviders
  21. rootFolder={rootFolder as any}
  22. projectId="123abc"
  23. rootDocId="456def"
  24. >
  25. <FileTreeRoot
  26. refProviders={{}}
  27. setRefProviderEnabled={cy.stub()}
  28. setStartedFreeTrial={cy.stub()}
  29. onSelect={cy.stub()}
  30. onInit={cy.stub()}
  31. isConnected
  32. />
  33. </EditorProviders>
  34. )
  35. cy.findByRole('menu').should('not.exist')
  36. cy.findByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  37. cy.findByRole('menu')
  38. })
  39. it('closes when a new selection is started', function () {
  40. const rootFolder = [
  41. {
  42. _id: 'root-folder-id',
  43. name: 'rootFolder',
  44. docs: [
  45. { _id: '456def', name: 'main.tex' },
  46. { _id: '456def', name: 'foo.tex' },
  47. ],
  48. folders: [],
  49. fileRefs: [],
  50. },
  51. ]
  52. cy.mount(
  53. <EditorProviders
  54. rootFolder={rootFolder as any}
  55. projectId="123abc"
  56. rootDocId="456def"
  57. >
  58. <FileTreeRoot
  59. refProviders={{}}
  60. setRefProviderEnabled={cy.stub()}
  61. setStartedFreeTrial={cy.stub()}
  62. onSelect={cy.stub()}
  63. onInit={cy.stub()}
  64. isConnected
  65. />
  66. </EditorProviders>
  67. )
  68. cy.findByRole('menu').should('not.exist')
  69. cy.findByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  70. cy.findByRole('menu')
  71. cy.findAllByRole('button', { name: 'foo.tex' }).click()
  72. cy.findByRole('menu').should('not.exist')
  73. })
  74. it("doesn't open in read only mode", function () {
  75. const rootFolder = [
  76. {
  77. _id: 'root-folder-id',
  78. name: 'rootFolder',
  79. docs: [{ _id: '456def', name: 'main.tex' }],
  80. folders: [],
  81. fileRefs: [],
  82. },
  83. ]
  84. cy.mount(
  85. <EditorProviders
  86. rootFolder={rootFolder as any}
  87. projectId="123abc"
  88. rootDocId="456def"
  89. permissionsLevel="readOnly"
  90. >
  91. <FileTreeRoot
  92. refProviders={{}}
  93. setRefProviderEnabled={cy.stub()}
  94. setStartedFreeTrial={cy.stub()}
  95. onSelect={cy.stub()}
  96. onInit={cy.stub()}
  97. isConnected
  98. />
  99. </EditorProviders>
  100. )
  101. cy.findAllByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  102. cy.findByRole('menu').should('not.exist')
  103. })
  104. it('shows "set main document" item when appropriate', function () {
  105. const rootFolder = [
  106. {
  107. _id: 'root-folder-id',
  108. name: 'rootFolder',
  109. docs: [
  110. { _id: 'main-doc', name: 'main.tex' },
  111. { _id: 'other-doc', name: 'other.tex' },
  112. ],
  113. folders: [],
  114. fileRefs: [],
  115. },
  116. ]
  117. cy.mount(
  118. <EditorProviders
  119. rootFolder={rootFolder as any}
  120. projectId="123abc"
  121. rootDocId="main-doc"
  122. >
  123. <FileTreeRoot
  124. refProviders={{}}
  125. setRefProviderEnabled={cy.stub()}
  126. setStartedFreeTrial={cy.stub()}
  127. onSelect={cy.stub()}
  128. onInit={cy.stub()}
  129. isConnected
  130. />
  131. </EditorProviders>
  132. )
  133. cy.findByRole('menu').should('not.exist')
  134. // main.tex is already the main document
  135. cy.findByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  136. cy.findByRole('menu')
  137. .findByRole('menuitem', { name: 'Set as main document' })
  138. .should('not.exist')
  139. // set other.tex as the main document
  140. cy.findByRole('button', { name: 'other.tex' }).click({ force: true })
  141. cy.findByRole('button', { name: 'other.tex' }).trigger('contextmenu')
  142. cy.intercept('POST', '/project/123abc/settings', { statusCode: 204 }).as(
  143. 'update-settings'
  144. )
  145. cy.findByRole('menu')
  146. .findByRole('menuitem', { name: 'Set as main document' })
  147. .click()
  148. cy.wait('@update-settings')
  149. .its('request.body.rootDocId')
  150. .should('eq', 'other-doc')
  151. // main.tex is now not the main document
  152. cy.findByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  153. cy.findByRole('menu').findByRole('menuitem', {
  154. name: 'Set as main document',
  155. })
  156. })
  157. })