mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #3640 from overleaf/ta-file-tree-input-draggable
[ReactFileTree] Disable Draggable when Renaming Entity GitOrigin-RevId: 7241815d43791685453431aa95b8258ec17d3f81
This commit is contained in:
+43
-7
@@ -7,23 +7,38 @@ import renderWithContext from '../../helpers/render-with-context'
|
||||
import FileTreeItemName from '../../../../../../frontend/js/features/file-tree/components/file-tree-item/file-tree-item-name'
|
||||
|
||||
describe('<FileTreeItemName />', function() {
|
||||
const setIsDraggable = sinon.stub()
|
||||
|
||||
beforeEach(function() {
|
||||
global.requestAnimationFrame = sinon.stub()
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
delete global.requestAnimationFrame
|
||||
setIsDraggable.reset()
|
||||
})
|
||||
|
||||
it('renders name as button', function() {
|
||||
renderWithContext(<FileTreeItemName name="foo.tex" isSelected />)
|
||||
renderWithContext(
|
||||
<FileTreeItemName
|
||||
name="foo.tex"
|
||||
isSelected
|
||||
setIsDraggable={setIsDraggable}
|
||||
/>
|
||||
)
|
||||
|
||||
screen.getByRole('button', { name: 'foo.tex' })
|
||||
expect(screen.queryByRole('textbox')).to.not.exist
|
||||
})
|
||||
|
||||
it("doesn't start renaming on unselected component", function() {
|
||||
renderWithContext(<FileTreeItemName name="foo.tex" isSelected={false} />)
|
||||
renderWithContext(
|
||||
<FileTreeItemName
|
||||
name="foo.tex"
|
||||
isSelected={false}
|
||||
setIsDraggable={setIsDraggable}
|
||||
/>
|
||||
)
|
||||
|
||||
const button = screen.queryByRole('button')
|
||||
fireEvent.click(button)
|
||||
@@ -33,7 +48,13 @@ describe('<FileTreeItemName />', function() {
|
||||
})
|
||||
|
||||
it('start renaming on double-click', function() {
|
||||
renderWithContext(<FileTreeItemName name="foo.tex" isSelected />)
|
||||
renderWithContext(
|
||||
<FileTreeItemName
|
||||
name="foo.tex"
|
||||
isSelected
|
||||
setIsDraggable={setIsDraggable}
|
||||
/>
|
||||
)
|
||||
|
||||
const button = screen.queryByRole('button')
|
||||
fireEvent.click(button)
|
||||
@@ -42,12 +63,20 @@ describe('<FileTreeItemName />', function() {
|
||||
screen.getByRole('textbox')
|
||||
expect(screen.queryByRole('button')).to.not.exist
|
||||
expect(global.requestAnimationFrame).to.be.calledOnce
|
||||
expect(setIsDraggable).to.be.calledWith(false)
|
||||
})
|
||||
|
||||
it('cannot start renaming in read-only', function() {
|
||||
renderWithContext(<FileTreeItemName name="foo.tex" isSelected />, {
|
||||
contextProps: { hasWritePermissions: false }
|
||||
})
|
||||
renderWithContext(
|
||||
<FileTreeItemName
|
||||
name="foo.tex"
|
||||
isSelected
|
||||
setIsDraggable={setIsDraggable}
|
||||
/>,
|
||||
{
|
||||
contextProps: { hasWritePermissions: false }
|
||||
}
|
||||
)
|
||||
|
||||
const button = screen.queryByRole('button')
|
||||
fireEvent.click(button)
|
||||
@@ -59,7 +88,13 @@ describe('<FileTreeItemName />', function() {
|
||||
|
||||
describe('stop renaming', function() {
|
||||
beforeEach(function() {
|
||||
renderWithContext(<FileTreeItemName name="foo.tex" isSelected />)
|
||||
renderWithContext(
|
||||
<FileTreeItemName
|
||||
name="foo.tex"
|
||||
isSelected
|
||||
setIsDraggable={setIsDraggable}
|
||||
/>
|
||||
)
|
||||
|
||||
const button = screen.getByRole('button')
|
||||
fireEvent.click(button)
|
||||
@@ -75,6 +110,7 @@ describe('<FileTreeItemName />', function() {
|
||||
fireEvent.keyDown(input, { key: 'Escape' })
|
||||
|
||||
screen.getByRole('button', { name: 'foo.tex' })
|
||||
expect(setIsDraggable).to.be.calledWith(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user