syncthing-app/test/test.js

198 lines
7.2 KiB
JavaScript
Raw Normal View History

2017-05-05 11:19:38 +00:00
#!/usr/bin/env node
2021-04-06 09:24:39 +00:00
/* jshint esversion: 8 */
2020-05-05 10:42:59 +00:00
/* global describe */
/* global before */
/* global after */
/* global it */
2021-04-06 09:24:39 +00:00
'use strict';
2018-04-07 00:02:37 +00:00
require('chromedriver');
2022-05-03 21:51:25 +00:00
const execSync = require('child_process').execSync,
2017-05-05 11:19:38 +00:00
expect = require('expect.js'),
2018-02-27 02:07:00 +00:00
superagent = require('superagent'),
2017-05-05 11:19:38 +00:00
path = require('path'),
2020-11-03 12:33:53 +00:00
{ Builder, By, Key, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
2017-05-05 11:19:38 +00:00
describe('Application life cycle test', function () {
this.timeout(0);
2017-06-10 09:33:48 +00:00
var LOCATION = 'test';
2017-05-08 09:47:39 +00:00
var TEST_TIMEOUT = 30000;
2018-05-02 20:33:07 +00:00
var FOLDER = 'xmf'; // keep this small. long folder names fail in automation, not sure why
2017-05-08 09:47:39 +00:00
var SYNC_PORT = 22001;
2020-05-05 10:42:59 +00:00
var EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
2020-11-03 12:33:53 +00:00
var browser;
2017-05-05 11:19:38 +00:00
var app;
2020-11-03 12:33:53 +00:00
var username = 'admin', password = 'changeme';
before(function () {
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
});
after(function () {
browser.quit();
});
2017-05-05 11:19:38 +00:00
2020-05-05 10:42:59 +00:00
function getAppInfo() {
var inspect = JSON.parse(execSync('cloudron inspect'));
2020-11-03 14:38:03 +00:00
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
2020-05-05 10:42:59 +00:00
expect(app).to.be.an('object');
2018-02-27 00:56:42 +00:00
}
2020-11-03 14:38:03 +00:00
function waitForElement(elem) {
return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
2017-05-05 11:19:38 +00:00
});
}
2018-02-27 02:07:00 +00:00
function invalidPassword(callback) {
superagent.get('https://' + app.fqdn).auth(username, password + 'x').end(function (error, result) {
expect(result.status).to.eql(401);
callback();
});
}
2017-05-08 09:47:39 +00:00
function loadPage(callback) {
2017-07-20 17:11:35 +00:00
browser.manage().deleteAllCookies().then(function () {
2020-11-03 14:38:03 +00:00
return browser.sleep(5000);
2020-05-05 10:42:59 +00:00
}).then(function() {
2017-08-08 16:22:39 +00:00
return browser.get('https://' + username + ':' + encodeURIComponent(password) + '@' + app.fqdn).then(function () {
return browser.get('https://' + app.fqdn);
});
2021-04-06 09:24:39 +00:00
}).then(function () {
return browser.sleep(5000);
}).then(function () {
return browser.get('https://' + app.fqdn);
2017-07-20 17:11:35 +00:00
}).then(function () {
2020-11-03 14:38:03 +00:00
return waitForElement(By.xpath('//span[text()="Actions"]'));
2017-07-20 17:11:35 +00:00
}).then(function () {
2017-05-08 09:47:39 +00:00
callback();
2017-05-05 11:19:38 +00:00
});
}
2017-05-08 09:47:39 +00:00
function addFolder(callback) {
2018-02-27 00:56:42 +00:00
browser.get('https://' + app.fqdn).then(function () {
2020-11-03 12:33:53 +00:00
return browser.findElement(By.css('[ng-click*=addFolder]')).click();
2017-07-20 17:11:35 +00:00
}).then(function () {
2020-11-03 14:38:03 +00:00
return waitForElement(By.id('folderPath'));
2018-05-02 20:33:07 +00:00
}).then(function () {
return browser.sleep(4000); // wait more, not sure why this is needed
2017-07-20 17:11:35 +00:00
}).then(function() {
2020-11-03 12:33:53 +00:00
return browser.findElement(By.id('folderLabel')).sendKeys(FOLDER);
2018-05-02 20:33:07 +00:00
}).then(function () {
return browser.sleep(4000); // without this sometimes only part of the folder name gets through
2017-07-20 17:11:35 +00:00
}).then(function() {
2020-11-03 12:33:53 +00:00
return browser.findElement(By.css('[ng-click*=saveFolder]')).click();
2017-07-20 17:11:35 +00:00
}).then(function() {
2020-11-03 12:33:53 +00:00
return browser.wait(until.elementLocated(By.css('#folders .panel-status span[ng-switch-when=unshared]')), TEST_TIMEOUT);
2018-05-02 20:33:07 +00:00
}).then(function () {
return browser.sleep(4000);
2017-07-20 17:11:35 +00:00
}).then(function() {
callback();
2017-05-05 11:19:38 +00:00
});
}
2018-02-27 00:56:42 +00:00
function checkFolder(callback) {
browser.get('https://' + app.fqdn).then(function () {
2021-04-06 09:24:39 +00:00
return browser.sleep(5000);
}).then(function () {
return browser.get('https://' + app.fqdn);
}).then(function () {
2020-11-03 12:33:53 +00:00
return browser.wait(until.elementLocated(By.xpath(`//span[text()="${FOLDER}"]`)), TEST_TIMEOUT);
2020-05-05 10:42:59 +00:00
}).then(function () {
2018-02-27 00:56:42 +00:00
callback();
});
}
2017-05-08 09:47:39 +00:00
function removeFolder(callback) {
2018-02-27 00:56:42 +00:00
browser.get('https://' + app.fqdn).then(function () {
2020-11-03 14:38:03 +00:00
return waitForElement(By.xpath('//span[text()="Actions"]'));
2017-07-20 17:11:35 +00:00
}).then(function() {
2020-11-03 12:33:53 +00:00
return browser.findElement(By.css('#folders button')).click();
2017-07-20 17:11:35 +00:00
}).then(function () {
2018-02-27 00:56:42 +00:00
return browser.sleep(3000); //No way to check for visibility of angular-js components
2017-07-20 17:11:35 +00:00
}).then(function () {
2020-11-03 12:33:53 +00:00
return browser.findElement(By.css('#folder-0 button[ng-click*=editFolder]')).click();
2017-07-20 17:11:35 +00:00
}).then(function () {
2018-02-27 00:56:42 +00:00
return browser.sleep(3000); //No way to check for visibility of angular-js components
}).then(function () {
2020-11-03 12:33:53 +00:00
return browser.findElement(By.xpath('//button[@data-target="#remove-folder-confirmation"]')).click();
2018-02-27 00:56:42 +00:00
}).then(function () {
return browser.sleep(3000); //No way to check for visibility of angular-js components
2017-07-20 17:11:35 +00:00
}).then(function () {
2020-11-03 12:33:53 +00:00
return browser.findElement(By.css('[ng-click*=deleteFolder]')).click();
2017-07-20 17:11:35 +00:00
}).then(function () {
2018-02-27 00:56:42 +00:00
return browser.sleep(3000); //This needs to run for some time
2017-07-20 17:11:35 +00:00
}).then(function () {
callback();
2017-05-05 11:19:38 +00:00
});
}
2020-11-03 14:38:03 +00:00
function wait (done) {
setTimeout(done, 10000);
}
2020-05-05 10:42:59 +00:00
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
2017-05-05 11:19:38 +00:00
2020-05-05 10:42:59 +00:00
it('install app', function () { execSync('cloudron install --port-bindings SYNC_PORT=' + SYNC_PORT + ' --location ' + LOCATION, EXEC_ARGS); });
it('can get app information', getAppInfo);
2017-05-05 11:19:38 +00:00
2020-11-03 14:38:03 +00:00
it('wait', wait);
2018-02-27 02:07:00 +00:00
it('fails with invalid password', invalidPassword);
2017-05-08 09:47:39 +00:00
it('can load page', loadPage);
it('can add folder', addFolder);
2017-05-05 11:19:38 +00:00
2020-05-05 10:42:59 +00:00
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
2021-04-06 09:24:39 +00:00
it('restore app', async function () {
await browser.get('about:blank');
execSync('cloudron restore --app ' + app.id, EXEC_ARGS);
});
2017-05-05 11:19:38 +00:00
2020-11-03 14:38:03 +00:00
it('wait', wait);
2017-05-08 09:47:39 +00:00
it('can load page', loadPage);
2018-02-27 00:56:42 +00:00
it('can check folder', checkFolder);
2017-05-05 11:19:38 +00:00
2021-04-06 09:24:39 +00:00
it('move to different location', async function () {
await browser.get('about:blank');
execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS);
2017-05-05 11:19:38 +00:00
});
2020-05-05 10:42:59 +00:00
it('can get app information', getAppInfo);
2017-05-05 11:19:38 +00:00
2020-11-03 14:38:03 +00:00
it('wait', wait);
2017-05-23 19:45:05 +00:00
it('can load page', loadPage);
2018-02-27 00:56:42 +00:00
it('can check folder', checkFolder);
2018-02-27 01:16:52 +00:00
it('can remove folder', removeFolder);
2017-05-05 11:19:38 +00:00
2021-04-06 09:24:39 +00:00
it('uninstall app', async function () {
await browser.get('about:blank');
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
2017-05-05 11:19:38 +00:00
});
2018-02-27 00:56:42 +00:00
// test update
2020-05-05 10:42:59 +00:00
it('can install app', function () { execSync('cloudron install --port-bindings SYNC_PORT=' + SYNC_PORT + ' --appstore-id net.syncthing.cloudronapp2 --location ' + LOCATION, EXEC_ARGS); });
it('can get app information', getAppInfo);
2020-11-03 14:38:03 +00:00
it('wait', wait);
2018-02-27 00:56:42 +00:00
it('can load page', loadPage);
it('can add folder', addFolder);
2021-04-06 09:24:39 +00:00
it('can update', async function () {
await browser.get('about:blank');
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
});
2020-11-03 14:38:03 +00:00
it('wait', wait);
2018-02-27 00:56:42 +00:00
it('can check folder', checkFolder);
2020-05-05 10:42:59 +00:00
2021-04-06 09:24:39 +00:00
it('uninstall app', async function () {
await browser.get('about:blank');
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
2018-02-27 00:56:42 +00:00
});
2017-05-05 11:19:38 +00:00
});