Skip to content

Commit

Permalink
Merge pull request #738 from oskarhane/e2e-refactor
Browse files Browse the repository at this point in the history
Refactor and make e2e test more isolated
  • Loading branch information
pe4cey authored Apr 17, 2018
2 parents 5c24910 + 853edaa commit 001353c
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 105 deletions.
83 changes: 34 additions & 49 deletions e2e_tests/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,69 +32,53 @@ describe('Neo4j Browser', () => {
.should('include', 'Neo4j Browser')
})
it('sets new login credentials', () => {
cy.title().should('include', 'Neo4j Browser')

cy
.get('input[data-test-id="boltaddress"]')
.clear()
.type('bolt://localhost:7687')

cy.get('input[data-test-id="username"]').should('have.value', 'neo4j')
cy.get('input[data-test-id="password"]').should('have.value', '')

cy.get('input[data-test-id="password"]').type('neo4j')

cy.get('input[data-test-id="username"]').should('have.value', 'neo4j')

cy.get('button[data-test-id="connect"]').click()

// update password
cy.get('input[data-test-id="newPassword"]')
cy.get('input[data-test-id="newPassword"]').should('have.value', '')
cy
.get('input[data-test-id="newPasswordConfirmation"]')
.should('have.value', '')

const newPassword = Cypress.env('BROWSER_NEW_PASSWORD') || 'newpassword'
cy.get('input[data-test-id="newPassword"]').type(newPassword)
cy.get('input[data-test-id="newPasswordConfirmation"]').type(newPassword)
cy.get('button[data-test-id="changePassword"]').click()

cy.get('input[data-test-id="changePassword"]').should('not.be.visible')

cy.get('input[data-test-id="connect"]').should('not.be.visible')
cy.wait(500)
cy.setInitialPassword(newPassword)
cy.disconnect()
})
it('can login', () => {
cy.executeCommand(':clear')
cy.executeCommand(':server connect')
const password = Cypress.env('BROWSER_NEW_PASSWORD') || 'newpassword'
cy.connect(password)
})
it('can empty the db', () => {
cy.executeCommand(':clear')
const query = 'MATCH (n) DETACH DELETE n'
cy.executeCommand(query)
cy
.get('[data-test-id="frameCommand"]')
.get('[data-test-id="frameCommand"]', { timeout: 10000 })
.first()
.should('contain', query)
cy
.get('[data-test-id="frameStatusbar"]', { timeout: 100000 })
.first()
.should('contain', ':play start')
.contains(/completed/i)
})
it('can run cypher statement', () => {
const cypher = 'return 1'
cy.get(Editor).type(cypher, { force: true })
cy.get(Editor).should('have.value', cypher)
cy.get(SubmitQueryButton).click()
cy.executeCommand(':clear')
const query = 'return 1'
cy.executeCommand(query)
cy
.get('[data-test-id="frameLoading"]', { timeout: 10000 })
.should('not.be.visible')
cy
.get('[data-test-id="frameCommand"]', { timeout: 10000 })
.first()
.should('contain', cypher)
.should('contain', query)
cy
.get('[data-test-id="frameLoading"]', { timeout: 10000 })
.should('not.be.visible')
.get('[data-test-id="frameStatusbar"]', { timeout: 10000 })
.first()
.should('contain', 'Started streaming')
})
it('can exec cypher from `:play movies`', () => {
const cypher = ':play movies'
cy.get('[data-test-id="clearEditorContent"]').click()

cy.get(Editor).type(cypher, { force: true })
cy.get(Editor).should('have.value', cypher)

cy.get(SubmitQueryButton).click()
cy.executeCommand(':clear')
const query = ':play movies'
cy.executeCommand(query)
cy
.get('[data-test-id="frameCommand"]')
.first()
.should('contain', cypher)

.should('contain', query)
cy
.get(Carousel)
.find('[data-test-id="nextSlide"]')
Expand All @@ -118,6 +102,7 @@ describe('Neo4j Browser', () => {
.should('contain', 'Emil Eifrem')
})
it('can display meta items from side drawer', () => {
cy.executeCommand(':clear')
cy.get('[data-test-id="drawerDB"]').click()
cy
.get('[data-test-id="sidebarMetaItem"]', { timeout: 30000 })
Expand Down
118 changes: 79 additions & 39 deletions e2e_tests/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,79 @@
// ***********************************************
// This example commands.js shows you how to
// create the custom command: 'login'.
//
// The commands.js file is a great place to
// modify existing commands and create custom
// commands for use throughout your tests.
//
// You can read more about custom commands here:
// https://on.cypress.io/api/commands
// ***********************************************
//
// Cypress.addParentCommand("login", function(email, password){
// var email = email || "joe@example.com"
// var password = password || "foobar"
//
// var log = Cypress.Log.command({
// name: "login",
// message: [email, password],
// consoleProps: function(){
// return {
// email: email,
// password: password
// }
// }
// })
//
// cy
// .visit("/login", {log: false})
// .contains("Log In", {log: false})
// .get("#email", {log: false}).type(email, {log: false})
// .get("#password", {log: false}).type(password, {log: false})
// .get("button", {log: false}).click({log: false}) //this should submit the form
// .get("h1", {log: false}).contains("Dashboard", {log: false}) //we should be on the dashboard now
// .url({log: false}).should("match", /dashboard/, {log: false})
// .then(function(){
// log.snapshot().end()
// })
// })
const SubmitQueryButton = '[data-test-id="submitQuery"]'
const ClearEditorButton = '[data-test-id="clearEditorContent"]'
const Editor = '.ReactCodeMirror textarea'

/* global Cypress, cy */

Cypress.Commands.add('setInitialPassword', newPassword => {
if (Cypress.env('E2E_TEST_ENV') === 'local') {
// We assume pw already set on local
return
}
cy.title().should('include', 'Neo4j Browser')

cy
.get('input[data-test-id="boltaddress"]')
.clear()
.type('bolt://localhost:7687')

cy.get('input[data-test-id="username"]').should('have.value', 'neo4j')
cy.get('input[data-test-id="password"]').should('have.value', '')

cy.get('input[data-test-id="password"]').type('neo4j')

cy.get('input[data-test-id="username"]').should('have.value', 'neo4j')

cy.get('button[data-test-id="connect"]').click()

// update password
cy.get('input[data-test-id="newPassword"]')
cy.get('input[data-test-id="newPassword"]').should('have.value', '')
cy
.get('input[data-test-id="newPasswordConfirmation"]')
.should('have.value', '')

cy.get('input[data-test-id="newPassword"]').type(newPassword)
cy.get('input[data-test-id="newPasswordConfirmation"]').type(newPassword)
cy.get('button[data-test-id="changePassword"]').click()

cy.get('input[data-test-id="changePassword"]').should('not.be.visible')

cy.get('input[data-test-id="connect"]').should('not.be.visible')
cy.wait(500)
cy
.get('[data-test-id="frameCommand"]')
.first()
.should('contain', ':play start')
})
Cypress.Commands.add('connect', password => {
cy.title().should('include', 'Neo4j Browser')
cy
.get('input[data-test-id="boltaddress"]')
.clear()
.type('bolt://localhost:7687')

cy.get('input[data-test-id="username"]').should('have.value', 'neo4j')
cy.get('input[data-test-id="password"]').should('have.value', '')

cy.get('input[data-test-id="password"]').type(password)

cy.get('input[data-test-id="username"]').should('have.value', 'neo4j')

cy.get('button[data-test-id="connect"]').click()
cy.get('[data-test-id="frame"]', { timeout: 10000 }).should('have.length', 2)
cy.wait(500)
cy
.get('[data-test-id="frameCommand"]')
.first()
.should('contain', ':play start')
})
Cypress.Commands.add('disconnect', () => {
const query = ':server disconnect'
cy.executeCommand(query)
})
Cypress.Commands.add('executeCommand', query => {
cy.get(ClearEditorButton).click()
cy.get(Editor).type(query, { force: true })
cy.get(Editor).should('have.value', query)
cy.get(SubmitQueryButton).click()
})
8 changes: 8 additions & 0 deletions e2e_tests/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// https://on.cypress.io/guides/configuration#section-global
// ***********************************************************

/* global Cypress, cy */

// Import commands.js and defaults.js
// using ES2015 syntax:
import './commands'
Expand All @@ -21,3 +23,9 @@ import './defaults'
// Alternatively you can use CommonJS syntax:
// require("./commands")
// require("./defaults")

afterEach(function () {
if (this.currentTest.state === 'failed') {
Cypress.runner.stop()
}
})
29 changes: 13 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@
"apiVersion": "^1.2.0"
},
"scripts": {
"start": "webpack-dashboard -t 'Neo4j Browser' -- webpack-dev-server --colors --no-info",
"starts": "webpack-dashboard -t 'Neo4j Browser' -- webpack-dev-server --https --colors --no-info",
"start":
"webpack-dashboard -t 'Neo4j Browser' -- webpack-dev-server --colors --no-info",
"starts":
"webpack-dashboard -t 'Neo4j Browser' -- webpack-dev-server --https --colors --no-info",
"startnodash": "webpack-dev-server --colors --no-info",
"precommit": "lint-staged",
"format": "prettier-eslint 'src/**/!(*.min).js' 'src/**/*.jsx' --write",
"lint": "eslint --fix --ext .js --ext .jsx ./",
"test": "npm run lint && jest",
"e2e": "cypress run",
"e2e-local": "CYPRESS_E2E_TEST_ENV=\"local\" cypress run",
"e2e-local-open": "CYPRESS_E2E_TEST_ENV=\"local\" cypress open",
"dev": "jest --watch",
"build": "rm -rf ./dist && NODE_ENV=\"production\" webpack",
"prepare-jar": "node ./scripts/prepare-mvn-package.js",
"jar": "yarn build && mvn package",
"version-pom": "node ./scripts/set-pom-version.js -f ./pom.xml -v $npm_package_version",
"version-pom":
"node ./scripts/set-pom-version.js -f ./pom.xml -v $npm_package_version",
"version": "npm run version-pom && git add ./pom.xml",
"update-licenses": "sh ./scripts/generate_licenses.sh"
},
"lint-staged": {
"linters": {
"*.{js,jsx}": [
"prettier-eslint --write",
"git add"
]
"*.{js,jsx}": ["prettier-eslint --write", "git add"]
}
},
"jest": {
"testPathIgnorePatterns": [
".jsx$",
"/e2e_tests/"
],
"testPathIgnorePatterns": [".jsx$", "/e2e_tests/"],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|html)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|html)$":
"<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
"neo4j": "<rootDir>/__mocks__/neo4j.js",
"^react-dom/server$": "preact-render-to-string",
Expand All @@ -57,10 +57,7 @@
"^browser-components(.*)$": "<rootDir>/src/browser/components$1",
"worker-loader": "<rootDir>/__mocks__/workerLoaderMock.js"
},
"modulePaths": [
"<rootDir>/src",
"<rootDir>/src/shared"
]
"modulePaths": ["<rootDir>/src", "<rootDir>/src/shared"]
},
"devDependencies": {
"autoprefixer": "^7.1.4",
Expand Down
5 changes: 4 additions & 1 deletion src/browser/modules/Stream/FrameTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ class FrameTemplate extends Component {
{this.props.contents}
</StyledFrameContents>
<Render if={this.props.statusbar}>
<StyledFrameStatusbar fullscreen={this.state.fullscreen}>
<StyledFrameStatusbar
fullscreen={this.state.fullscreen}
data-test-id='frameStatusbar'
>
{this.props.statusbar}
</StyledFrameStatusbar>
</Render>
Expand Down

0 comments on commit 001353c

Please sign in to comment.