2020-11-26 09:22:30 -05:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
import { screen, fireEvent } from '@testing-library/react'
|
|
|
|
import renderWithContext from '../../helpers/render-with-context'
|
|
|
|
|
|
|
|
import FileTreeitemInner from '../../../../../../frontend/js/features/file-tree/components/file-tree-item/file-tree-item-inner'
|
2021-04-29 04:16:42 -04:00
|
|
|
import FileTreeContextMenu from '../../../../../../frontend/js/features/file-tree/components/file-tree-context-menu'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('<FileTreeitemInner />', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
const setContextMenuCoords = sinon.stub()
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
global.requestAnimationFrame = sinon.stub()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
afterEach(function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
setContextMenuCoords.reset()
|
|
|
|
delete global.requestAnimationFrame
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('menu', function () {
|
|
|
|
it('does not display if file is not selected', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeitemInner id="123abc" name="bar.tex" isSelected={false} />,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(screen.queryByRole('menu', { visible: false })).to.not.exist
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('context menu', function () {
|
|
|
|
it('does not display without write permissions', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeitemInner id="123abc" name="bar.tex" isSelected />,
|
|
|
|
{ contextProps: { hasWritePermissions: false } }
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(screen.queryByRole('menu', { visible: false })).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('open / close', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
const { container } = renderWithContext(
|
2021-04-29 04:16:42 -04:00
|
|
|
<>
|
|
|
|
<FileTreeitemInner id="123abc" name="bar.tex" isSelected />
|
|
|
|
<FileTreeContextMenu />
|
|
|
|
</>
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
|
|
|
|
2021-04-29 04:16:42 -04:00
|
|
|
expect(screen.queryByRole('menu')).to.be.null
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-04-29 04:16:42 -04:00
|
|
|
// open the context menu
|
|
|
|
const entityElement = container.querySelector('div.entity')
|
2020-11-26 09:22:30 -05:00
|
|
|
fireEvent.contextMenu(entityElement)
|
|
|
|
screen.getByRole('menu', { visible: true })
|
|
|
|
|
2021-04-29 04:16:42 -04:00
|
|
|
// close the context menu
|
|
|
|
fireEvent.click(entityElement)
|
|
|
|
expect(screen.queryByRole('menu')).to.be.null
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('name', function () {
|
|
|
|
it('renders name', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeitemInner id="123abc" name="bar.tex" isSelected />
|
|
|
|
)
|
|
|
|
|
|
|
|
screen.getByRole('button', { name: 'bar.tex' })
|
|
|
|
expect(screen.queryByRole('textbox')).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('starts rename on menu item click', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeitemInner id="123abc" name="bar.tex" isSelected />,
|
2021-01-08 05:03:10 -05:00
|
|
|
{
|
|
|
|
contextProps: {
|
|
|
|
rootDocId: '123abc',
|
|
|
|
rootFolder: [
|
|
|
|
{
|
|
|
|
_id: 'root-folder-id',
|
|
|
|
docs: [{ _id: '123abc', name: 'bar.tex' }],
|
|
|
|
folders: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
fileRefs: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-01-08 05:03:10 -05:00
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
2021-04-29 04:16:42 -04:00
|
|
|
const toggleButton = screen.getByRole('button', { name: 'Menu' })
|
|
|
|
fireEvent.click(toggleButton)
|
2020-11-26 09:22:30 -05:00
|
|
|
const renameButton = screen.getByRole('menuitem', { name: 'Rename' })
|
|
|
|
fireEvent.click(renameButton)
|
|
|
|
expect(screen.queryByRole('button', { name: 'bar.tex' })).to.not.exist
|
|
|
|
screen.getByRole('textbox')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|