Skip to content

Commit fd528f9

Browse files
committed
Fix server switch bug
Also: test connection when provided by desktop api. Inject fake `window.neo4jDesktopApi` in a testfile and test auto connection + connection switch Added e2e test config bolt-url to README
1 parent f0bf2cb commit fd528f9

File tree

22 files changed

+294
-238
lines changed

22 files changed

+294
-238
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Here are the avaialable options / env variables:
3535
server=3.2|3.3|3.4|3.5 (default 3.4)
3636
browser-password=<your-pw> (default 'newpassword')
3737
include-import-tests=true|false (default false)
38+
bolt-url=<bolr url excluding the protocol> (default localhost:7687)
3839
E2E_TEST_ENV=local|null (if the initial set of pw should run or not) (default undefined)
3940
BROWSER_URL=<url to reach the browser to test> (default http://localhost:8080)
4041
```
@@ -43,5 +44,5 @@ BROWSER_URL=<url to reach the browser to test> (default http://localhost:8080)
4344

4445
Download these two chrome extensions:
4546

46-
* [Redux devtools](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en)
47-
* [React devtools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)
47+
- [Redux devtools](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en)
48+
- [React devtools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)

cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"animationDistanceThreshold": 5,
33
"baseUrl": null,
4-
"chromeWebSecurity": true,
4+
"chromeWebSecurity": false,
55
"defaultCommandTimeout": 4000,
66
"environmentVariables": {},
77
"execTimeout": 60000,

e2e_tests/cypress.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

e2e_tests/integration/0.index.spec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
/* global Cypress, cy, test, expect */
21+
/* global Cypress, cy, test, expect, before */
2222

2323
const Editor = '.ReactCodeMirror textarea'
2424
const Carousel = '[data-test-id="carousel"]'
2525
const SubmitQueryButton = '[data-test-id="submitQuery"]'
2626
const ClearEditorButton = '[data-test-id="clearEditorContent"]'
2727

2828
describe('Neo4j Browser', () => {
29+
before(function () {
30+
cy.visit(Cypress.config.url)
31+
.title()
32+
.should('include', 'Neo4j Browser')
33+
})
2934
it('sets new login credentials', () => {
30-
const newPassword = Cypress.env('browser-password') || 'newpassword'
35+
const newPassword = Cypress.config.password
3136
cy.setInitialPassword(newPassword)
3237
cy.disconnect()
3338
})
@@ -37,7 +42,7 @@ describe('Neo4j Browser', () => {
3742
cy.get(ClearEditorButton).click()
3843
})
3944
it('can connect', () => {
40-
const password = Cypress.env('browser-password') || 'newpassword'
45+
const password = Cypress.config.password
4146
cy.connect(
4247
'neo4j',
4348
password

e2e_tests/integration/bolt.spec.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
/* global Cypress, cy, test, expect */
21+
/* global Cypress, cy, test, expect, before */
2222

2323
describe('Bolt connections', () => {
24+
before(function () {
25+
cy.visit(Cypress.config.url)
26+
.title()
27+
.should('include', 'Neo4j Browser')
28+
})
2429
it('show "no connection" error when not using web workers', () => {
2530
cy.executeCommand(':clear')
2631
cy.executeCommand(':config useCypherThread: false')
@@ -49,7 +54,7 @@ describe('Bolt connections', () => {
4954
})
5055
it('users with no role can connect', () => {
5156
cy.executeCommand(':clear')
52-
const password = Cypress.env('browser-password') || 'newpassword'
57+
const password = Cypress.config.password
5358
cy.connect(
5459
'neo4j',
5560
password
@@ -62,22 +67,13 @@ describe('Bolt connections', () => {
6267
cy.executeCommand(':server connect')
6368

6469
// Make sure initial pw set works
65-
cy.setInitialPassword('.', 'pw', 'no-roles', true)
70+
cy.setInitialPassword('.', 'pw', 'no-roles', Cypress.config.boltUrl, true)
6671

6772
// Try regular connect
6873
cy.executeCommand(':server disconnect')
6974
cy.connect(
7075
'no-roles',
7176
'.'
7277
)
73-
74-
// We need to reset the local storage value to
75-
// default so other tests can pass
76-
cy.executeCommand(':server disconnect')
77-
cy.connect(
78-
'neo4j',
79-
password
80-
)
81-
cy.executeCommand(':server disconnect')
8278
})
8379
})

e2e_tests/integration/commands.spec.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
/* global Cypress, cy, test, expect */
21+
/* global Cypress, cy, test, expect, before */
2222

2323
const commands = [
2424
':style',
@@ -44,6 +44,11 @@ const commands = [
4444
]
4545

4646
describe('Commands', () => {
47+
before(function () {
48+
cy.visit(Cypress.config.url)
49+
.title()
50+
.should('include', 'Neo4j Browser')
51+
})
4752
it('can run all simple commands not connected without blowing up', () => {
4853
commands.forEach(cmd => {
4954
cy.executeCommand(cmd)
@@ -52,11 +57,19 @@ describe('Commands', () => {
5257
})
5358
it('can show connection error', () => {
5459
const password = 'unlikely password'
55-
cy.connect('neo4j', password, undefined, false)
60+
cy.connect(
61+
'neo4j',
62+
password,
63+
undefined,
64+
false
65+
)
5666
})
5767
it('can connect', () => {
58-
const password = Cypress.env('browser-password') || 'newpassword'
59-
cy.connect('neo4j', password)
68+
const password = Cypress.config.password
69+
cy.connect(
70+
'neo4j',
71+
password
72+
)
6073
})
6174
it('can run all simple commands while connected without blowing up', () => {
6275
commands.forEach(cmd => {
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2002-2018 "Neo4j, Inc"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/* global Cypress, cy, test, expect, before */
22+
23+
let appContextListener
24+
25+
describe('Neo4j Desktop environment', () => {
26+
before(() => {
27+
cy.visit(Cypress.config.url, {
28+
onBeforeLoad: win => {
29+
win.neo4jDesktopApi = {
30+
getContext: () => Promise.resolve(getContext()),
31+
onContextUpdate: fn => (appContextListener = fn.bind(fn))
32+
}
33+
}
34+
})
35+
})
36+
it('can auto connect', () => {
37+
const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 })
38+
frames.should('have.length', 2)
39+
40+
// Auto connected = :play start
41+
frames.first().should('contain', ':play start')
42+
cy.wait(1000)
43+
})
44+
it('switches connection when that event is triggered', () => {
45+
cy.executeCommand(':clear')
46+
cy.wait(1000).then(() => {
47+
appContextListener({ type: 'GRAPH_ACTIVE', id: 'test' }, getContext())
48+
})
49+
50+
const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 })
51+
frames.should('have.length', 1)
52+
53+
frames.first().should('contain', ':server switch success')
54+
55+
cy.get('[data-test-id="frame"]', { timeout: 10000 })
56+
.first()
57+
.should('contain', 'Connection updated')
58+
})
59+
})
60+
61+
const getContext = () => ({
62+
projects: [
63+
{
64+
graphs: [
65+
{
66+
status: 'ACTIVE',
67+
connection: {
68+
type: 'REMOTE',
69+
configuration: {
70+
protocols: {
71+
bolt: {
72+
enabled: true,
73+
username: 'neo4j',
74+
password: Cypress.config.password,
75+
host: Cypress.config.boltHost,
76+
port: Cypress.config.boltPort,
77+
tlsLevel: Cypress.config.url.startsWith('https')
78+
? 'REQUIRED'
79+
: 'OPTIONAL'
80+
},
81+
http: {
82+
enabled: true,
83+
username: 'neo4j',
84+
password: Cypress.config.password,
85+
host: 'localhost',
86+
port: '7474'
87+
}
88+
}
89+
}
90+
}
91+
}
92+
]
93+
}
94+
]
95+
})

e2e_tests/integration/loadcsv.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
/* global Cypress, cy, test, expect */
21+
/* global Cypress, cy, test, expect, before */
2222

2323
describe('LOAD CSV', () => {
24+
before(function () {
25+
cy.visit(Cypress.config.url)
26+
.title()
27+
.should('include', 'Neo4j Browser')
28+
})
2429
it('can connect', () => {
25-
const password = Cypress.env('browser-password') || 'newpassword'
26-
cy.connect('neo4j', password)
30+
const password = Cypress.config.password
31+
cy.connect(
32+
'neo4j',
33+
password
34+
)
2735
})
2836
it('imports without periodic commit', () => {
2937
if (!Cypress.config.includeImportTests) {

e2e_tests/integration/multistatements.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ describe('Multi statements', () => {
2424
const validQuery = 'RETURN 1; :config; RETURN 2;'
2525

2626
before(() => {
27+
cy.visit(Cypress.config.url)
28+
.title()
29+
.should('include', 'Neo4j Browser')
2730
cy.get('[data-test-id="drawerSettings"]').click()
2831
cy.get('[data-test-id="enableMultiStatementMode"]').click()
2932
cy.get('[data-test-id="drawerSettings"]').click()
@@ -34,7 +37,7 @@ describe('Multi statements', () => {
3437
cy.get('[data-test-id="drawerSettings"]').click()
3538
})
3639
it('can connect', () => {
37-
const password = Cypress.env('browser-password') || 'newpassword'
40+
const password = Cypress.config.password
3841
cy.connect(
3942
'neo4j',
4043
password

e2e_tests/integration/params.spec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
/* global Cypress, cy, test, expect */
21+
/* global Cypress, cy, test, expect, before */
2222

2323
describe(':param in Browser', () => {
24+
before(function () {
25+
cy.visit(Cypress.config.url)
26+
.title()
27+
.should('include', 'Neo4j Browser')
28+
})
2429
it('handles :param without web worker', () => {
2530
cy.executeCommand(':config userCypherThread: false').then(() => {
2631
cy.executeCommand(':clear')
@@ -39,7 +44,7 @@ function runTests () {
3944
let setParamQ
4045
let getParamQ
4146
// it('can connect', () => {
42-
const password = Cypress.env('browser-password') || 'newpassword'
47+
const password = Cypress.config.password
4348
cy.connect(
4449
'neo4j',
4550
password

0 commit comments

Comments
 (0)