Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Refactor + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Gina Contrino committed Nov 7, 2017
1 parent 38d7478 commit 88a21a1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 45 deletions.
22 changes: 12 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,21 @@ node('lisk-nano') {
stage ('Start Dev Server and Run E2E Tests') {
try {
ansiColor('xterm') {
sh '''
N=${EXECUTOR_NUMBER:-0}
withCredentials([string(credentialsId: 'lisk-nano-testnet-passphrase', variable: 'TESTNET_PASSPHRASE')]) {
sh '''
N=${EXECUTOR_NUMBER:-0}
# End to End test configuration
export DISPLAY=:1$N
Xvfb :1$N -ac -screen 0 1280x1024x24 &
# End to End test configuration
export DISPLAY=:1$N
Xvfb :1$N -ac -screen 0 1280x1024x24 &
# Run end-to-end tests
# Run end-to-end tests
npm run --silent e2e-test:testnet:custom -- --params.baseURL file://$WORKSPACE/app/build/index.html --params.liskCoreURL http://127.0.0.1:400$N --params.testnetCustomNode true
npm run --silent e2e-test:testnet -- --params.baseURL file://$WORKSPACE/app/build/index.html --params.liskCoreURL http://127.0.0.1:400$N $TESTNET_PASSPHRASE
npm run --silent e2e-test -- --params.baseURL file://$WORKSPACE/app/build/index.html --params.liskCoreURL http://127.0.0.1:400$N
'''
npm run --silent e2e-test -- --params.baseURL file://$WORKSPACE/app/build/index.html --params.liskCoreURL https://testnet.lisk.io --cucumberOpts.tags @testnet --params.network customNodeTestnet
npm run --silent e2e-test -- --params.baseURL file://$WORKSPACE/app/build/index.html --params.liskCoreURL http://127.0.0.1:400$N --cucumberOpts.tags @testnet --params.network testnet
npm run --silent e2e-test -- --params.baseURL file://$WORKSPACE/app/build/index.html --params.liskCoreURL http://127.0.0.1:400$N
'''
}
}
} catch (err) {
echo "Error: ${err}"
Expand Down
1 change: 1 addition & 0 deletions features/send.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Feature: Send dialog
@testnet
Scenario: should allow to send when enough funds and correct address form
Given I'm logged in as "genesis"
When I click "send button"
Expand Down
15 changes: 2 additions & 13 deletions features/step_definitions/generic.step.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
waitForElem,
checkAlertDialog,
waitTime,
getPassphrase,
} = require('../support/util.js');
const accounts = require('../support/accounts.js');

Expand All @@ -19,18 +20,6 @@ const expect = chai.expect;
const EC = protractor.ExpectedConditions;
const defaultTimeout = 10 * 1000;

const getNetworkType = (browser) => {
if (browser.params.testnetCustomNode) return 'customTestnet';
if (browser.params.testnet) return 'testnet';

return 'custom';
};
const getPassphrase = (browser, accountName) => ({
customTestnet: () => browser.params.testnetPassphrase,
testnet: () => browser.params.testnetPassphrase,
custom: () => accounts[accountName].passphrase,
}[getNetworkType(browser)]);

defineSupportCode(({ Given, When, Then, setDefaultTimeout }) => {
setDefaultTimeout(defaultTimeout);

Expand Down Expand Up @@ -152,7 +141,7 @@ defineSupportCode(({ Given, When, Then, setDefaultTimeout }) => {

Given('I\'m logged in as "{accountName}"', { timeout: 2 * defaultTimeout }, (accountName, callback) => {
browser.get(browser.params.baseURL);
waitForElemAndSendKeys('.passphrase input', (getPassphrase(browser)()), () => {
waitForElemAndSendKeys('.passphrase input', getPassphrase({ browser, account: accounts[accountName] }), () => {
waitForElemAndClickIt('.login-button', callback);
});
});
Expand Down
18 changes: 2 additions & 16 deletions features/step_definitions/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const { defineSupportCode } = require('cucumber');
const fs = require('fs');
const localStorage = require('../support/localStorage.js');
const { setNetwork } = require('../support/util.js');

function slugify(text) {
return text.toString().toLowerCase()
Expand Down Expand Up @@ -32,29 +33,14 @@ function takeScreenshot(screnarioSlug, callback) {
});
}

const getNetworkType = (browser) => {
if (browser.params.testnetCustomNode) return 'customTestnet';
if (browser.params.testnet) return 'testnet';

return 'custom';
};
const setNetwork = {
custom: () => { localStorage.setItem('network', 2); },
testnet: () => { localStorage.setItem('network', 1); },
customTestnet: () => {
localStorage.setItem('address', 'https://testnet.lisk.io');
localStorage.setItem('network', 2);
},
};

defineSupportCode(({ Before, After }) => {
Before((scenario, callback) => {
browser.ignoreSynchronization = true;
browser.driver.manage().window().setSize(1000, 1000);
browser.get(browser.params.baseURL);
localStorage.clear();
localStorage.setItem('address', browser.params.liskCoreURL);
setNetwork[getNetworkType(browser)]();
setNetwork[browser.params.network]();
callback();
});

Expand Down
16 changes: 16 additions & 0 deletions features/support/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable import/no-extraneous-dependencies */
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const localStorage = require('../support/localStorage.js');
const networks = require('./../../src/constants/networks');

chai.use(chaiAsPromised);
const expect = chai.expect;
Expand Down Expand Up @@ -59,6 +61,18 @@ function checkAlertDialog(title, text, callback = emptyFn) {
waitForElemAndCheckItsText('.modal-dialog .alert-dialog-message', text, callback);
}

const getPassphrase = ({ browser, account }) => ({
customNodeTestnet: browser.params.testnetPassphrase,
testnet: browser.params.testnetPassphrase,
customNode: account.passphrase,
}[browser.params.network]);

const setNetwork = {
customNode: () => { localStorage.setItem('network', networks.customNode.code); },
testnet: () => { localStorage.setItem('network', networks.testnet.code); },
customNodeTestnet: () => { localStorage.setItem('network', networks.customNode.code); },
};

module.exports = {
waitForElemAndCheckItsText,
waitForElemAndMatchItsText,
Expand All @@ -68,4 +82,6 @@ module.exports = {
checkAlertDialog,
waitTime,
waitForElem,
getPassphrase,
setNetwork,
};
1 change: 1 addition & 0 deletions features/voting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Feature: Voting tab
And I click checkbox on table row no. 5
And I should see no "voting bar"

@testnet
Scenario: should allow to select delegates in the "Voting" tab and vote for them
Given I'm logged in as "delegate candidate"
When I click tab number 2
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"build-prod": "webpack --config ./config/webpack.config.prod --env.prod",
"build-electron": "webpack --config ./config/webpack.config.electron",
"e2e-test": "protractor protractor.conf.js",
"e2e-test:testnet": "protractor protractor.conf.js \"--specs=features/send.feature:2:17,features/voting.feature:70\" \"--params.testnet=true\"",
"e2e-test:testnet:custom": "protractor protractor.conf.js \"--specs=features/send.feature:2:17,features/voting.feature:70\" \"--params.testnetCustomNode=true\"",
"test": "karma start",
"test-live": "npm test -- --auto-watch --no-single-run",
"start": "electron ./app/",
Expand Down
5 changes: 2 additions & 3 deletions protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.config = {

cucumberOpts: {
require: 'features/step_definitions/*.js',
tags: '~@ignore',
tags: [],
format: 'pretty',
profile: false,
'no-source': true,
Expand All @@ -25,7 +25,6 @@ exports.config = {
baseURL: 'http://localhost:8080/',
liskCoreURL: 'http://localhost:4000/',
testnetPassphrase: process.env.TESTNET_PASSPHRASE,
testnetCustomNode: false,
testnet: false,
network: 'customNode',
},
};
2 changes: 1 addition & 1 deletion src/constants/networks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
mainnet: { // network name translation t('Mainnet');
name: 'Mainnet',
ssl: true,
Expand Down

0 comments on commit 88a21a1

Please sign in to comment.