Skip to content

Commit

Permalink
Merge pull request #1478 from emanueldima/ui-tests
Browse files Browse the repository at this point in the history
Add basic end-to-end test with nightmare+jest+enzyme
  • Loading branch information
emanueldima authored May 24, 2017
2 parents 2410087 + 113bf35 commit adc10c0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 4 deletions.
3 changes: 3 additions & 0 deletions webui/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "react"]
}
15 changes: 11 additions & 4 deletions webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@
"license": "GPL-2.0",
"repository": "https://github.com/EUDAT-B2SHARE/b2share.git",
"scripts": {
"postinstall": "./copy_files.sh"
"postinstall": "./copy_files.sh",
"test": "jest"
},
"devDependencies": {
"babel-core": "^6.2.1",
"babel-jest": "^20.0.0",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"css-loader": "^0.23.0",
"enzyme": "^2.8.1",
"enzyme-to-json": "^1.5.1",
"jest": "^20.0.0",
"nightmare": "^2.10.0",
"react-addons-test-utils": "^15.5.1",
"style-loader": "^0.13.0",
"uglify-loader": "^1.3.0",
"webpack": "^1.12.14",
Expand All @@ -26,9 +33,9 @@
"immutable": "^3.7.6",
"moment": "^2.13.0",
"pluralize": "^1.2.1",
"react": "^15.0.1",
"react-dom": "^15.0.1",
"react-addons-shallow-compare": "^15.0.1",
"react": "^15.5.0",
"react-dom": "^15.5.0",
"react-addons-shallow-compare": "^15.5.0",
"react-router": "^2.1.1",
"react-toggle": "^2.2.0",
"react-widgets": "^3.2.4",
Expand Down
92 changes: 92 additions & 0 deletions webui/src/__tests__/homepage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Nightmare from 'nightmare'

jasmine.DEFAULT_TIMEOUT_INTERVAL=20*1000;

const B2SHARE_URL = "https://b2share.local/"
const B2ACCESS_AUTH_URL = "https://unity.eudat-aai.fz-juelich.de:8443/oauth2-as/oauth2-authz-web-entry"

const user = process.env.AUTOTEST_USER;
const pass = process.env.AUTOTEST_PASS;
const email = process.env.AUTOTEST_EMAIL;

if (!user || !pass || !email) {
console.log("user, pass and email environment variables not defined!");
console.log(user, pass, email);
}

var nightmare = Nightmare({
// show: true,
switches: {
'ignore-certificate-errors': true,
},
});

function step(msg) {
console.log(msg, "...")
}
function print_obj(o) {
for (var p in o) {
console.log(p)
}
}

async function assertPageContains(page, text) {
let body = await page.evaluate(()=>document.body.textContent);
await expect(body).toContain(text);
}

async function assertElementText(page, selector, text) {
const fn = (selector) => {
document.querySelector(selector).innerText
};
let elementText = await page.evaluate(fn, selector);
return expect(elementText == text);
}

describe('Smoke test', function () {
test('well formed homepage', async function () {
let page = nightmare.goto(B2SHARE_URL);

step("test homepage title");
expect(await page.title() == 'B2SHARE');

step("wait for menu")
await page.wait('#header-navbar-collapse a');

step("wait for records")
await page.wait('#page .home-page .record a');
});
});

describe('Smoke test2', function () {
test('user can login', async function () {
let page = nightmare.goto(B2SHARE_URL);

step("click on Login");
await page.wait('#header-navbar-collapse > .user > li > a')
.click('#header-navbar-collapse > .user > li > a');

step("check if redirected to B2ACCESS");
await expect(page.url() == B2ACCESS_AUTH_URL);

step("check if we are on B2ACCESS unity auth page");
await page.wait('#AuthenticationUI\\.username');
await assertPageContains(page, "Login to UNITY OAuth2 Authorization Server");

step("authenticate with user1");
await page.type('#AuthenticationUI\\.username', user)
.type('#WebPasswordRetrieval\\.password', pass)
.click('#AuthenticationUI\\.authnenticateButton')
.wait('#IdpButtonsBar\\.confirmButton')
.click('#IdpButtonsBar\\.confirmButton');

step("check if we are back to B2SHARE");
expect(page.title() == 'B2SHARE');

step("wait for menu");
await page.wait('#header-navbar-collapse a');

step("check that the test user is logged in");
await assertElementText(page, '#header-navbar-collapse > .user > li > a', email);
});
});

0 comments on commit adc10c0

Please sign in to comment.