Skip to content

Commit 7cfed79

Browse files
committed
move drag and drop tests to documents and collections specs
1 parent 31567c6 commit 7cfed79

File tree

3 files changed

+560
-466
lines changed

3 files changed

+560
-466
lines changed
Lines changed: 253 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,275 @@
11
/// <reference types="Cypress" />
2+
import { FSApi } from '../../fusion-studio-extension/src/common/api';
23

34
context('Document Operations', () => {
45
describe('working with tree view', () => {
6+
let fetchSpy;
7+
const connection = {
8+
server: Cypress.env('API_HOST'),
9+
username: 'admin',
10+
password: '',
11+
};
512
before(() => {
13+
new Cypress.Promise(async resolve => {
14+
await FSApi.remove(connection, '/db/test', true).catch(e => { });
15+
await FSApi.newCollection(connection, '/db/test');
16+
await FSApi.newCollection(connection, '/db/test/col1');
17+
await FSApi.save(connection, '/db/test/col1/doc1', '');
18+
await FSApi.save(connection, '/db/test/col1/doc2', '');
19+
resolve();
20+
})
621
cy.connect()
7-
cy.visit('/')
22+
cy.visit('/', {
23+
onBeforeLoad: win => fetchSpy = cy.spy(win, 'fetch'),
24+
})
825
cy.get(`[node-id=${CSS.escape('admin@' + Cypress.env('API_HOST'))}]`)
9-
// TODO(DP): might have to improve by adding more before / after hooks to prevent dangling documents
10-
// see #400
26+
// TODO(DP): might have to improve by adding more before / after hooks to prevent dangling documents
27+
// see #400
28+
})
29+
after(() => {
30+
// delete the test colelction
31+
// new Cypress.Promise(resolve => FSApi.remove(connection, '/db/test', true).then(resolve).catch(resolve))
1132
})
33+
it('should display creation options', () => {
34+
cy.get('.fusion-view', { timeout: 55000 })
35+
.should('be.visible')
36+
cy.get('.fusion-item')
37+
.click()
38+
// (DP): start workaround for #413
39+
cy.get('[node-id$=db]')
40+
.click()
41+
.prev().should('not.have.class', 'fa-spin').wait(1)
42+
// (DP): end workaround for #413
43+
// all we need is the final part of the node-id attribute
44+
cy.get('[node-id$=test]')
45+
.click()
46+
.prev().should('not.have.class', 'fa-spin').wait(1)
47+
cy.get('[node-id$=test]')
48+
.rightclick()
49+
cy.get('.p-Menu')
50+
.should('be.visible')
51+
.contains('New document...')
52+
.trigger('mousemove')
53+
cy.get('[data-command="fusion.new-document"]')
54+
.contains('Empty document')
55+
.click()
56+
cy.focused()
57+
.type('untitled_1{enter}')
58+
cy.get('.fusion-view')
59+
.contains('untitled_1')
1260

13-
describe('db context menu', () => {
14-
it('should display creation options', () => {
15-
cy.get('.ReactVirtualized__Grid', { timeout: 55000 })
16-
.should('be.visible')
17-
cy.get('.fusion-item')
18-
.click()
19-
// all we need is the final part of the node-id attribute
20-
cy.get('[node-id$=db]')
21-
.rightclick()
22-
.then(() => {
23-
cy.get('.p-Menu')
24-
.should('be.visible')
25-
.contains('New document')
26-
.trigger('mousemove')
27-
cy.get('[data-command="fusion.new-document"] > .p-Menu-itemLabel')
28-
.should('be.visible')
29-
.click()
30-
})
31-
// (DP): start workaround for #413
32-
cy.get('[node-id$=db]')
33-
.trigger('mousemove')
34-
.type('{enter}')
35-
// end workaround for #413
36-
cy.get('.ReactVirtualized__Grid')
37-
.contains('untitled-1')
61+
// TODO(DP):
62+
// - add test for #413 : change order, remove workaround, might need a call to focused()
63+
// - check if tree view is deselected (it is but need not be),
64+
// - check if Explorer is updated properly (seems inconsistent need to double click)
65+
// - check if editor window is opening the newly create doc in a new tab (it doesn't)
66+
// - two doc create routes one with follow-up dialog (xquery lib) one without (txt, xml)
67+
})
3868

39-
// TODO(DP):
40-
// - add test for #413 : change order, remove workaround, might need a call to focused()
41-
// - check if tree view is deselected (it is but need not be),
42-
// - check if Explorer is updated properly (seems inconsistent need to double click)
43-
// - check if editor window is opening the newly create doc in a new tab (it doesn't)
44-
// - two file create routes one with follow-up dialog (xquery lib) one without (txt, xml)
45-
})
69+
// see https://github.com/cypress-io/cypress/pull/15388/docs#
70+
// see #414
71+
72+
it('should let users edit new document', () => {
73+
cy.get('[node-id$=untitled_1]')
74+
.dblclick()
75+
if (Cypress.platform === 'darwin') {
76+
cy.get('.view-line')
77+
.type('asdf{meta+s}')
78+
} else {
79+
cy.get('.view-line')
80+
.type('asdf{ctrl+s}')
81+
}
82+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/untitled_1', {
83+
method: 'PUT',
84+
body: 'asdf',
85+
});
86+
})
87+
// see #414 workaround is to run this after editing and saving the document,
88+
// we should be able to rename before entering content
89+
it('should let users rename documents', () => {
90+
cy.get('[node-id$=untitled_1]')
91+
.rightclick()
92+
cy.get('[data-command="fusion.rename"]')
93+
.should('be.visible')
94+
.contains('Rename')
95+
.click()
96+
.focused()
97+
.type('test.txt{enter}')
98+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/test.txt', {
99+
method: 'PUT',
100+
headers: { 'x-fs-move-source': '/db/test/untitled_1' },
101+
});
102+
})
103+
104+
it('should display document properties', () => {
105+
cy.get('[node-id$="test.txt"]')
106+
.rightclick()
107+
cy.get('.p-Menu')
108+
.should('be.visible')
109+
.find('[data-command="fusion.properties"]')
110+
.contains('Properties...')
111+
.click();
112+
cy.get('.dialogTitle')
113+
.should('contain.text', 'Properties')
114+
// rename doc -> text.xml
115+
cy.get('.value > .theia-input')
116+
.clear()
117+
.type('test.xml')
118+
// check properties table
119+
cy.get('.dialogContent')
120+
.find('.keys > tr')
121+
.should('have.length', 11)
122+
.contains('Media Type')
123+
cy.get('.dialogContent')
124+
.find('.keys > tr')
125+
.contains('Owner')
126+
// check permissions table
127+
cy.get('.dialogContent')
128+
.find('.permissions-editor > tr')
129+
.should('have.length', 3)
130+
.contains('user')
131+
cy.get('.main')
132+
.click()
133+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/test.xml', {
134+
method: 'PUT',
135+
headers: { 'x-fs-move-source': '/db/test/test.txt' },
136+
});
137+
})
46138

47-
// see https://github.com/cypress-io/cypress/pull/15388/files#
48-
// see #414
139+
it('should not create duplicate documents', () => {
140+
cy.get('[node-id$=test]')
141+
.rightclick()
142+
cy.get('.p-Menu')
143+
.should('be.visible')
144+
.contains('New document')
145+
.trigger('mousemove')
146+
cy.get('[data-command="fusion.new-document-template:xml"] > .p-Menu-itemLabel')
147+
.should('be.visible')
148+
.click()
149+
cy.get('.fs-inline-input > .theia-input')
150+
.clear()
151+
.type('test.xml{enter}')
152+
cy.get('.error')
153+
.should('exist')
154+
.should('contain.text', 'Item already exists')
155+
})
49156

50-
it('should let users edit new document', () => {
51-
cy.get('[node-id$=untitled-1]')
52-
.dblclick()
53-
if( Cypress.platform === 'darwin') {
54-
cy.get('.view-line')
55-
.type('asdf{meta+s}')
56-
} else {
57-
cy.get('.view-line')
58-
.type('asdf{ctrl+s}')
59-
}
60-
})
61-
// see #414 workaround is to run this after editing and saving the document,
62-
// we should be able to rename before entering content
63-
it('should let users rename documents', () => {
64-
cy.get('[node-id$=untitled-1]')
65-
.rightclick()
66-
cy.get('[data-command="fusion.rename"] > .p-Menu-itemLabel')
67-
.should('be.visible')
68-
.click()
69-
.focused()
70-
.type('test.txt{enter}')
157+
it('should move a document', () => {
158+
const dataTransfer = new DataTransfer();
159+
cy.get('[node-id$="test\\/test.xml"]')
160+
.should('be.visible')
161+
.trigger('dragstart', { dataTransfer })
162+
cy.get('[node-id$=col1]')
163+
.trigger('dragover', { dataTransfer })
164+
.trigger('drop', { dataTransfer })
165+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/col1/test.xml', {
166+
method: 'PUT',
167+
headers: { 'x-fs-move-source': '/db/test/test.xml' },
71168
})
169+
cy.get('[node-id$="test\\/test.xml"]')
170+
.should('not.exist')
171+
cy.get('[node-id$="col1\\/test.xml"]')
172+
.should('be.visible')
173+
})
72174

73-
it('should display document properties', () => {
74-
cy.get('[node-id$=test\\.txt]')
75-
.rightclick()
76-
.type('{alt+enter}', { force: true })
77-
cy.get('.dialogTitle')
78-
.should('contain.text', 'Properties')
79-
// rename file -> text.xml
80-
cy.get('.value > .theia-input')
81-
.clear()
82-
.type('test.xml')
83-
// check properties table
84-
cy.get('.dialogContent')
85-
.find('.keys > tr')
86-
.should('have.length', 11)
87-
.contains('Media Type')
88-
cy.get('.dialogContent')
89-
.find('.keys > tr')
90-
.contains('Owner')
91-
// check permissions table
92-
cy.get('.dialogContent')
93-
.find('.permissions-editor > tr')
94-
.should('have.length', 3)
95-
.contains('user')
96-
cy.get('.main')
97-
.click()
175+
it('should copy a document', () => {
176+
const dataTransfer = new DataTransfer();
177+
cy.get('[node-id$="col1\\/test.xml"]')
178+
.should('be.visible')
179+
.trigger('dragstart', { dataTransfer })
180+
cy.get('[node-id$=test]')
181+
.trigger('dragover', { dataTransfer })
182+
.trigger('drop', { dataTransfer, ctrlKey: true })
183+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/test.xml', {
184+
method: 'PUT',
185+
headers: { 'x-fs-copy-source': '/db/test/col1/test.xml' },
98186
})
187+
cy.get('[node-id$="col1\\/test.xml"]')
188+
.should('be.visible')
189+
cy.get('[node-id$="test\\/test.xml"]')
190+
.should('be.visible')
191+
})
99192

100-
it('should not create duplicate documents', () => {
101-
cy.get('[node-id$=db]')
102-
.rightclick()
103-
.then(() => {
104-
cy.get('.p-Menu')
105-
.should('be.visible')
106-
.contains('New document')
107-
.trigger('mousemove')
108-
cy.get('[data-command="fusion.new-document-template:xml"] > .p-Menu-itemLabel')
109-
.should('be.visible')
110-
.click()
111-
cy.get('.fs-inline-input > .theia-input')
112-
.clear()
113-
.type('test.xml{enter}')
114-
cy.get('.error')
115-
.should('exist')
116-
.should('contain.text', 'Item already exists')
117-
})
193+
it('should move more than one document', () => {
194+
const dataTransfer = new DataTransfer();
195+
cy.get('[node-id$="col1\\/doc1"]')
196+
.should('be.visible')
197+
.click()
198+
.trigger('dragstart', { dataTransfer })
199+
cy.get('[node-id$="col1\\/doc2"]')
200+
.should('be.visible')
201+
.click({ ctrlKey: true })
202+
.trigger('dragstart', { dataTransfer })
203+
cy.get('[node-id$=test]')
204+
.trigger('dragover', { dataTransfer })
205+
.trigger('drop', { dataTransfer })
206+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/doc1', {
207+
method: 'PUT',
208+
headers: { 'x-fs-move-source': '/db/test/col1/doc1' },
209+
})
210+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/doc2', {
211+
method: 'PUT',
212+
headers: { 'x-fs-move-source': '/db/test/col1/doc2' },
118213
})
214+
cy.get('[node-id$="col1\\/doc1"]')
215+
.should('not.exist')
216+
cy.get('[node-id$="col1\\/doc2"]')
217+
.should('not.exist')
218+
cy.get('[node-id$="test\\/doc1"]')
219+
.should('be.visible')
220+
cy.get('[node-id$="test\\/doc2"]')
221+
.should('be.visible')
222+
})
119223

120-
it('should let users delete documents', () => {
121-
cy.get('[node-id$=test\\.xml]')
122-
.rightclick()
123-
cy.get('[data-command="fusion.delete"] > .p-Menu-itemLabel')
124-
.should('be.visible')
125-
.click()
126-
cy.get('.main')
127-
.click()
128-
// make sure all test files are gone see #400
129-
cy.get('[node-id$=untitled-1]')
130-
.should('not.exist')
131-
cy.get('[node-id$=test\\.txt]')
132-
.should('not.exist')
133-
cy.get('[node-id$=test\\.xml]')
134-
.should('not.exist')
135-
cy.get('[node-id$=untitled-2]')
136-
.should('not.exist')
224+
it('should copy more than one document', () => {
225+
const dataTransfer = new DataTransfer();
226+
cy.get('[node-id$="test\\/doc1"]')
227+
.should('be.visible')
228+
.click()
229+
.trigger('dragstart', { dataTransfer })
230+
cy.get('[node-id$="test\\/doc2"]')
231+
.should('be.visible')
232+
.click({ ctrlKey: true })
233+
.trigger('dragstart', { dataTransfer })
234+
cy.get('[node-id$=col1]')
235+
.trigger('dragover', { dataTransfer })
236+
.trigger('drop', { dataTransfer, ctrlKey: true })
237+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/col1/doc1', {
238+
method: 'PUT',
239+
headers: { 'x-fs-copy-source': '/db/test/doc1' },
240+
})
241+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/col1/doc2', {
242+
method: 'PUT',
243+
headers: { 'x-fs-copy-source': '/db/test/doc2' },
137244
})
245+
cy.get('[node-id$="test\\/doc1"]')
246+
.should('be.visible')
247+
cy.get('[node-id$="test\\/doc2"]')
248+
.should('be.visible')
249+
cy.get('[node-id$="col1\\/doc1"]')
250+
.should('be.visible')
251+
cy.get('[node-id$="col1\\/doc2"]')
252+
.should('be.visible')
253+
})
254+
255+
it('should let users delete documents', () => {
256+
cy.get('[node-id$="test\\/test.xml"]')
257+
.rightclick()
258+
cy.get('[data-command="fusion.delete"] > .p-Menu-itemLabel')
259+
.should('be.visible')
260+
.click()
261+
cy.get('.main')
262+
.click()
263+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/test.xml', { method: 'DELETE' });
264+
// make sure all test docs are gone see #400
265+
cy.get('[node-id$=test\\/untitled_1]')
266+
.should('not.exist')
267+
cy.get('[node-id$="test\\/test.txt"]')
268+
.should('not.exist')
269+
cy.get('[node-id$="test\\/test.xml"]')
270+
.should('not.exist')
271+
cy.get('[node-id$=test\\/untitled-2]')
272+
.should('not.exist')
138273
})
139274
})
140275
})

0 commit comments

Comments
 (0)