-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #833 from oskarhane/desktop-url-field
Use `url` field from Neo4j Desktop context if it exists
- Loading branch information
Showing
4 changed files
with
121 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters