Add tests
parent
ac43f35b70
commit
eedfc23314
|
@ -0,0 +1 @@
|
|||
test/node_modules
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"chromedriver": "^80.0.2",
|
||||
"expect.js": "^0.3.1",
|
||||
"mocha": "^7.1.1",
|
||||
"selenium-webdriver": "^3.6.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,192 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/* global describe */
|
||||
/* global before */
|
||||
/* global after */
|
||||
/* global it */
|
||||
|
||||
'use strict';
|
||||
|
||||
var execSync = require('child_process').execSync,
|
||||
expect = require('expect.js'),
|
||||
path = require('path'),
|
||||
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
||||
{ Options } = require('selenium-webdriver/chrome');
|
||||
|
||||
if (!process.env.USERNAME || !process.env.PASSWORD) {
|
||||
console.log('USERNAME and PASSWORD env vars need to be set');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
describe('Application life cycle test', function () {
|
||||
this.timeout(0);
|
||||
|
||||
const LOCATION = 'test';
|
||||
const TEST_TIMEOUT = 10000;
|
||||
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
||||
const EMAIL = 'admin@server.local';
|
||||
const PASSWORD = 'changeME123?!12354';
|
||||
const ITEM_NAME = 'Test Item'
|
||||
|
||||
var browser, app;
|
||||
|
||||
before(function () {
|
||||
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
|
||||
});
|
||||
|
||||
after(function () {
|
||||
browser.quit();
|
||||
});
|
||||
|
||||
function waitForElement(elem) {
|
||||
return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
|
||||
return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
||||
});
|
||||
}
|
||||
|
||||
function getAppInfo() {
|
||||
var inspect = JSON.parse(execSync('cloudron inspect'));
|
||||
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
||||
expect(app).to.be.an('object');
|
||||
}
|
||||
|
||||
function signup(callback) {
|
||||
browser.get(`https://${app.fqdn}/#/register?email=${EMAIL}`).then(function () {
|
||||
return waitForElement(By.id('masterPassword'));
|
||||
}).then(function () {
|
||||
return browser.findElement(By.id('masterPassword')).sendKeys(PASSWORD);
|
||||
}).then(function () {
|
||||
return browser.findElement(By.id('masterPasswordRetype')).sendKeys(PASSWORD);
|
||||
}).then(function () {
|
||||
return browser.findElement(By.xpath('//form')).submit();
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath('//label[text()="Remember email"]'));
|
||||
}).then(function () {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function login(callback) {
|
||||
browser.get(`https://${app.fqdn}`).then(function () {
|
||||
return waitForElement(By.id('email'));
|
||||
}).then(function () {
|
||||
return browser.findElement(By.id('email')).clear();
|
||||
}).then(function () {
|
||||
return browser.findElement(By.id('email')).sendKeys(EMAIL);
|
||||
}).then(function () {
|
||||
return browser.findElement(By.id('masterPassword')).sendKeys(PASSWORD);
|
||||
}).then(function () {
|
||||
return browser.findElement(By.xpath('//form')).submit();
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath('//a[text()="Settings"]'));
|
||||
}).then(function () {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function logout(callback) {
|
||||
// get over the lock first
|
||||
browser.get(`https://${app.fqdn}`).then(function () {
|
||||
return browser.findElement(By.id('masterPassword')).sendKeys(PASSWORD);
|
||||
}).then(function () {
|
||||
return browser.findElement(By.xpath('//form')).submit();
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath('//a[text()="Settings"]'));
|
||||
}).then(function () {
|
||||
return browser.findElement(By.id('nav-profile')).click();
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath('//button[@class="dropdown-item"][2]'));
|
||||
}).then(function () {
|
||||
return browser.findElement(By.xpath('//button[@class="dropdown-item"][2]')).click();
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath('//label[text()="Remember email"]'));
|
||||
}).then(function () {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function createItem(callback) {
|
||||
browser.get(`https://${app.fqdn}`).then(function () {
|
||||
return browser.findElement(By.id('masterPassword')).sendKeys(PASSWORD);
|
||||
}).then(function () {
|
||||
return browser.findElement(By.xpath('//form')).submit();
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath('//a[text()="Settings"]'));
|
||||
}).then(function () {
|
||||
return browser.findElement(By.xpath('//div[contains(@class, "page-header")]//button[contains(@class, "btn-outline-primary")]')).click();
|
||||
}).then(function () {
|
||||
return waitForElement(By.id('name'));
|
||||
}).then(function () {
|
||||
return browser.findElement(By.id('name')).sendKeys(ITEM_NAME);
|
||||
}).then(function () {
|
||||
return browser.sleep(2000);
|
||||
}).then(function () {
|
||||
return browser.findElement(By.xpath('//div[contains(@class, "modal")]//form')).submit();
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath(`//a[text()="${ITEM_NAME}"]`));
|
||||
}).then(function () {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function itemExists(callback) {
|
||||
browser.get(`https://${app.fqdn}`).then(function () {
|
||||
return browser.findElement(By.id('masterPassword')).sendKeys(PASSWORD);
|
||||
}).then(function () {
|
||||
return browser.findElement(By.xpath('//form')).submit();
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath('//a[text()="Settings"]'));
|
||||
}).then(function () {
|
||||
return waitForElement(By.xpath(`//a[text()="${ITEM_NAME}"]`));
|
||||
}).then(function () {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
||||
it('install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_ARGS); });
|
||||
|
||||
it('can get app information', getAppInfo);
|
||||
it('can signup', signup);
|
||||
it('can login', login);
|
||||
it('can create item', createItem);
|
||||
it('item exists', itemExists);
|
||||
it('can logout', logout);
|
||||
|
||||
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
|
||||
|
||||
it('can login', login);
|
||||
it('item exists', itemExists);
|
||||
it('can logout', logout);
|
||||
|
||||
it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS); });
|
||||
it('restore app', function () { execSync(`cloudron restore --app ${app.id}`, EXEC_ARGS); });
|
||||
|
||||
it('can login', login);
|
||||
it('item exists', itemExists);
|
||||
it('can logout', logout);
|
||||
|
||||
it('move to different location', function (done) {
|
||||
// ensure we don't hit NXDOMAIN in the mean time
|
||||
browser.get('about:blank').then(function () {
|
||||
execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get app information', getAppInfo);
|
||||
it('can login', login);
|
||||
it('item exists', itemExists);
|
||||
it('can logout', logout);
|
||||
|
||||
it('uninstall app', function (done) {
|
||||
// ensure we don't hit NXDOMAIN in the mean time
|
||||
browser.get('about:blank').then(function () {
|
||||
execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
// TODO update tests will come once we have an update
|
||||
});
|
Loading…
Reference in New Issue