Skip to content

Commit 3894000

Browse files
committed
split upload tests between document and collection
1 parent 69a7dc9 commit 3894000

File tree

3 files changed

+83
-68
lines changed

3 files changed

+83
-68
lines changed

cypress/integration/04_document_spec.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ context('Document Operations', () => {
2828
})
2929
after(() => {
3030
// delete the test colelction
31-
// new Cypress.Promise(resolve => FSApi.remove(connection, '/db/test', true).then(resolve).catch(resolve))
31+
new Cypress.Promise(resolve => FSApi.remove(connection, '/db/test', true).then(resolve).catch(resolve))
32+
})
33+
afterEach(() => {
34+
// make sure the tree has rendered all its items properly
35+
cy.wait(10)
3236
})
3337
it('should display creation options', () => {
3438
cy.get('.fusion-view', { timeout: 55000 })
@@ -90,7 +94,7 @@ context('Document Operations', () => {
9094
cy.get('[node-id$=untitled_1]')
9195
.rightclick()
9296
cy.get('[data-command="fusion.rename"]')
93-
.should('be.visible')
97+
.should('be.visible')
9498
.contains('Rename')
9599
.click()
96100
.focused()
@@ -152,6 +156,30 @@ context('Document Operations', () => {
152156
cy.get('.error')
153157
.should('exist')
154158
.should('contain.text', 'Item already exists')
159+
cy.get('.fs-inline-input > .theia-input')
160+
.type('{esc}')
161+
})
162+
163+
it('should upload a document', () => {
164+
cy.extendedFiles().then(win => {
165+
const file = new win.ExFile('/', [new Blob(['sample text content.'])], 'upload_test.txt', { type: 'text/plain' })
166+
167+
const originalDataTransfer = new win.DataTransfer();
168+
originalDataTransfer.items.add(file);
169+
const dataTransfer = {
170+
...originalDataTransfer,
171+
items: [file],
172+
files: [file],
173+
};
174+
dataTransfer.getData = (...args) => originalDataTransfer.getData(...args);
175+
176+
cy.get('[node-id$=test]')
177+
.trigger('dragover', { dataTransfer })
178+
.trigger('drop', { dataTransfer })
179+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/upload_test.txt', { method: 'PUT' })
180+
cy.get('[node-id$="test\\/upload_test.txt"]')
181+
.should('be.visible')
182+
})
155183
})
156184

157185
it('should move a document', () => {

cypress/integration/05_collection_spec.js

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,17 @@ context('Collection Operations', () => {
2222
cy.visit('/', {
2323
onBeforeLoad(win) {
2424
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-
}
5525
}
5626
});
5727
})
5828
after(() => {
5929
// delete the test collection
6030
new Cypress.Promise(resolve => FSApi.remove(connection, '/db/test', true).then(resolve).catch(resolve))
6131
})
32+
afterEach(() => {
33+
// make sure the tree has rendered all its items properly
34+
cy.wait(10)
35+
})
6236

6337
it('should display creation options', () => {
6438
cy.get('.fusion-view')
@@ -186,32 +160,10 @@ context('Collection Operations', () => {
186160
.should('exist')
187161
})
188162

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-
211163
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')
164+
cy.extendedFiles().then(win => {
165+
const file = new win.ExFile('/uploaded_col/', [new Blob(['sample text content.'])], 'uploaded_test.txt', { type: 'text/plain' })
166+
const dir = new win.ExDir('/', [file], 'uploaded_col')
215167

216168
const originalDataTransfer = new win.DataTransfer();
217169
originalDataTransfer.items.add(file);
@@ -225,11 +177,11 @@ context('Collection Operations', () => {
225177
cy.get('[node-id$=test]')
226178
.trigger('dragover', { dataTransfer })
227179
.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"]')
180+
fetchSpy.calledWithMatch(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/document?uri=/db/test/uploaded_col', { method: 'PUT' })
181+
cy.get('[node-id$="test\\/uploaded_col"]')
230182
.should('be.visible')
231183
.click()
232-
cy.get('[node-id$="col\\/test2.txt"]')
184+
cy.get('[node-id$="uploaded_col\\/uploaded_test.txt"]')
233185
.should('be.visible')
234186
})
235187
})

cypress/support/commands.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,51 @@
1616
// populate localStorage with a default connection, automatically cleared before each spec
1717
// assumes default 'admin' user and '' password
1818
// actual server URL is retrieved via ENV
19-
Cypress.Commands.add("connect", () => {
20-
// conn_val mimics actual app behavior, its value is inconsequential for establishing a connection
21-
let conn_val = 'admin@' + Cypress.env('API_HOST')
22-
let nested = {"name":"localhost","server": Cypress.env('API_HOST'),"username":"admin","password":"","users":[],"groups":[]}
23-
let obj = {}
24-
obj[conn_val] = nested
19+
Cypress.Commands.add("connect", () => {
20+
// conn_val mimics actual app behavior, its value is inconsequential for establishing a connection
21+
let conn_val = 'admin@' + Cypress.env('API_HOST')
22+
let nested = { "name": "localhost", "server": Cypress.env('API_HOST'), "username": "admin", "password": "", "users": [], "groups": [] }
23+
let obj = {}
24+
obj[conn_val] = nested
2525

26-
localStorage.setItem('connections', JSON.stringify(obj))
26+
localStorage.setItem('connections', JSON.stringify(obj))
2727

28-
})
28+
})
29+
Cypress.Commands.add("extendedFiles", () => {
30+
return cy.window().then(win => {
31+
win.ExFile = class extends win.File {
32+
constructor(root, data, fileName, options) {
33+
super(data, fileName, options);
34+
this.root = root;
35+
}
36+
webkitGetAsEntry() {
37+
const me = this;
38+
return {
39+
isDirectory: false,
40+
isFile: true,
41+
fullPath: this.root + this.name,
42+
file: callback => callback(this),
43+
};
44+
}
45+
}
46+
win.ExDir = class extends win.ExFile {
47+
constructor(root, entries, fileName, options) {
48+
super(root, [], fileName, options);
49+
this.entries = entries.map(entry => entry.webkitGetAsEntry());
50+
}
51+
webkitGetAsEntry() {
52+
const me = this;
53+
return {
54+
isDirectory: true,
55+
isFile: false,
56+
fullPath: this.root + this.name,
57+
createReader: () => ({ readEntries: callback => callback(this.entries) }),
58+
};
59+
}
60+
}
61+
return win;
62+
});
63+
})
2964
//
3065
//
3166
// -- This is a child command --

0 commit comments

Comments
 (0)