context-menu.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import '../../../helpers/bootstrap-3'
  2. import FileTreeRoot from '../../../../../frontend/js/features/file-tree/components/file-tree-root'
  3. import { EditorProviders } from '../../../helpers/editor-providers'
  4. describe('FileTree Context Menu Flow', function () {
  5. beforeEach(function () {
  6. cy.window().then(win => {
  7. win.metaAttributesCache.set('ol-user', { id: 'user1' })
  8. })
  9. })
  10. it('opens on contextMenu event', function () {
  11. const rootFolder = [
  12. {
  13. _id: 'root-folder-id',
  14. name: 'rootFolder',
  15. docs: [{ _id: '456def', name: 'main.tex' }],
  16. folders: [],
  17. fileRefs: [],
  18. },
  19. ]
  20. cy.mount(
  21. <EditorProviders
  22. rootFolder={rootFolder as any}
  23. projectId="123abc"
  24. rootDocId="456def"
  25. >
  26. <FileTreeRoot
  27. refProviders={{}}
  28. setRefProviderEnabled={cy.stub()}
  29. setStartedFreeTrial={cy.stub()}
  30. onSelect={cy.stub()}
  31. onInit={cy.stub()}
  32. isConnected
  33. />
  34. </EditorProviders>
  35. )
  36. cy.findByRole('menu').should('not.exist')
  37. cy.findByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  38. cy.findByRole('menu')
  39. })
  40. it('closes when a new selection is started', function () {
  41. const rootFolder = [
  42. {
  43. _id: 'root-folder-id',
  44. name: 'rootFolder',
  45. docs: [
  46. { _id: '456def', name: 'main.tex' },
  47. { _id: '456def', name: 'foo.tex' },
  48. ],
  49. folders: [],
  50. fileRefs: [],
  51. },
  52. ]
  53. cy.mount(
  54. <EditorProviders
  55. rootFolder={rootFolder as any}
  56. projectId="123abc"
  57. rootDocId="456def"
  58. >
  59. <FileTreeRoot
  60. refProviders={{}}
  61. setRefProviderEnabled={cy.stub()}
  62. setStartedFreeTrial={cy.stub()}
  63. onSelect={cy.stub()}
  64. onInit={cy.stub()}
  65. isConnected
  66. />
  67. </EditorProviders>
  68. )
  69. cy.findByRole('menu').should('not.exist')
  70. cy.findByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  71. cy.findByRole('menu')
  72. cy.findAllByRole('button', { name: 'foo.tex' }).click()
  73. cy.findByRole('menu').should('not.exist')
  74. })
  75. it("doesn't open in read only mode", function () {
  76. const rootFolder = [
  77. {
  78. _id: 'root-folder-id',
  79. name: 'rootFolder',
  80. docs: [{ _id: '456def', name: 'main.tex' }],
  81. folders: [],
  82. fileRefs: [],
  83. },
  84. ]
  85. cy.mount(
  86. <EditorProviders
  87. rootFolder={rootFolder as any}
  88. projectId="123abc"
  89. rootDocId="456def"
  90. permissionsLevel="readOnly"
  91. >
  92. <FileTreeRoot
  93. refProviders={{}}
  94. setRefProviderEnabled={cy.stub()}
  95. setStartedFreeTrial={cy.stub()}
  96. onSelect={cy.stub()}
  97. onInit={cy.stub()}
  98. isConnected
  99. />
  100. </EditorProviders>
  101. )
  102. cy.findAllByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  103. cy.findByRole('menu').should('not.exist')
  104. })
  105. })