Skip to content

Commit

Permalink
Merge pull request #833 from oskarhane/desktop-url-field
Browse files Browse the repository at this point in the history
Use `url` field from Neo4j Desktop context if it exists
  • Loading branch information
pe4cey authored Oct 8, 2018
2 parents e30b135 + d6d94e3 commit 7e6444b
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 42 deletions.
68 changes: 68 additions & 0 deletions e2e_tests/integration/desktop-env-url.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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 */

import { getDesktopContext } from '../support/utils'
let appContextListener

// This file only esists to be able to test the auto connect using
// the host field.
// We can't load two times in the same file

describe('Neo4j Desktop environment using url field', () => {
before(() => {
cy.visit(Cypress.config.url, {
onBeforeLoad: win => {
win.neo4jDesktopApi = {
getContext: () =>
Promise.resolve(getDesktopContext(Cypress.config, 'url')),
onContextUpdate: fn => (appContextListener = fn.bind(fn))
}
}
})
})
it('can auto connect using url field', () => {
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 using url field', () => {
cy.executeCommand(':clear')
cy.wait(1000).then(() => {
appContextListener(
{ type: 'GRAPH_ACTIVE', id: 'test' },
getDesktopContext(Cypress.config, 'url')
)
})

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')
})
})
49 changes: 9 additions & 40 deletions e2e_tests/integration/desktop-env.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

/* global Cypress, cy, test, expect, before */
import { getDesktopContext } from '../support/utils'

let appContextListener

Expand All @@ -27,24 +28,28 @@ describe('Neo4j Desktop environment', () => {
cy.visit(Cypress.config.url, {
onBeforeLoad: win => {
win.neo4jDesktopApi = {
getContext: () => Promise.resolve(getContext()),
getContext: () =>
Promise.resolve(getDesktopContext(Cypress.config, 'url')),
onContextUpdate: fn => (appContextListener = fn.bind(fn))
}
}
})
})
it('can auto connect', () => {
it('can auto connect using host + post fields', () => {
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', () => {
it('switches connection when that event is triggered using host + port fields', () => {
cy.executeCommand(':clear')
cy.wait(1000).then(() => {
appContextListener({ type: 'GRAPH_ACTIVE', id: 'test' }, getContext())
appContextListener(
{ type: 'GRAPH_ACTIVE', id: 'test' },
getDesktopContext(Cypress.config, 'url')
)
})

const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 })
Expand All @@ -57,39 +62,3 @@ describe('Neo4j Desktop environment', () => {
.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'
}
}
}
}
}
]
}
]
})
42 changes: 42 additions & 0 deletions e2e_tests/support/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export const getDesktopContext = (config, connectionCredsType = 'host') => ({
projects: [
{
graphs: [
{
status: 'ACTIVE',
connection: {
type: 'REMOTE',
configuration: {
protocols: {
bolt: getBoltConfig(config, connectionCredsType),
http: {
enabled: true,
username: 'neo4j',
password: config.password,
host: 'localhost',
port: '7474'
}
}
}
}
}
]
}
]
})

const getBoltConfig = (config, type) => {
const obj = {
enabled: true,
username: 'neo4j',
password: config.password,
tlsLevel: config.url.startsWith('https') ? 'REQUIRED' : 'OPTIONAL'
}
if (type === 'url') {
obj.url = `bolt://${config.boltHost}:${config.boltPort}`
} else {
obj.host = config.boltHost
obj.port = config.boltPort
}
return obj
}
4 changes: 2 additions & 2 deletions src/browser/modules/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
...stateProps.defaultConnectionData,
...creds,
encrypted: creds.tlsLevel === 'REQUIRED',
host: `bolt://${creds.host}:${creds.port}`,
host: creds.url || `bolt://${creds.host}:${creds.port}`,
restApi
}
ownProps.bus.send(SWITCH_CONNECTION, connectionCreds)
Expand All @@ -212,7 +212,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
...stateProps.defaultConnectionData,
...creds,
encrypted: creds.tlsLevel === 'REQUIRED',
host: `bolt://${creds.host}:${creds.port}`,
host: creds.url || `bolt://${creds.host}:${creds.port}`,
restApi
}
ownProps.bus.send(INJECTED_DISCOVERY, connectionCreds)
Expand Down

0 comments on commit 7e6444b

Please sign in to comment.