Commit e7b24f66 authored by Johannes Zellner's avatar Johannes Zellner

Add tests

parent 0d3a2ad0
{
"node": true,
"browser": true,
"unused": true,
"globalstrict": true,
"predef": [ "angular", "$", "describe", "it", "before", "after" ]
}
This diff is collapsed.
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"expect.js": "^0.3.1",
"mocha": "^8.0.1"
},
"dependencies": {
"chromedriver": "^83.0.0",
"selenium-server-standalone-jar": "^3.141.59",
"selenium-webdriver": "^3.6.0"
}
}
#!/usr/bin/env node
/* global describe */
/* global before */
/* global after */
/* global it */
'use strict';
require('chromedriver');
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');
describe('Application life cycle test', function () {
this.timeout(0);
var app;
var server, browser = new Builder().forBrowser('chrome').build();
const USERNAME = 'admin';
const PASSWORD = 'admin';
const LOCATION = 'test';
const TEST_TIMEOUT = 100000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
const MONITOR_NAME = 'cloudron';
const MONITOR_URL = 'https://cloudron.io';
before(function () {
var seleniumJar= require('selenium-server-standalone-jar');
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
server = new SeleniumServer(seleniumJar.path, { port: 4444 });
server.start();
});
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 login(callback) {
browser.manage().deleteAllCookies();
browser.get(`https://${app.fqdn}/dashboard`).then(function () {
return waitForElement(By.id('username'));
}).then(function () {
return browser.findElement(By.id('username')).sendKeys(USERNAME);
}).then(function () {
return browser.findElement(By.id('password')).sendKeys(PASSWORD);
}).then(function () {
return browser.findElement(By.xpath('//button[@type="submit"]')).submit();
}).then(function () {
return waitForElement(By.xpath('//span[text()="Total Services"]'));
}).then(function () {
callback();
});
}
function getAppInfo() {
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
expect(app).to.be.an('object');
}
function createMonitor(done) {
browser.get(`https://${app.fqdn}/dashboard/create_service`).then(function () {
return waitForElement(By.id('name'));
}).then(function () {
return browser.findElement(By.id('name')).sendKeys(MONITOR_NAME);
}).then(function () {
return browser.findElement(By.id('service_url')).sendKeys(MONITOR_URL);
}).then(function () {
return browser.findElement(By.xpath('//button[@type="submit"]')).click();
}).then(function () {
return waitForElement(By.xpath('//a[@href="/dashboard/create_service"]'));
}).then(function () {
done();
});
}
function monitorExists(done) {
browser.get(`https://${app.fqdn}`).then(function () {
return waitForElement(By.xpath(`//a[text()="${MONITOR_NAME}"]`));
}).then(function () {
done();
});
}
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 login', login);
it('can create monitor', createMonitor);
it('monitor exists', monitorExists);
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
it('monitor exists', monitorExists);
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('monitor exists', monitorExists);
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('monitor exists', monitorExists);
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();
});
});
// test update
// it('can install app', function () { execSync(`cloudron install --appstore-id io.taiga.cloudronapp --location ${LOCATION}`, EXEC_ARGS); });
// it('can get app information', getAppInfo);
// it('can login', login);
// it('can create monitor', createMonitor);
// it('monitor exists', monitorExists);
// it('can update', function () { execSync(`cloudron update --app ${LOCATION}`, EXEC_ARGS); });
// it('can login', login);
// it('monitor exists', monitorExists);
// 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();
// });
// });
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment