Fix tests
This commit is contained in:
33
test/test.js
33
test/test.js
@@ -32,10 +32,8 @@ describe('Application life cycle test', function () {
|
|||||||
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
||||||
|
|
||||||
let browser, app;
|
let browser, app;
|
||||||
var athenticated_by_oidc = false;
|
const username = process.env.USERNAME;
|
||||||
let username = process.env.USERNAME;
|
const password = process.env.PASSWORD;
|
||||||
let password = process.env.PASSWORD;
|
|
||||||
let manifest = require('../CloudronManifest.json');
|
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
|
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
|
||||||
@@ -59,10 +57,6 @@ describe('Application life cycle test', function () {
|
|||||||
fs.writeFileSync(`./screenshots/${new Date().getTime()}-${this.currentTest.title.replaceAll(' ', '_')}.png`, screenshotData, 'base64');
|
fs.writeFileSync(`./screenshots/${new Date().getTime()}-${this.currentTest.title.replaceAll(' ', '_')}.png`, screenshotData, 'base64');
|
||||||
});
|
});
|
||||||
|
|
||||||
function sleep(millis) {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, millis));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function waitForElement(elem) {
|
async function waitForElement(elem) {
|
||||||
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
||||||
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
||||||
@@ -98,7 +92,7 @@ describe('Application life cycle test', function () {
|
|||||||
await browser.sleep(3000); // can be wizard or timeline at this point
|
await browser.sleep(3000); // can be wizard or timeline at this point
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loginOIDC(username, password) {
|
async function loginOIDC(username, password, hasSession) {
|
||||||
browser.manage().deleteAllCookies();
|
browser.manage().deleteAllCookies();
|
||||||
await browser.get(`https://${app.fqdn}/auth/sign_in`);
|
await browser.get(`https://${app.fqdn}/auth/sign_in`);
|
||||||
await browser.sleep(4000);
|
await browser.sleep(4000);
|
||||||
@@ -106,18 +100,16 @@ describe('Application life cycle test', function () {
|
|||||||
await browser.findElement(By.xpath('//a[contains(@class, "button") and text()="Cloudron"]')).click();
|
await browser.findElement(By.xpath('//a[contains(@class, "button") and text()="Cloudron"]')).click();
|
||||||
await browser.sleep(4000);
|
await browser.sleep(4000);
|
||||||
|
|
||||||
if (!athenticated_by_oidc) {
|
if (!hasSession) {
|
||||||
await waitForElement(By.xpath('//input[@name="username"]'));
|
await waitForElement(By.xpath('//input[@name="username"]'));
|
||||||
await browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
|
await browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
|
||||||
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
|
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
|
||||||
await browser.sleep(2000);
|
await browser.sleep(2000);
|
||||||
await browser.findElement(By.id('loginSubmitButton')).click();
|
await browser.findElement(By.id('loginSubmitButton')).click();
|
||||||
await browser.sleep(2000);
|
await browser.sleep(2000);
|
||||||
|
|
||||||
athenticated_by_oidc = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await waitForElement(By.xpath('//a[contains(., "Edit profile")] | //strong[text()="Successfully authenticated from Cloudron account."]'));
|
await waitForElement(By.xpath('//span[contains(., "Bookmarks")] | //strong[text()="Successfully authenticated from Cloudron account."]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
@@ -153,7 +145,7 @@ describe('Application life cycle test', function () {
|
|||||||
it('has registration open', checkRegistration.bind(null, 'none'));
|
it('has registration open', checkRegistration.bind(null, 'none'));
|
||||||
let testPassword;
|
let testPassword;
|
||||||
it('create a user with CLI', function () {
|
it('create a user with CLI', function () {
|
||||||
let output = execSync('cloudron exec --app ' + LOCATION + ' -- bin/tootctl accounts create test --email=test@cloudron.io', { cwd: path.resolve(__dirname, '..'), encoding: 'utf8' });
|
const output = execSync('cloudron exec --app ' + LOCATION + ' -- bin/tootctl accounts create test --email=test@cloudron.io', { cwd: path.resolve(__dirname, '..'), encoding: 'utf8' });
|
||||||
console.log(output);
|
console.log(output);
|
||||||
testPassword = output.slice(output.indexOf('New password: ') + 'New password: '.length).trim();
|
testPassword = output.slice(output.indexOf('New password: ') + 'New password: '.length).trim();
|
||||||
console.log(testPassword);
|
console.log(testPassword);
|
||||||
@@ -177,7 +169,7 @@ describe('Application life cycle test', function () {
|
|||||||
|
|
||||||
it('can get app information', getAppInfo);
|
it('can get app information', getAppInfo);
|
||||||
it('registration is disabled', checkRegistration.bind(null, 'none'));
|
it('registration is disabled', checkRegistration.bind(null, 'none'));
|
||||||
it('can OIDC login', loginOIDC.bind(null, username, password));
|
it('can OIDC login', loginOIDC.bind(null, username, password, false));
|
||||||
it('can dismiss help', dismissHelp);
|
it('can dismiss help', dismissHelp);
|
||||||
it('can see timeline', checkTimeline);
|
it('can see timeline', checkTimeline);
|
||||||
it('can logout', logout);
|
it('can logout', logout);
|
||||||
@@ -191,7 +183,7 @@ describe('Application life cycle test', function () {
|
|||||||
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can OIDC login', loginOIDC.bind(null, username, password));
|
it('can OIDC login', loginOIDC.bind(null, username, password, true));
|
||||||
it('can see timeline', checkTimeline);
|
it('can see timeline', checkTimeline);
|
||||||
|
|
||||||
it('can restart app', function () { execSync('cloudron restart --app ' + app.id, EXEC_ARGS); });
|
it('can restart app', function () { execSync('cloudron restart --app ' + app.id, EXEC_ARGS); });
|
||||||
@@ -203,7 +195,7 @@ describe('Application life cycle test', function () {
|
|||||||
});
|
});
|
||||||
it('can get app information', getAppInfo);
|
it('can get app information', getAppInfo);
|
||||||
|
|
||||||
it('can OIDC login', loginOIDC.bind(null, username, password));
|
it('can OIDC login', loginOIDC.bind(null, username, password, true));
|
||||||
it('can see timeline', checkTimeline);
|
it('can see timeline', checkTimeline);
|
||||||
|
|
||||||
it('uninstall app', async function () {
|
it('uninstall app', async function () {
|
||||||
@@ -212,10 +204,9 @@ describe('Application life cycle test', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// test update
|
// test update
|
||||||
it('can install app', function () { execSync('cloudron install --appstore-id ' + manifest.id + ' --location ' + LOCATION, EXEC_ARGS); });
|
it('can install app', function () { execSync('cloudron install --appstore-id org.joinmastodon.cloudronapp --location ' + LOCATION, EXEC_ARGS); });
|
||||||
it('can get app information', getAppInfo);
|
it('can get app information', getAppInfo);
|
||||||
// needs to be changed to loginOIDC on the next release
|
it('can OIDC login', loginOIDC.bind(null, username, password, true));
|
||||||
it('can OIDC login', loginOIDC.bind(null, username, password));
|
|
||||||
it('can logout', logout);
|
it('can logout', logout);
|
||||||
|
|
||||||
it('can update', async function () {
|
it('can update', async function () {
|
||||||
@@ -223,7 +214,7 @@ describe('Application life cycle test', function () {
|
|||||||
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
|
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can OIDC login', loginOIDC.bind(null, username, password));
|
it('can OIDC login', loginOIDC.bind(null, username, password, true));
|
||||||
|
|
||||||
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
|
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user