2020-11-26 09:22:30 -05:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import sinon from 'sinon'
|
2021-05-12 06:31:18 -04:00
|
|
|
import { screen, fireEvent } from '@testing-library/react'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-05-12 06:31:18 -04:00
|
|
|
import {
|
|
|
|
renderWithEditorContext,
|
|
|
|
cleanUpContext,
|
|
|
|
} from '../../../helpers/render-with-context'
|
2020-11-26 09:22:30 -05:00
|
|
|
import FileTreeRoot from '../../../../../frontend/js/features/file-tree/components/file-tree-root'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('FileTree Context Menu Flow', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
const onSelect = sinon.stub()
|
|
|
|
const onInit = sinon.stub()
|
|
|
|
|
2021-05-12 06:31:18 -04:00
|
|
|
afterEach(function () {
|
|
|
|
onSelect.reset()
|
|
|
|
onInit.reset()
|
|
|
|
cleanUpContext()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('opens on contextMenu event', async function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
const rootFolder = [
|
|
|
|
{
|
|
|
|
_id: 'root-folder-id',
|
|
|
|
docs: [{ _id: '456def', name: 'main.tex' }],
|
|
|
|
folders: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
fileRefs: [],
|
|
|
|
},
|
2020-11-26 09:22:30 -05:00
|
|
|
]
|
2021-05-12 06:31:18 -04:00
|
|
|
renderWithEditorContext(
|
2020-11-26 09:22:30 -05:00
|
|
|
<FileTreeRoot
|
|
|
|
rootFolder={rootFolder}
|
|
|
|
projectId="123abc"
|
|
|
|
hasWritePermissions
|
2021-03-24 06:06:56 -04:00
|
|
|
userHasFeature={() => true}
|
2021-03-18 05:52:36 -04:00
|
|
|
refProviders={{}}
|
|
|
|
reindexReferences={() => null}
|
|
|
|
setRefProviderEnabled={() => null}
|
|
|
|
setStartedFreeTrial={() => null}
|
2020-11-26 09:22:30 -05:00
|
|
|
rootDocId="456def"
|
|
|
|
onSelect={onSelect}
|
|
|
|
onInit={onInit}
|
2021-01-14 08:57:33 -05:00
|
|
|
isConnected
|
2020-11-26 09:22:30 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
const treeitem = screen.getByRole('button', { name: 'main.tex' })
|
|
|
|
|
2021-04-29 04:16:42 -04:00
|
|
|
expect(screen.queryByRole('menu')).to.be.null
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
fireEvent.contextMenu(treeitem)
|
|
|
|
|
2021-04-29 04:16:42 -04:00
|
|
|
screen.getByRole('menu')
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it("doesn't open in read only mode", async function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
const rootFolder = [
|
|
|
|
{
|
|
|
|
_id: 'root-folder-id',
|
|
|
|
docs: [{ _id: '456def', name: 'main.tex' }],
|
|
|
|
folders: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
fileRefs: [],
|
|
|
|
},
|
2020-11-26 09:22:30 -05:00
|
|
|
]
|
2021-05-12 06:31:18 -04:00
|
|
|
renderWithEditorContext(
|
2020-11-26 09:22:30 -05:00
|
|
|
<FileTreeRoot
|
|
|
|
rootFolder={rootFolder}
|
|
|
|
projectId="123abc"
|
|
|
|
hasWritePermissions={false}
|
2021-03-24 06:06:56 -04:00
|
|
|
userHasFeature={() => true}
|
2021-03-18 05:52:36 -04:00
|
|
|
refProviders={{}}
|
|
|
|
reindexReferences={() => null}
|
|
|
|
setRefProviderEnabled={() => null}
|
|
|
|
setStartedFreeTrial={() => null}
|
2020-11-26 09:22:30 -05:00
|
|
|
rootDocId="456def"
|
|
|
|
onSelect={onSelect}
|
|
|
|
onInit={onInit}
|
2021-01-14 08:57:33 -05:00
|
|
|
isConnected
|
2020-11-26 09:22:30 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
const treeitem = screen.getByRole('button', { name: 'main.tex' })
|
|
|
|
|
|
|
|
fireEvent.contextMenu(treeitem)
|
|
|
|
|
|
|
|
expect(screen.queryByRole('menu')).to.not.exist
|
|
|
|
})
|
|
|
|
})
|