mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
7c97f8ab6e
* Use new JSX runtime and update Babel Node target * Update .eslintrc * Remove React imports GitOrigin-RevId: 559de0267f8f2934c56a860ea8701bb522aa861a
86 lines
2.2 KiB
JavaScript
86 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',
|
|
docs: [{ _id: '456def', name: 'main.tex' }],
|
|
folders: [],
|
|
fileRefs: [],
|
|
},
|
|
]
|
|
renderWithEditorContext(
|
|
<FileTreeRoot
|
|
rootFolder={rootFolder}
|
|
projectId="123abc"
|
|
hasWritePermissions
|
|
userHasFeature={() => true}
|
|
refProviders={{}}
|
|
reindexReferences={() => null}
|
|
setRefProviderEnabled={() => null}
|
|
setStartedFreeTrial={() => null}
|
|
rootDocId="456def"
|
|
onSelect={onSelect}
|
|
onInit={onInit}
|
|
isConnected
|
|
/>
|
|
)
|
|
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',
|
|
docs: [{ _id: '456def', name: 'main.tex' }],
|
|
folders: [],
|
|
fileRefs: [],
|
|
},
|
|
]
|
|
renderWithEditorContext(
|
|
<FileTreeRoot
|
|
rootFolder={rootFolder}
|
|
projectId="123abc"
|
|
hasWritePermissions={false}
|
|
userHasFeature={() => true}
|
|
refProviders={{}}
|
|
reindexReferences={() => null}
|
|
setRefProviderEnabled={() => null}
|
|
setStartedFreeTrial={() => null}
|
|
rootDocId="456def"
|
|
onSelect={onSelect}
|
|
onInit={onInit}
|
|
isConnected
|
|
/>
|
|
)
|
|
const treeitem = screen.getByRole('button', { name: 'main.tex' })
|
|
|
|
fireEvent.contextMenu(treeitem)
|
|
|
|
expect(screen.queryByRole('menu')).to.not.exist
|
|
})
|
|
})
|