|
| 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 | +}) |
0 commit comments