mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
b9a6e7009d
* Tidy up menu button * Unselect all items when clicking in the file tree root * Close the context menu when selecting a new item * Avoid selecting multiple items with Ctrl+click on macOS GitOrigin-RevId: b67a724909668ec13d7a6d09ffc31574cb42238f
134 lines
3.3 KiB
JavaScript
134 lines
3.3 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()
|
|
|
|
beforeEach(function () {
|
|
window.metaAttributesCache = new Map()
|
|
window.metaAttributesCache.set('ol-user', { id: 'user1' })
|
|
})
|
|
|
|
afterEach(function () {
|
|
onSelect.reset()
|
|
onInit.reset()
|
|
cleanUpContext()
|
|
window.metaAttributesCache = new Map()
|
|
})
|
|
|
|
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('closes when a new selection is started', async function () {
|
|
const rootFolder = [
|
|
{
|
|
_id: 'root-folder-id',
|
|
name: 'rootFolder',
|
|
docs: [
|
|
{ _id: '456def', name: 'main.tex' },
|
|
{ _id: '456def', name: 'foo.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')
|
|
|
|
screen.getByRole('button', { name: 'foo.tex' }).click()
|
|
expect(screen.queryByRole('menu')).to.be.null
|
|
})
|
|
|
|
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
|
|
})
|
|
})
|