Skip to content

Commit 69a7dc9

Browse files
committed
added drag and drop upload tests
1 parent 2199463 commit 69a7dc9

File tree

2 files changed

+100
-20
lines changed

2 files changed

+100
-20
lines changed

cypress/integration/05_collection_spec.js

Lines changed: 99 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { FSApi } from '../../fusion-studio-extension/src/common/api';
33

44
context('Collection Operations', () => {
55
describe('working with tree view', () => {
6+
let fetchSpy;
67
const connection = {
78
server: Cypress.env('API_HOST'),
89
username: 'admin',
910
password: '',
1011
};
1112
before(() => {
12-
// prepare collections used in the test
13+
// prepare collections and documents used in the test
1314
new Cypress.Promise(async resolve => {
1415
await FSApi.remove(connection, '/db/test', true).catch(e => { });
1516
await FSApi.newCollection(connection, '/db/test');
@@ -18,13 +19,44 @@ context('Collection Operations', () => {
1819
resolve();
1920
})
2021
cy.connect()
21-
cy.visit('/');
22-
})
23-
beforeEach(() => {
24-
cy.window().then(win => cy.spy(win, 'fetch').as('fetch'));
22+
cy.visit('/', {
23+
onBeforeLoad(win) {
24+
fetchSpy = cy.spy(win, 'fetch')
25+
win.ExFile = class extends win.File {
26+
constructor(root, data, fileName, options) {
27+
super(data, fileName, options);
28+
this.root = root;
29+
}
30+
webkitGetAsEntry() {
31+
const me = this;
32+
return {
33+
isDirectory: false,
34+
isFile: true,
35+
fullPath: this.root + this.name,
36+
file: callback => callback(this),
37+
};
38+
}
39+
}
40+
win.ExDir = class extends win.ExFile {
41+
constructor(root, entries, fileName, options) {
42+
super(root, [], fileName, options);
43+
this.entries = entries.map(entry => entry.webkitGetAsEntry());
44+
}
45+
webkitGetAsEntry() {
46+
const me = this;
47+
return {
48+
isDirectory: true,
49+
isFile: false,
50+
fullPath: this.root + this.name,
51+
createReader: () => ({ readEntries: callback => callback(this.entries) }),
52+
};
53+
}
54+
}
55+
}
56+
});
2557
})
2658
after(() => {
27-
// delete the test colelction
59+
// delete the test collection
2860
new Cypress.Promise(resolve => FSApi.remove(connection, '/db/test', true).then(resolve).catch(resolve))
2961
})
3062

@@ -42,8 +74,8 @@ context('Collection Operations', () => {
4274
cy.get('[node-id$=test]')
4375
.click()
4476
.prev().should('not.have.class', 'fa-spin')
45-
cy.get('@fetch').should('be.calledWith', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/explorer?uri=/db');
46-
cy.get('@fetch').should('be.calledWith', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/explorer?uri=/db/test');
77+
fetchSpy.calledWith(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/explorer?uri=/db');
78+
fetchSpy.calledWith(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/explorer?uri=/db/test');
4779
cy.get('[node-id$=test]')
4880
.rightclick();
4981
cy.get('.p-Menu')
@@ -56,7 +88,7 @@ context('Collection Operations', () => {
5688
.type('{enter}')
5789
cy.get('.fusion-view')
5890
.contains('untitled-1')
59-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/untitled-1', { method: 'PUT' });
91+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/untitled-1', { method: 'PUT' });
6092
})
6193

6294
it('should let users rename collection', () => {
@@ -68,7 +100,7 @@ context('Collection Operations', () => {
68100
.click()
69101
cy.focused()
70102
.type('test_col{enter}')
71-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col', {
103+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col', {
72104
method: 'PUT',
73105
headers: { 'x-fs-move-source': '/db/test/untitled-1' },
74106
});
@@ -154,6 +186,54 @@ context('Collection Operations', () => {
154186
.should('exist')
155187
})
156188

189+
it('should upload a document', () => {
190+
cy.window().then(win => {
191+
const file = new win.ExFile('/', [new Blob(['sample text content.'])], 'test.txt', { type: 'text/plain' })
192+
193+
const originalDataTransfer = new win.DataTransfer();
194+
originalDataTransfer.items.add(file);
195+
const dataTransfer = {
196+
...originalDataTransfer,
197+
items: [file],
198+
files: [file],
199+
};
200+
dataTransfer.getData = (...args) => originalDataTransfer.getData(...args);
201+
202+
cy.get('[node-id$=test]')
203+
.trigger('dragover', { dataTransfer })
204+
.trigger('drop', { dataTransfer })
205+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/test.txt', { method: 'PUT' })
206+
cy.get('[node-id$="test\\/test.txt"]')
207+
.should('be.visible')
208+
})
209+
})
210+
211+
it('should upload a collection', () => {
212+
cy.window().then(win => {
213+
const file = new win.ExFile('/col/', [new Blob(['sample text content.'])], 'test2.txt', { type: 'text/plain' })
214+
const dir = new win.ExDir('/', [file], 'col')
215+
216+
const originalDataTransfer = new win.DataTransfer();
217+
originalDataTransfer.items.add(file);
218+
const dataTransfer = {
219+
...originalDataTransfer,
220+
items: [dir],
221+
files: [dir],
222+
};
223+
dataTransfer.getData = (...args) => originalDataTransfer.getData(...args);
224+
225+
cy.get('[node-id$=test]')
226+
.trigger('dragover', { dataTransfer })
227+
.trigger('drop', { dataTransfer })
228+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/col', { method: 'PUT' })
229+
cy.get('[node-id$="test\\/col"]')
230+
.should('be.visible')
231+
.click()
232+
cy.get('[node-id$="col\\/test2.txt"]')
233+
.should('be.visible')
234+
})
235+
})
236+
157237
it('should move a collection', () => {
158238
const dataTransfer = new DataTransfer();
159239
cy.get('[node-id$="test\\/col1"]')
@@ -162,7 +242,7 @@ context('Collection Operations', () => {
162242
cy.get('[node-id$=test_col2]')
163243
.trigger('dragover', { dataTransfer })
164244
.trigger('drop', { dataTransfer })
165-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col2/col1', {
245+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col2/col1', {
166246
method: 'PUT',
167247
headers: { 'x-fs-move-source': '/db/test/col1' },
168248
})
@@ -183,7 +263,7 @@ context('Collection Operations', () => {
183263
cy.get('[node-id$=test]')
184264
.trigger('dragover', { dataTransfer })
185265
.trigger('drop', { dataTransfer, ctrlKey: true })
186-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1', {
266+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1', {
187267
method: 'PUT',
188268
headers: { 'x-fs-copy-source': '/db/test/test_col2/col1' },
189269
})
@@ -210,11 +290,11 @@ context('Collection Operations', () => {
210290
cy.get('[node-id$=test\\/col1]')
211291
.trigger('dragover', { dataTransfer })
212292
.trigger('drop', { dataTransfer })
213-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1/col1', {
293+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1/col1', {
214294
method: 'PUT',
215295
headers: { 'x-fs-move-source': '/db/test/test_col2/col1' },
216296
})
217-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1/test_colA', {
297+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1/test_colA', {
218298
method: 'PUT',
219299
headers: { 'x-fs-move-source': '/db/test/test_col2/test_colA' },
220300
})
@@ -243,11 +323,11 @@ context('Collection Operations', () => {
243323
cy.get('[node-id$=test\\/test_col2]')
244324
.trigger('dragover', { dataTransfer })
245325
.trigger('drop', { dataTransfer, ctrlKey: true })
246-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col2/col1', {
326+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col2/col1', {
247327
method: 'PUT',
248328
headers: { 'x-fs-copy-source': '/db/test/col1/col1' },
249329
})
250-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col2/test_colA', {
330+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col2/test_colA', {
251331
method: 'PUT',
252332
headers: { 'x-fs-copy-source': '/db/test/col1/test_colA' },
253333
})
@@ -274,7 +354,7 @@ context('Collection Operations', () => {
274354
cy.get('[node-id$=test\\/col1\\/col1]')
275355
.trigger('dragover', { dataTransfer })
276356
.trigger('drop', { dataTransfer })
277-
cy.get('@fetch').should('not.be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1/col1/col1', {
357+
fetchSpy.neverCalledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1/col1/col1', {
278358
method: 'PUT',
279359
headers: { 'x-fs-move-source': '/db/test/test/col1' },
280360
})
@@ -294,7 +374,7 @@ context('Collection Operations', () => {
294374
cy.get('[node-id$=test\\/col1\\/col1]')
295375
.trigger('dragover', { dataTransfer })
296376
.trigger('drop', { dataTransfer, ctrlKey: true })
297-
cy.get('@fetch').should('not.be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1/col1/col1', {
377+
fetchSpy.neverCalledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/col1/col1/col1', {
298378
method: 'PUT',
299379
headers: { 'x-fs-move-source': '/db/test/test/col1' },
300380
})
@@ -315,7 +395,7 @@ context('Collection Operations', () => {
315395
.click()
316396
cy.get('.main')
317397
.click()
318-
cy.get('@fetch').should('be.calledWithMatch', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col2', { method: 'DELETE' });
398+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/collection?uri=/db/test/test_col2', { method: 'DELETE' });
319399
// make sure all test files are gone see #400, including those produced by failed create commands
320400
cy.get('[node-id$=untitled-1]')
321401
.should('not.exist')

fusion-studio-extension/src/browser/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export class FSCore {
461461
this.startLoading(node);
462462
const docs = await FSApi.saveDocuments(node.connectionNode.connection, node.collection, documents);
463463
this.endLoading(node);
464-
this.load(node, node.uri);
464+
this.asyncLoad(node);
465465
return docs;
466466
} catch (error) {
467467
this.endLoading(node);

0 commit comments

Comments
 (0)