From 991658042a77dfdda70f9cb3ce19b560069faef9 Mon Sep 17 00:00:00 2001 From: Emanuel Dima Date: Mon, 29 May 2017 14:44:31 +0200 Subject: [PATCH] improve end to end tests --- webui/package.json | 3 ++ webui/src/__tests__/common.js | 48 +++++++++++++++++++++ webui/src/__tests__/homepage.js | 74 +++++---------------------------- 3 files changed, 62 insertions(+), 63 deletions(-) create mode 100644 webui/src/__tests__/common.js diff --git a/webui/package.json b/webui/package.json index 05f4799b51..93dfc9333c 100644 --- a/webui/package.json +++ b/webui/package.json @@ -9,6 +9,9 @@ "postinstall": "./copy_files.sh", "test": "jest" }, + "jest": { + "modulePathIgnorePatterns": ["common.js"] + }, "devDependencies": { "babel-core": "^6.2.1", "babel-jest": "^20.0.0", diff --git a/webui/src/__tests__/common.js b/webui/src/__tests__/common.js new file mode 100644 index 0000000000..60f4cdc408 --- /dev/null +++ b/webui/src/__tests__/common.js @@ -0,0 +1,48 @@ +import Nightmare from 'nightmare'; + +jasmine.DEFAULT_TIMEOUT_INTERVAL=20*1000; + +export const nightmareConfig = { + // show: true, + switches: { + 'ignore-certificate-errors': true, + }, +}; + +export const B2ACCESS_AUTH_URL = "https://unity.eudat-aai.fz-juelich.de:8443/oauth2-as/oauth2-authz-web-entry"; + +export const B2SHARE_URL = process.env.B2SHARE_URL || process.env.B2SHARE_JSONSCHEMAS_HOST; +export const USER_NAME = process.env.AUTOTEST_USER; +export const USER_PASS = process.env.AUTOTEST_PASS; +export const USER_EMAIL = process.env.AUTOTEST_EMAIL; + +if (!B2SHARE_URL) { + console.log("B2SHARE_URL environment variables not defined!"); +} + +if (!USER_NAME || !USER_PASS || !USER_EMAIL) { + console.log("username or password or email environment variables not defined!"); +} + +export function step(msg) { + console.log(msg, "..."); +} + +export function print_obj(o) { + for (var p in o) { + console.log(p); + } +} + +export async function assertPageContains(page, text) { + let body = await page.evaluate(()=>document.body.textContent); + await expect(body).toContain(text); +} + +export async function assertElementText(page, selector, text) { + const fn = (selector) => { + document.querySelector(selector).innerText + }; + let elementText = await page.evaluate(fn, selector); + return expect(elementText == text); +} diff --git a/webui/src/__tests__/homepage.js b/webui/src/__tests__/homepage.js index d7888e3085..a64bb89d6c 100644 --- a/webui/src/__tests__/homepage.js +++ b/webui/src/__tests__/homepage.js @@ -1,92 +1,40 @@ -import Nightmare from 'nightmare' +import Nightmare from 'nightmare'; +import { B2ACCESS_AUTH_URL, B2SHARE_URL, USER_NAME, USER_PASS, USER_EMAIL, + nightmareConfig, step, print_obj, assertPageContains, assertElementText } from './common'; -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 () { +describe('Homepage', function () { test('well formed homepage', async function () { - let page = nightmare.goto(B2SHARE_URL); - - step("test homepage title"); + let page = Nightmare(nightmareConfig).goto(B2SHARE_URL); 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 () { +describe('Login', function () { test('user can login', async function () { - let page = nightmare.goto(B2SHARE_URL); + let page = Nightmare(nightmareConfig).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) + await page.type('#AuthenticationUI\\.username', USER_NAME) + .type('#WebPasswordRetrieval\\.password', USER_PASS) .click('#AuthenticationUI\\.authnenticateButton') .wait('#IdpButtonsBar\\.confirmButton') .click('#IdpButtonsBar\\.confirmButton'); - step("check if we are back to B2SHARE"); - expect(page.title() == 'B2SHARE'); + expect(await 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); + await assertElementText(page, '#header-navbar-collapse > .user > li > a', USER_EMAIL); }); });