mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-10 03:03:22 -05:00
283 lines
8.3 KiB
TypeScript
283 lines
8.3 KiB
TypeScript
|
// @ts-ignore
|
||
|
import MockedSocket from 'socket.io-mock'
|
||
|
import FileTreeRoot from '../../../../../frontend/js/features/file-tree/components/file-tree-root'
|
||
|
import { EditorProviders } from '../../../helpers/editor-providers'
|
||
|
|
||
|
describe('FileTree Delete Entity Flow', function () {
|
||
|
beforeEach(function () {
|
||
|
cy.window().then(win => {
|
||
|
win.metaAttributesCache.set('ol-user', { id: 'user1' })
|
||
|
})
|
||
|
})
|
||
|
|
||
|
describe('single entity', function () {
|
||
|
beforeEach(function () {
|
||
|
const rootFolder = [
|
||
|
{
|
||
|
_id: 'root-folder-id',
|
||
|
name: 'rootFolder',
|
||
|
docs: [
|
||
|
{ _id: '123abc', name: 'foo.tex' },
|
||
|
{ _id: '456def', name: 'main.tex' },
|
||
|
],
|
||
|
folders: [],
|
||
|
fileRefs: [],
|
||
|
},
|
||
|
]
|
||
|
|
||
|
cy.mount(
|
||
|
<EditorProviders
|
||
|
rootFolder={rootFolder as any}
|
||
|
projectId="123abc"
|
||
|
socket={new MockedSocket()}
|
||
|
>
|
||
|
<FileTreeRoot
|
||
|
refProviders={{}}
|
||
|
reindexReferences={cy.stub().as('reindexReferences')}
|
||
|
setRefProviderEnabled={cy.stub()}
|
||
|
setStartedFreeTrial={cy.stub()}
|
||
|
onSelect={cy.stub()}
|
||
|
onInit={cy.stub()}
|
||
|
isConnected
|
||
|
/>
|
||
|
</EditorProviders>
|
||
|
)
|
||
|
|
||
|
cy.findByRole('treeitem', { name: 'main.tex' }).click()
|
||
|
cy.findByRole('button', { name: 'Menu' }).click()
|
||
|
cy.findByRole('menuitem', { name: 'Delete' }).click()
|
||
|
})
|
||
|
|
||
|
it('removes item', function () {
|
||
|
cy.intercept('delete', '/project/*/doc/*', { statusCode: 204 }).as(
|
||
|
'deleteDoc'
|
||
|
)
|
||
|
|
||
|
// check that the confirmation modal is open
|
||
|
cy.findByText(
|
||
|
'Are you sure you want to permanently delete the following files?'
|
||
|
)
|
||
|
|
||
|
cy.findByRole('button', { name: 'Delete' }).click()
|
||
|
|
||
|
cy.wait('@deleteDoc')
|
||
|
|
||
|
cy.window().then(win => {
|
||
|
// @ts-ignore
|
||
|
win._ide.socket.socketClient.emit('removeEntity', '456def')
|
||
|
})
|
||
|
|
||
|
cy.findByRole('treeitem', {
|
||
|
name: 'main.tex',
|
||
|
hidden: true, // treeitem might be hidden behind the modal
|
||
|
}).should('not.exist')
|
||
|
|
||
|
cy.findByRole('treeitem', {
|
||
|
name: 'main.tex',
|
||
|
}).should('not.exist')
|
||
|
|
||
|
// check that the confirmation modal is closed
|
||
|
cy.findByText(
|
||
|
'Are you sure you want to permanently delete the following files?'
|
||
|
).should('not.exist')
|
||
|
|
||
|
cy.get('@deleteDoc.all').should('have.length', 1)
|
||
|
cy.get('@reindexReferences').should('not.have.been.called')
|
||
|
})
|
||
|
|
||
|
it('continues delete on 404s', function () {
|
||
|
cy.intercept('delete', '/project/*/doc/*', { statusCode: 404 }).as(
|
||
|
'deleteDoc'
|
||
|
)
|
||
|
|
||
|
// check that the confirmation modal is open
|
||
|
cy.findByText(
|
||
|
'Are you sure you want to permanently delete the following files?'
|
||
|
)
|
||
|
|
||
|
cy.findByRole('button', { name: 'Delete' }).click()
|
||
|
|
||
|
cy.window().then(win => {
|
||
|
// @ts-ignore
|
||
|
win._ide.socket.socketClient.emit('removeEntity', '456def')
|
||
|
})
|
||
|
|
||
|
cy.findByRole('treeitem', {
|
||
|
name: 'main.tex',
|
||
|
hidden: true, // treeitem might be hidden behind the modal
|
||
|
}).should('not.exist')
|
||
|
|
||
|
cy.findByRole('treeitem', {
|
||
|
name: 'main.tex',
|
||
|
}).should('not.exist')
|
||
|
|
||
|
// check that the confirmation modal is closed
|
||
|
// is not, the 404 probably triggered a bug
|
||
|
cy.findByText(
|
||
|
'Are you sure you want to permanently delete the following files?'
|
||
|
).should('not.exist')
|
||
|
})
|
||
|
|
||
|
it('aborts delete on error', function () {
|
||
|
cy.intercept('delete', '/project/*/doc/*', { statusCode: 500 }).as(
|
||
|
'deleteDoc'
|
||
|
)
|
||
|
|
||
|
cy.findByRole('button', { name: 'Delete' }).click()
|
||
|
|
||
|
// The modal should still be open, but the file should not be deleted
|
||
|
cy.findByRole('treeitem', { name: 'main.tex', hidden: true })
|
||
|
})
|
||
|
})
|
||
|
|
||
|
describe('folders', function () {
|
||
|
beforeEach(function () {
|
||
|
const rootFolder = [
|
||
|
{
|
||
|
_id: 'root-folder-id',
|
||
|
name: 'rootFolder',
|
||
|
docs: [{ _id: '456def', name: 'main.tex' }],
|
||
|
folders: [
|
||
|
{
|
||
|
_id: '123abc',
|
||
|
name: 'folder',
|
||
|
docs: [],
|
||
|
folders: [],
|
||
|
fileRefs: [{ _id: '789ghi', name: 'my.bib' }],
|
||
|
},
|
||
|
],
|
||
|
fileRefs: [],
|
||
|
},
|
||
|
]
|
||
|
|
||
|
cy.mount(
|
||
|
<EditorProviders
|
||
|
rootFolder={rootFolder as any}
|
||
|
projectId="123abc"
|
||
|
socket={new MockedSocket()}
|
||
|
>
|
||
|
<FileTreeRoot
|
||
|
refProviders={{}}
|
||
|
reindexReferences={cy.stub().as('reindexReferences')}
|
||
|
setRefProviderEnabled={cy.stub()}
|
||
|
setStartedFreeTrial={cy.stub()}
|
||
|
onSelect={cy.stub()}
|
||
|
onInit={cy.stub()}
|
||
|
isConnected
|
||
|
/>
|
||
|
</EditorProviders>
|
||
|
)
|
||
|
|
||
|
cy.findByRole('button', { name: 'Expand' }).click()
|
||
|
cy.findByRole('treeitem', { name: 'main.tex' }).click()
|
||
|
cy.findByRole('treeitem', { name: 'my.bib' }).click({
|
||
|
ctrlKey: true,
|
||
|
cmdKey: true,
|
||
|
})
|
||
|
|
||
|
cy.window().then(win => {
|
||
|
// @ts-ignore
|
||
|
win._ide.socket.socketClient.emit('removeEntity', '123abc')
|
||
|
})
|
||
|
})
|
||
|
|
||
|
it('removes the folder', function () {
|
||
|
cy.findByRole('treeitem', { name: 'folder' }).should('not.exist')
|
||
|
})
|
||
|
|
||
|
it('leaves the main file selected', function () {
|
||
|
cy.findByRole('treeitem', { name: 'main.tex', selected: true })
|
||
|
})
|
||
|
|
||
|
it('unselect the child entity', function () {
|
||
|
// as a proxy to check that the child entity has been unselect we start
|
||
|
// a delete and ensure the modal is displayed (the cancel button can be
|
||
|
// selected) This is needed to make sure the test fail.
|
||
|
cy.findByRole('button', { name: 'Menu' }).click()
|
||
|
cy.findByRole('menuitem', { name: 'Delete' }).click()
|
||
|
cy.findByRole('button', { name: 'Cancel' })
|
||
|
})
|
||
|
})
|
||
|
|
||
|
describe('multiple entities', function () {
|
||
|
beforeEach(function () {
|
||
|
const rootFolder = [
|
||
|
{
|
||
|
_id: 'root-folder-id',
|
||
|
name: 'rootFolder',
|
||
|
docs: [{ _id: '456def', name: 'main.tex' }],
|
||
|
folders: [],
|
||
|
fileRefs: [{ _id: '789ghi', name: 'my.bib' }],
|
||
|
},
|
||
|
]
|
||
|
|
||
|
cy.mount(
|
||
|
<EditorProviders
|
||
|
rootFolder={rootFolder as any}
|
||
|
projectId="123abc"
|
||
|
socket={new MockedSocket()}
|
||
|
>
|
||
|
<FileTreeRoot
|
||
|
refProviders={{}}
|
||
|
reindexReferences={cy.stub().as('reindexReferences')}
|
||
|
setRefProviderEnabled={cy.stub()}
|
||
|
setStartedFreeTrial={cy.stub()}
|
||
|
onSelect={cy.stub()}
|
||
|
onInit={cy.stub()}
|
||
|
isConnected
|
||
|
/>
|
||
|
</EditorProviders>
|
||
|
)
|
||
|
|
||
|
// select two files
|
||
|
cy.findByRole('treeitem', { name: 'main.tex' }).click()
|
||
|
cy.findByRole('treeitem', { name: 'my.bib' }).click({
|
||
|
ctrlKey: true,
|
||
|
cmdKey: true,
|
||
|
})
|
||
|
|
||
|
// open the context menu
|
||
|
cy.findByRole('button', { name: 'my.bib' }).trigger('contextmenu')
|
||
|
|
||
|
// make sure the menu has opened, with only a "Delete" item (as multiple files are selected)
|
||
|
cy.findByRole('menu')
|
||
|
cy.findAllByRole('menuitem').should('have.length', 1)
|
||
|
|
||
|
// select the Delete menu item
|
||
|
cy.findByRole('menuitem', { name: 'Delete' }).click()
|
||
|
})
|
||
|
|
||
|
it('removes all items and reindexes references after deleting .bib file', function () {
|
||
|
cy.intercept('delete', '/project/123abc/doc/456def', {
|
||
|
statusCode: 204,
|
||
|
}).as('deleteDoc')
|
||
|
|
||
|
cy.intercept('delete', '/project/123abc/file/789ghi', {
|
||
|
statusCode: 204,
|
||
|
}).as('deleteFile')
|
||
|
|
||
|
cy.findByRole('button', { name: 'Delete' }).click()
|
||
|
|
||
|
cy.window().then(win => {
|
||
|
// @ts-ignore
|
||
|
win._ide.socket.socketClient.emit('removeEntity', '456def')
|
||
|
// @ts-ignore
|
||
|
win._ide.socket.socketClient.emit('removeEntity', '789ghi')
|
||
|
})
|
||
|
|
||
|
for (const name of ['main.tex', 'my.bib']) {
|
||
|
for (const hidden of [true, false]) {
|
||
|
cy.findByRole('treeitem', { name, hidden }).should('not.exist')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check that the confirmation modal is closed
|
||
|
cy.findByText('Are you sure').should('not.exist')
|
||
|
|
||
|
cy.get('@deleteDoc.all').should('have.length', 1)
|
||
|
cy.get('@deleteFile.all').should('have.length', 1)
|
||
|
cy.get('@reindexReferences').should('have.been.calledOnce')
|
||
|
})
|
||
|
})
|
||
|
})
|