overleaf/services/web/test/frontend/features/file-tree/flows/context-menu.test.js
Timothée Alby 24bd557485 Merge pull request #6210 from overleaf/ta-file-tree-data-in-context
Remove rootFolder from EditorContext

GitOrigin-RevId: 827b046046265ad2418eb91d5a69eae02aa8b5a4
2022-01-11 09:04:56 +00:00

89 lines
2.2 KiB
JavaScript

import { expect } from 'chai'
import sinon from 'sinon'
import { screen, fireEvent } from '@testing-library/react'
import {
renderWithEditorContext,
cleanUpContext,
} from '../../../helpers/render-with-context'
import FileTreeRoot from '../../../../../frontend/js/features/file-tree/components/file-tree-root'
describe('FileTree Context Menu Flow', function () {
const onSelect = sinon.stub()
const onInit = sinon.stub()
afterEach(function () {
onSelect.reset()
onInit.reset()
cleanUpContext()
})
it('opens on contextMenu event', async function () {
const rootFolder = [
{
_id: 'root-folder-id',
name: 'rootFolder',
docs: [{ _id: '456def', name: 'main.tex' }],
folders: [],
fileRefs: [],
},
]
renderWithEditorContext(
<FileTreeRoot
refProviders={{}}
reindexReferences={() => null}
setRefProviderEnabled={() => null}
setStartedFreeTrial={() => null}
onSelect={onSelect}
onInit={onInit}
isConnected
/>,
{
rootFolder,
projectId: '123abc',
rootDocId: '456def',
}
)
const treeitem = screen.getByRole('button', { name: 'main.tex' })
expect(screen.queryByRole('menu')).to.be.null
fireEvent.contextMenu(treeitem)
screen.getByRole('menu')
})
it("doesn't open in read only mode", async function () {
const rootFolder = [
{
_id: 'root-folder-id',
name: 'rootFolder',
docs: [{ _id: '456def', name: 'main.tex' }],
folders: [],
fileRefs: [],
},
]
renderWithEditorContext(
<FileTreeRoot
refProviders={{}}
reindexReferences={() => null}
setRefProviderEnabled={() => null}
setStartedFreeTrial={() => null}
onSelect={onSelect}
onInit={onInit}
isConnected
/>,
{
rootFolder,
projectId: '123abc',
rootDocId: '456def',
permissionsLevel: 'readOnly',
}
)
const treeitem = screen.getByRole('button', { name: 'main.tex' })
fireEvent.contextMenu(treeitem)
expect(screen.queryByRole('menu')).to.not.exist
})
})