Skip to content

Commit

Permalink
Fix server switch bug
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oskarhane committed Sep 5, 2018
1 parent f0bf2cb commit fd528f9
Show file tree
Hide file tree
Showing 22 changed files with 294 additions and 238 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Here are the avaialable options / env variables:
server=3.2|3.3|3.4|3.5 (default 3.4)
browser-password=<your-pw> (default 'newpassword')
include-import-tests=true|false (default false)
bolt-url=<bolr url excluding the protocol> (default localhost:7687)
E2E_TEST_ENV=local|null (if the initial set of pw should run or not) (default undefined)
BROWSER_URL=<url to reach the browser to test> (default http://localhost:8080)
```
Expand All @@ -43,5 +44,5 @@ BROWSER_URL=<url to reach the browser to test> (default http://localhost:8080)

Download these two chrome extensions:

* [Redux devtools](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en)
* [React devtools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)
- [Redux devtools](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en)
- [React devtools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)
2 changes: 1 addition & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"animationDistanceThreshold": 5,
"baseUrl": null,
"chromeWebSecurity": true,
"chromeWebSecurity": false,
"defaultCommandTimeout": 4000,
"environmentVariables": {},
"execTimeout": 60000,
Expand Down
1 change: 0 additions & 1 deletion e2e_tests/cypress.json

This file was deleted.

11 changes: 8 additions & 3 deletions e2e_tests/integration/0.index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect */
/* global Cypress, cy, test, expect, before */

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

describe('Neo4j Browser', () => {
before(function () {
cy.visit(Cypress.config.url)
.title()
.should('include', 'Neo4j Browser')
})
it('sets new login credentials', () => {
const newPassword = Cypress.env('browser-password') || 'newpassword'
const newPassword = Cypress.config.password
cy.setInitialPassword(newPassword)
cy.disconnect()
})
Expand All @@ -37,7 +42,7 @@ describe('Neo4j Browser', () => {
cy.get(ClearEditorButton).click()
})
it('can connect', () => {
const password = Cypress.env('browser-password') || 'newpassword'
const password = Cypress.config.password
cy.connect(
'neo4j',
password
Expand Down
20 changes: 8 additions & 12 deletions e2e_tests/integration/bolt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect */
/* global Cypress, cy, test, expect, before */

describe('Bolt connections', () => {
before(function () {
cy.visit(Cypress.config.url)
.title()
.should('include', 'Neo4j Browser')
})
it('show "no connection" error when not using web workers', () => {
cy.executeCommand(':clear')
cy.executeCommand(':config useCypherThread: false')
Expand Down Expand Up @@ -49,7 +54,7 @@ describe('Bolt connections', () => {
})
it('users with no role can connect', () => {
cy.executeCommand(':clear')
const password = Cypress.env('browser-password') || 'newpassword'
const password = Cypress.config.password
cy.connect(
'neo4j',
password
Expand All @@ -62,22 +67,13 @@ describe('Bolt connections', () => {
cy.executeCommand(':server connect')

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

// Try regular connect
cy.executeCommand(':server disconnect')
cy.connect(
'no-roles',
'.'
)

// We need to reset the local storage value to
// default so other tests can pass
cy.executeCommand(':server disconnect')
cy.connect(
'neo4j',
password
)
cy.executeCommand(':server disconnect')
})
})
21 changes: 17 additions & 4 deletions e2e_tests/integration/commands.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect */
/* global Cypress, cy, test, expect, before */

const commands = [
':style',
Expand All @@ -44,6 +44,11 @@ const commands = [
]

describe('Commands', () => {
before(function () {
cy.visit(Cypress.config.url)
.title()
.should('include', 'Neo4j Browser')
})
it('can run all simple commands not connected without blowing up', () => {
commands.forEach(cmd => {
cy.executeCommand(cmd)
Expand All @@ -52,11 +57,19 @@ describe('Commands', () => {
})
it('can show connection error', () => {
const password = 'unlikely password'
cy.connect('neo4j', password, undefined, false)
cy.connect(
'neo4j',
password,
undefined,
false
)
})
it('can connect', () => {
const password = Cypress.env('browser-password') || 'newpassword'
cy.connect('neo4j', password)
const password = Cypress.config.password
cy.connect(
'neo4j',
password
)
})
it('can run all simple commands while connected without blowing up', () => {
commands.forEach(cmd => {
Expand Down
95 changes: 95 additions & 0 deletions e2e_tests/integration/desktop-env.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2002-2018 "Neo4j, Inc"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect, before */

let appContextListener

describe('Neo4j Desktop environment', () => {
before(() => {
cy.visit(Cypress.config.url, {
onBeforeLoad: win => {
win.neo4jDesktopApi = {
getContext: () => Promise.resolve(getContext()),
onContextUpdate: fn => (appContextListener = fn.bind(fn))
}
}
})
})
it('can auto connect', () => {
const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 })
frames.should('have.length', 2)

// Auto connected = :play start
frames.first().should('contain', ':play start')
cy.wait(1000)
})
it('switches connection when that event is triggered', () => {
cy.executeCommand(':clear')
cy.wait(1000).then(() => {
appContextListener({ type: 'GRAPH_ACTIVE', id: 'test' }, getContext())
})

const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 })
frames.should('have.length', 1)

frames.first().should('contain', ':server switch success')

cy.get('[data-test-id="frame"]', { timeout: 10000 })
.first()
.should('contain', 'Connection updated')
})
})

const getContext = () => ({
projects: [
{
graphs: [
{
status: 'ACTIVE',
connection: {
type: 'REMOTE',
configuration: {
protocols: {
bolt: {
enabled: true,
username: 'neo4j',
password: Cypress.config.password,
host: Cypress.config.boltHost,
port: Cypress.config.boltPort,
tlsLevel: Cypress.config.url.startsWith('https')
? 'REQUIRED'
: 'OPTIONAL'
},
http: {
enabled: true,
username: 'neo4j',
password: Cypress.config.password,
host: 'localhost',
port: '7474'
}
}
}
}
}
]
}
]
})
14 changes: 11 additions & 3 deletions e2e_tests/integration/loadcsv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect */
/* global Cypress, cy, test, expect, before */

describe('LOAD CSV', () => {
before(function () {
cy.visit(Cypress.config.url)
.title()
.should('include', 'Neo4j Browser')
})
it('can connect', () => {
const password = Cypress.env('browser-password') || 'newpassword'
cy.connect('neo4j', password)
const password = Cypress.config.password
cy.connect(
'neo4j',
password
)
})
it('imports without periodic commit', () => {
if (!Cypress.config.includeImportTests) {
Expand Down
5 changes: 4 additions & 1 deletion e2e_tests/integration/multistatements.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ describe('Multi statements', () => {
const validQuery = 'RETURN 1; :config; RETURN 2;'

before(() => {
cy.visit(Cypress.config.url)
.title()
.should('include', 'Neo4j Browser')
cy.get('[data-test-id="drawerSettings"]').click()
cy.get('[data-test-id="enableMultiStatementMode"]').click()
cy.get('[data-test-id="drawerSettings"]').click()
Expand All @@ -34,7 +37,7 @@ describe('Multi statements', () => {
cy.get('[data-test-id="drawerSettings"]').click()
})
it('can connect', () => {
const password = Cypress.env('browser-password') || 'newpassword'
const password = Cypress.config.password
cy.connect(
'neo4j',
password
Expand Down
9 changes: 7 additions & 2 deletions e2e_tests/integration/params.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect */
/* global Cypress, cy, test, expect, before */

describe(':param in Browser', () => {
before(function () {
cy.visit(Cypress.config.url)
.title()
.should('include', 'Neo4j Browser')
})
it('handles :param without web worker', () => {
cy.executeCommand(':config userCypherThread: false').then(() => {
cy.executeCommand(':clear')
Expand All @@ -39,7 +44,7 @@ function runTests () {
let setParamQ
let getParamQ
// it('can connect', () => {
const password = Cypress.env('browser-password') || 'newpassword'
const password = Cypress.config.password
cy.connect(
'neo4j',
password
Expand Down
9 changes: 7 additions & 2 deletions e2e_tests/integration/plan.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect */
/* global Cypress, cy, test, expect, before */

describe('Plan output', () => {
before(function () {
cy.visit(Cypress.config.url)
.title()
.should('include', 'Neo4j Browser')
})
it('can connect', () => {
const password = Cypress.env('browser-password') || 'newpassword'
const password = Cypress.config.password
cy.connect(
'neo4j',
password
Expand Down
26 changes: 15 additions & 11 deletions e2e_tests/integration/style.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global Cypress, cy, test, expect */
/* global Cypress, cy, test, expect, before */

describe(':style', () => {
before(function () {
cy.visit(Cypress.config.url)
.title()
.should('include', 'Neo4j Browser')
})
it('can connect', () => {
const password = Cypress.env('browser-password') || 'newpassword'
cy.connect('neo4j', password)
const password = Cypress.config.password
cy.connect(
'neo4j',
password
)
})
it('print the current style', () => {
cy.executeCommand(':clear')
Expand All @@ -33,12 +41,10 @@ describe(':style', () => {

const query = ':style'
cy.executeCommand(query)
cy
.get('[data-test-id="frameCommand"]', { timeout: 10000 })
cy.get('[data-test-id="frameCommand"]', { timeout: 10000 })
.first()
.should('contain', query)
cy
.get('[data-test-id="frameContents"]', { timeout: 10000 })
cy.get('[data-test-id="frameContents"]', { timeout: 10000 })
.first()
.should('contain', 'node {')
.should('contain', 'relationship {')
Expand All @@ -48,12 +54,10 @@ describe(':style', () => {
cy.executeCommand(':clear')
cy.executeCommand(':style')
cy.get('[data-test-id="exportGrassButton"]', { timeout: 10000 })
cy
.get('[data-test-id="styleResetButton"]', { timeout: 10000 })
cy.get('[data-test-id="styleResetButton"]', { timeout: 10000 })
.first()
.click()
cy
.get('[data-test-id="frameContents"]', { timeout: 10000 })
cy.get('[data-test-id="frameContents"]', { timeout: 10000 })
.first()
.should('contain', 'No style generated or set yet')
})
Expand Down
Loading

0 comments on commit fd528f9

Please sign in to comment.