Skip to content

Commit

Permalink
Merge pull request #1085 from HerrEmil/aura-e2e
Browse files Browse the repository at this point in the history
Aura E2E testing
  • Loading branch information
oskarhane authored Apr 27, 2020
2 parents cc0b0e1 + 4c925fa commit 4971059
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 115 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Here are the available options / env variables:

```
server=3.2|3.3|3.4|3.5|4.0 (default 3.5)
edition=enterprise|community (default enterprise)
edition=enterprise|community|aura (default enterprise)
browser-password=<your-pw> (default 'newpassword')
include-import-tests=true|false (default false)
bolt-url=<bolt url excluding the protocol> (default localhost:7687)
Expand Down
54 changes: 32 additions & 22 deletions e2e_tests/integration/0.index.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/>.
*/

import { isEnterpriseEdition } from '../support/utils'
import { isAura, isEnterpriseEdition } from '../support/utils'

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

Expand Down Expand Up @@ -50,6 +50,7 @@ describe('Neo4j Browser', () => {
const password = Cypress.config('password')
cy.connect('neo4j', password)
})

it('can empty the db', () => {
cy.executeCommand(':clear')
const query = 'MATCH (n) DETACH DELETE n'
Expand Down Expand Up @@ -125,7 +126,9 @@ describe('Neo4j Browser', () => {
console.log('isEnterpriseEdition(): ', isEnterpriseEdition())
cy.get('[data-testid="user-details-roles"]').should(
'contain',
isEnterpriseEdition() || Cypress.config('serverVersion') < 4.0
isAura()
? 'PUBLIC'
: isEnterpriseEdition() || Cypress.config('serverVersion') < 4.0
? 'admin'
: '-'
)
Expand All @@ -138,37 +141,44 @@ describe('Neo4j Browser', () => {
cy.get('[data-testid="user-details-username"]').should('contain', 'neo4j')
cy.get('[data-testid="user-details-roles"]').should(
'contain',
isEnterpriseEdition() || Cypress.config('serverVersion') < 4.0
isAura()
? 'PUBLIC'
: isEnterpriseEdition() || Cypress.config('serverVersion') < 4.0
? 'admin'
: '-'
)
cy.get('[data-testid="drawerDBMS"]').click()
})
it('will clear local storage when clicking "Clear local data"', () => {
const scriptName = 'foo'
cy.get(Editor).type(`//${scriptName}`, { force: true })
cy.get('[data-testid="editorFavorite"]').click()

cy.get('[data-testid="drawerFavorites"]').click()
cy.get('.saved-scripts-list-item')
.first()
.should('be', scriptName)
// Browser sync is disabled on Aura
if (!isAura()) {
it('will clear local storage when clicking "Clear local data"', () => {
const scriptName = 'foo'
cy.get(Editor).type(`//${scriptName}`, { force: true })
cy.get('[data-testid="editorFavorite"]').click()

cy.get('[data-testid="drawerSync"]').click()
cy.get('[data-testid="clearLocalData"]').click()
cy.wait(500)
cy.get('[data-testid="drawerFavorites"]').click()
cy.get('.saved-scripts-list-item')
.first()
.should('be', scriptName)

// confirm clear
cy.get('[data-testid="clearLocalData"]').click()
cy.get('[data-testid="drawerSync"]').click()
cy.get('[data-testid="clearLocalData"]').click()
cy.wait(500)

cy.get('[data-testid="drawerFavorites"]').click()
cy.get('.saved-scripts-list-item').should('have.length', 0)
cy.get('[data-testid="drawerFavorites"]').click()
// confirm clear
cy.get('[data-testid="clearLocalData"]').click()

// once data is cleared the user is logged out and the connect form is displayed
cy.get('input[data-testid="boltaddress"]')
})
cy.get('[data-testid="drawerFavorites"]').click()
cy.get('.saved-scripts-list-item').should('have.length', 0)
cy.get('[data-testid="drawerFavorites"]').click()

// once data is cleared the user is logged out and the connect form is displayed
cy.get('input[data-testid="boltaddress"]')
})
}
it('displays no user info in sidebar (when not connected)', () => {
cy.executeCommand(':server disconnect')
cy.executeCommand(':clear')
cy.get('[data-testid="drawerDBMS"]').click()
cy.get('[data-testid="user-details-username"]').should('have.length', 0)
Expand Down
65 changes: 34 additions & 31 deletions e2e_tests/integration/desktop-env-url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/* global Cypress, cy, before */

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

Expand All @@ -41,41 +41,44 @@ describe('Neo4j Desktop environment using url field', () => {
}
})
})
it('can auto connect using url field', () => {
const frames = cy.get('[data-testid="frameCommand"]', { timeout: 10000 })
frames.should('have.length', 2)
// No need to run these when in Aura
if (!isAura()) {
it('can auto connect using url field', () => {
const frames = cy.get('[data-testid="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')
)
// 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-testid="frameCommand"]', { timeout: 10000 })
frames.should('have.length', 1)

frames.first().should('contain', ':server switch success')
const frames = cy.get('[data-testid="frameCommand"]', { timeout: 10000 })
frames.should('have.length', 1)

cy.get('[data-testid="frame"]', { timeout: 10000 })
.first()
.should('contain', 'Connection updated')
})
it('reacts to arguments changing and handle different encodings', () => {
// Use regular expression to match multiple lines
const expectedCommand = /RETURN 1;[^R]*RETURN 2;/
cy.executeCommand(':clear')
frames.first().should('contain', ':server switch success')

cy.wait(1000).then(() => {
appOnAgumentsChange('cmd=edit&arg=RETURN+1;&arg=RETURN%202;')
cy.get('[data-testid="frame"]', { timeout: 10000 })
.first()
.should('contain', 'Connection updated')
})
it('reacts to arguments changing and handle different encodings', () => {
// Use regular expression to match multiple lines
const expectedCommand = /RETURN 1;[^R]*RETURN 2;/
cy.executeCommand(':clear')

cy.getEditor().contains(expectedCommand)
})
cy.wait(1000).then(() => {
appOnAgumentsChange('cmd=edit&arg=RETURN+1;&arg=RETURN%202;')
})

cy.getEditor().contains(expectedCommand)
})
}
})
81 changes: 42 additions & 39 deletions e2e_tests/integration/desktop-env.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

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

let appContextListener

Expand All @@ -35,52 +35,55 @@ describe('Neo4j Desktop environment', () => {
}
})
})
it('can auto connect using host + post fields', () => {
const frames = cy.get('[data-testid="frameCommand"]', { timeout: 10000 })
frames.should('have.length', 2)
// No need to test these in Aura
if (!isAura()) {
it('can auto connect using host + post fields', () => {
const frames = cy.get('[data-testid="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 host + port fields', () => {
cy.executeCommand(':clear')
cy.wait(1000).then(() => {
appContextListener(
{ type: 'GRAPH_ACTIVE', id: 'test' },
getDesktopContext(Cypress.config, 'host')
)
// Auto connected = :play start
frames.first().should('contain', ':play start')
cy.wait(1000)
})
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' },
getDesktopContext(Cypress.config, 'host')
)
})

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

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

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

it('displays disconnected banner and connection failed frame when initial state is INACTIVE', () => {
cy.visit(Cypress.config('url'), {
onBeforeLoad: win => {
win.neo4jDesktopApi = {
getContext: () =>
Promise.resolve(
getDesktopContext(Cypress.config, 'host', 'INACTIVE')
)
it('displays disconnected banner and connection failed frame when initial state is INACTIVE', () => {
cy.visit(Cypress.config('url'), {
onBeforeLoad: win => {
win.neo4jDesktopApi = {
getContext: () =>
Promise.resolve(
getDesktopContext(Cypress.config, 'host', 'INACTIVE')
)
}
}
}
})
})

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

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

cy.get('[data-testid="disconnectedBanner"]', { timeout: 10000 })
.first()
.should('contain', 'Database access not available.')
})
cy.get('[data-testid="disconnectedBanner"]', { timeout: 10000 })
.first()
.should('contain', 'Database access not available.')
})
}
})
File renamed without changes.
7 changes: 5 additions & 2 deletions e2e_tests/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isAura } from './utils'

const SubmitQueryButton = '[data-testid="submitQuery"]'
const ClearEditorButton = '[data-testid="clearEditorContent"]'
const Editor = '.ReactCodeMirror textarea'
Expand All @@ -23,10 +25,11 @@ Cypress.Commands.add(
boltUrl = Cypress.config('boltUrl'),
force = false
) => {
if (Cypress.env('E2E_TEST_ENV') === 'local' && !force) {
if (!Cypress.config('setInitialPassword') && !force) {
// We assume pw already set on local
return
}

cy.title().should('include', 'Neo4j Browser')
cy.wait(3000)

Expand Down Expand Up @@ -85,7 +88,7 @@ Cypress.Commands.add(

cy.get('button[data-testid="connect"]').click()
if (makeAssertions) {
cy.get('[data-testid="frame"]', { timeout: 10000 }).should(
cy.get('[data-testid="frame"]', { timeout: 25000 }).should(
'have.length',
2
)
Expand Down
31 changes: 25 additions & 6 deletions e2e_tests/support/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,43 @@

Cypress.config('serverVersion', parseFloat(Cypress.env('server')) || 3.5)
Cypress.config('serverEdition', Cypress.env('edition') || 'enterprise')

Cypress.config(
'includeImportTests',
Cypress.env('include-import-tests') || false
)

// Don't set initial pw on local or aura
Cypress.config(
'setInitialPassword',
!['local', 'aura'].includes(Cypress.env('E2E_TEST_ENV'))
)

Cypress.config('url', '/')
Cypress.config('password', Cypress.env('browser-password') || 'newpassword')
Cypress.config(
'boltHost',
Cypress.env('bolt-url') ? Cypress.env('bolt-url').split(':')[0] : 'localhost'
Cypress.env('bolt-url')
? removeUriScheme(Cypress.env('bolt-url')).split(':')[0]
: 'localhost'
)
Cypress.config(
'boltPort',
Cypress.env('bolt-url') ? Cypress.env('bolt-url').split(':')[1] : 7687
Cypress.env('bolt-url')
? removeUriScheme(Cypress.env('bolt-url')).split(':')[1]
: 7687
)
Cypress.config(
'boltUrl',
'bolt://' +
(Cypress.env('bolt-url')
? Cypress.env('bolt-url')
: Cypress.config('boltHost') + ':' + Cypress.config('boltPort'))
Cypress.env('bolt-url')
? Cypress.env('bolt-url')
: 'bolt://' + Cypress.config('boltHost') + ':' + Cypress.config('boltPort')
)

function removeUriScheme(uri = '') {
const SEPARATOR = '://'
const [_skip, ...rest] = uri.includes(SEPARATOR)
? uri.split(SEPARATOR)
: [, uri]
return rest.join(SEPARATOR)
}
4 changes: 3 additions & 1 deletion e2e_tests/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
export const isEnterpriseEdition = () =>
Cypress.config('serverEdition') === 'enterprise'

export const isAura = () => Cypress.config('serverEdition') === 'aura'

export const getDesktopContext = (
config,
connectionCredsType = 'host',
Expand Down Expand Up @@ -42,7 +44,7 @@ const getBoltConfig = (config, type) => {
tlsLevel: config('baseUrl').startsWith('https') ? 'REQUIRED' : 'OPTIONAL'
}
if (type === 'url') {
obj.url = `bolt://${config('boltHost')}:${config('boltPort')}`
obj.url = config('boltUrl')
} else {
obj.host = config('boltHost')
obj.port = config('boltPort')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build": "NODE_ENV=\"production\" webpack --config ./build_scripts/webpack.config.js",
"dev": "jest --watch",
"e2e": "cypress run",
"e2e-aura": "CYPRESS_E2E_TEST_ENV=\"aura\" cypress run",
"e2e-local": "CYPRESS_E2E_TEST_ENV=\"local\" cypress run",
"e2e-local-open": "CYPRESS_E2E_TEST_ENV=\"local\" cypress open",
"format": "prettier-eslint --write 'src/**/!(*.min).{js,jsx,css,json}' 'e2e_tests/**/*.{js,jsx,css,json}' 'scripts/**/*.{js,jsx,css,json}' 'build_scripts/**/*.{js,jsx,css,json}'",
Expand Down
Loading

0 comments on commit 4971059

Please sign in to comment.