context-menu.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. reindexReferences={cy.stub()}
  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. reindexReferences={cy.stub()}
  62. setRefProviderEnabled={cy.stub()}
  63. setStartedFreeTrial={cy.stub()}
  64. onSelect={cy.stub()}
  65. onInit={cy.stub()}
  66. isConnected
  67. />
  68. </EditorProviders>
  69. )
  70. cy.findByRole('menu').should('not.exist')
  71. cy.findByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  72. cy.findByRole('menu')
  73. cy.findAllByRole('button', { name: 'foo.tex' }).click()
  74. cy.findByRole('menu').should('not.exist')
  75. })
  76. it("doesn't open in read only mode", function () {
  77. const rootFolder = [
  78. {
  79. _id: 'root-folder-id',
  80. name: 'rootFolder',
  81. docs: [{ _id: '456def', name: 'main.tex' }],
  82. folders: [],
  83. fileRefs: [],
  84. },
  85. ]
  86. cy.mount(
  87. <EditorProviders
  88. rootFolder={rootFolder as any}
  89. projectId="123abc"
  90. rootDocId="456def"
  91. permissionsLevel="readOnly"
  92. >
  93. <FileTreeRoot
  94. refProviders={{}}
  95. reindexReferences={cy.stub()}
  96. setRefProviderEnabled={cy.stub()}
  97. setStartedFreeTrial={cy.stub()}
  98. onSelect={cy.stub()}
  99. onInit={cy.stub()}
  100. isConnected
  101. />
  102. </EditorProviders>
  103. )
  104. cy.findAllByRole('button', { name: 'main.tex' }).trigger('contextmenu')
  105. cy.findByRole('menu').should('not.exist')
  106. })
  107. })