diff --git a/package.json b/package.json index 6d06109c2..874ee3d3c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ }, "scripts": { "build": "yarn workspace @okta/okta-auth-js build", - "clean": "yarn clean-node-modules", + "clean": "yarn clean-dist && yarn clean-node-modules", "clean-dist": "rimraf dist && lerna exec rimraf build2 && lerna exec rimraf dist", "clean-node-modules": "lerna exec rimraf node_modules && rimraf node_modules", "lint": "yarn workspaces run lint", diff --git a/test/app/.gitignore b/test/app/.gitignore index 22dea6242..174d81169 100644 --- a/test/app/.gitignore +++ b/test/app/.gitignore @@ -1,3 +1,5 @@ node_modules/ .yalc -*.log \ No newline at end of file +*.log +public/*.js +public/*.map diff --git a/test/app/public/index.html b/test/app/public/index.html index ab7dab468..8a8827a65 100644 --- a/test/app/public/index.html +++ b/test/app/public/index.html @@ -12,5 +12,19 @@ bootstrapLanding(); Server-side Login Form + + Static App \ No newline at end of file diff --git a/test/app/public/static/index.html b/test/app/public/static/index.html new file mode 100644 index 000000000..40932b844 --- /dev/null +++ b/test/app/public/static/index.html @@ -0,0 +1,111 @@ + + + + + + + + + + + +
+
+
+ Return Home + + + \ No newline at end of file diff --git a/test/app/server.js b/test/app/server.js index e8d005b12..44a45dd90 100644 --- a/test/app/server.js +++ b/test/app/server.js @@ -20,6 +20,7 @@ app.use(webpackDevMiddleware(compiler, { })); app.use(express.static('./public')); +app.use(express.static('../../packages/okta-auth-js/dist')); app.use(express.urlencoded()); app.post('/login', function(req, res) { diff --git a/test/app/src/webpackEntry.js b/test/app/src/webpackEntry.js index 4f023e427..a6d03be5d 100644 --- a/test/app/src/webpackEntry.js +++ b/test/app/src/webpackEntry.js @@ -7,6 +7,7 @@ import Cookies from 'js-cookie'; import TestApp from './testApp'; import { getDefaultConfig, getConfigFromUrl, getConfigFromStorage, clearStorage } from './config'; +import { toQueryParams } from './util'; let app; let config; @@ -24,6 +25,9 @@ function mount() { return app; } +window.getAuthJSConfig = getDefaultConfig; +window.toQueryParams = toQueryParams; + // Login page, read config from URL window.getWidgetConfig = function() { const siwConfig = window.location.search ? getConfigFromUrl() : getDefaultConfig(); diff --git a/test/e2e/pageobjects/StaticApp.js b/test/e2e/pageobjects/StaticApp.js new file mode 100644 index 000000000..e9d756ed2 --- /dev/null +++ b/test/e2e/pageobjects/StaticApp.js @@ -0,0 +1,60 @@ +import assert from 'assert'; +import toQueryParams from '../util/toQueryParams'; + +class StaticApp { + get unauth() { return $('#unauth'); } + get auth() { return $('#auth'); } + get userinfo() { return $('#userinfo'); } + get error() { return $('#error'); } + get login() { return $('#login'); } + get logout() { return $('#logout'); } + + async open() { + const ISSUER = process.env.ISSUER; + const CLIENT_ID = process.env.CLIENT_ID; + const params = toQueryParams({ + issuer: ISSUER, + clientId: CLIENT_ID + }); + await browser.url('/static' + params); + await browser.waitUntil(async () => this.error.then(el => el.isExisting()), 5000, 'wait for error selector'); + } + + async assertNoError() { + await this.error.then(el => el.getText()).then(txt => { + assert(txt === ''); + }); + } + + async waitForLoginBtn() { + return browser.waitUntil(async () => this.login.then(el => el.isDisplayed()), 5000, 'wait for login button'); + } + + async clickLogin() { + await this.waitForLoginBtn(); + await this.login.then(el => el.click()); + } + + async waitForUserInfo() { + return browser.waitUntil(async () => this.userinfo.then(el => el.isDisplayed()), 5000, 'wait for userinfo'); + } + + async assertUserInfo() { + await this.waitForUserInfo(); + await this.userinfo.then(el => el.getText()).then(txt => { + assert(txt !== ''); + }); + } + + async waitForLogoutBtn() { + return browser.waitUntil(async () => this.logout.then(el => el.isDisplayed()), 5000, 'wait for logout button'); + } + + async clickLogout() { + await this.waitForLogoutBtn(); + await this.logout.then(el => el.click()); + } + +} + +export default new StaticApp(); \ No newline at end of file diff --git a/test/e2e/specs/static.js b/test/e2e/specs/static.js new file mode 100644 index 000000000..46c3f1a78 --- /dev/null +++ b/test/e2e/specs/static.js @@ -0,0 +1,23 @@ +import StaticApp from '../pageobjects/StaticApp'; +import OktaLogin from '../pageobjects/OktaLogin'; +import TestApp from '../pageobjects/TestApp'; + +const USERNAME = process.env.USERNAME; +const PASSWORD = process.env.PASSWORD; + +describe('Static App', () => { + + beforeEach(async () => { + await StaticApp.open(); + }); + + it('can login, display userinfo, and logout', async () => { + await StaticApp.clickLogin(); + await OktaLogin.signin(USERNAME, PASSWORD); + await StaticApp.assertUserInfo(); + await StaticApp.assertNoError(); + await StaticApp.clickLogout(); + await TestApp.waitForLoginBtn(); + }); + +}); \ No newline at end of file