Skip to content

Commit 18432a4

Browse files
authored
Merge pull request #426 from ccheraa/tests-rewrite
basic api tests
2 parents 8e9272e + 5e07829 commit 18432a4

File tree

3 files changed

+64
-34
lines changed

3 files changed

+64
-34
lines changed

cypress/fixtures/bad_api.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2-
"server": {
3-
"product-name": "eXist",
4-
"build": "20200123123609",
5-
"version": "5.2.0",
6-
"revision": "c58d04ec45de50e7738489dee072fcc863dc8b1b"
7-
},
8-
"exist-db": {
9-
"compatible-version": "0.0.1"
10-
}
2+
"version": "0.0.1",
3+
"server": {
4+
"product-name": "eXist",
5+
"build": "20200123123609",
6+
"version": "5.2.0",
7+
"revision": "c58d04ec45de50e7738489dee072fcc863dc8b1b"
8+
},
9+
"exist-db": {
10+
"compatible-version": null
11+
}
1112
}

cypress/integration/02_api-spec.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
/// <reference types="Cypress" />
22

33
context('Talking to the api directly', () => {
4-
describe('API version', () => {
5-
it.skip('should connect with newer api', () => {
6-
cy.visit('/')
7-
// TODO: Why does this have UUID is the ID stable, this needs a meaningful selector
8-
.get('#d184cace-9938-4ad5-b8df-925a91942661')
9-
.should('be.visible')
10-
})
11-
12-
})
4+
describe('API version', () => {
5+
before(function() {
6+
cy.connect();
7+
cy.visit('/');
8+
});
9+
it('should fail to connect with older api', () => {
10+
cy.intercept('GET', Cypress.env('API_HOST') + '/exist/restxq/fusiondb/version', { fixture: 'bad_api' });
11+
cy.get('.fusion-item').click().then(() => {
12+
cy.get('.dialogTitle').should('contain.text', 'New Connection');
13+
cy.get('.dialogContent').should('be.visible')
14+
.should('contain.text', 'Outdated API "0.0.1"')
15+
.should('contain.text', 'You need to update your API to version "0.2.0" or higher');
16+
cy.get('.theia-button.main').should('be.visible').click();
17+
cy.get('.dialogBlock').should('not.exist');
18+
});
19+
});
20+
it('should connect with newer api', () => {
21+
cy.window().then(function(win) {
22+
const fetchSpy = cy.spy(win, 'fetch');
23+
fetchSpy.withArgs(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/version').as('/version');
24+
fetchSpy.withArgs(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/explorer?uri=/').as('/explorer');
25+
fetchSpy.withArgs(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/user').as('/user');
26+
fetchSpy.withArgs(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/group').as('/group');
27+
fetchSpy.withArgs(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/index').as('/index');
28+
fetchSpy.withArgs(Cypress.env('API_HOST') + '/exist/restxq/fusiondb/restxq').as('/restxq');
29+
cy.get('.fusion-item').click();
30+
cy.get('.fusion-view')
31+
.should('contain', 'db')
32+
.should('contain', 'RestXQ');
33+
cy.get('@/version').should('be.called');
34+
cy.get('@/explorer').should('be.called');
35+
cy.get('@/user').should('be.called');
36+
cy.get('@/group').should('be.called');
37+
cy.get('@/index').should('be.called');
38+
cy.get('@/restxq').should('be.called');
39+
});
40+
});
41+
});
1342
})

cypress/integration/04_document_spec.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ context('Document Operations', () => {
44
describe('working with tree view', () => {
55
before(() => {
66
cy.connect()
7-
// TODO(DP): might have to improve by adding more before / after hooks to prevent dangling documents
8-
// see #400
7+
// TODO(DP): might have to improve by adding more before / after hooks to prevent dangling documents
8+
// see #400
99
})
1010

1111
describe('db context menu', () => {
@@ -15,7 +15,7 @@ context('Document Operations', () => {
1515
.should('be.visible')
1616
cy.get('.fusion-item')
1717
.click()
18-
// all we need is the final part of the node-id attribute
18+
// all we need is the final part of the node-id attribute
1919
cy.get('[node-id$=db]')
2020
.rightclick()
2121
.then(() => {
@@ -27,11 +27,11 @@ context('Document Operations', () => {
2727
.should('be.visible')
2828
.click()
2929
})
30-
// (DP): start workaround for #413
30+
// (DP): start workaround for #413
3131
cy.get('[node-id$=db]')
3232
.trigger('mousemove')
3333
.type('{enter}')
34-
// end workaround for #413
34+
// end workaround for #413
3535
cy.get('.ReactVirtualized__Grid')
3636
.contains('untitled-1')
3737

@@ -47,13 +47,13 @@ context('Document Operations', () => {
4747
// or by using the file menu UI instead
4848
// see #414
4949
it('should let users edit new document', () => {
50-
cy.get('[node-id$=untitled-1]')
51-
.dblclick()
52-
cy.get('.view-line')
53-
.type('asdf{meta+s}')
54-
})
55-
// see #414 workaround is to run this after editing and saving the document,
56-
// we should be able to rename before entering content
50+
cy.get('[node-id$=untitled-1]')
51+
.dblclick()
52+
cy.get('.view-line')
53+
.type('asdf{meta+s}')
54+
})
55+
// see #414 workaround is to run this after editing and saving the document,
56+
// we should be able to rename before entering content
5757
it('should let users rename documents', () => {
5858
cy.get('[node-id$=untitled-1]')
5959
.rightclick()
@@ -70,19 +70,19 @@ context('Document Operations', () => {
7070
.type('{alt+enter}', { force: true })
7171
cy.get('.dialogTitle')
7272
.should('contain.text', 'Properties')
73-
// rename file -> text.xml
73+
// rename file -> text.xml
7474
cy.get('.value > .theia-input')
7575
.clear()
7676
.type('test.xml')
77-
// check properties table
77+
// check properties table
7878
cy.get('.dialogContent')
7979
.find('.keys > tr')
8080
.should('have.length', 11)
8181
.contains('Media Type')
8282
cy.get('.dialogContent')
8383
.find('.keys > tr')
8484
.contains('Owner')
85-
// check permissions table
85+
// check permissions table
8686
cy.get('.dialogContent')
8787
.find('.permissions-editor > tr')
8888
.should('have.length', 3)
@@ -120,7 +120,7 @@ context('Document Operations', () => {
120120
.click()
121121
cy.get('.main')
122122
.click()
123-
// make sure all test files are gone see #400
123+
// make sure all test files are gone see #400
124124
cy.get('[node-id$=untitled-1]')
125125
.should('not.exist')
126126
cy.get('[node-id$=test\\.txt]')

0 commit comments

Comments
 (0)