freshrss-app/test/test.js

247 lines
8.9 KiB
JavaScript

#!/usr/bin/env node
'use strict';
require('chromedriver');
var execSync = require('child_process').execSync,
expect = require('expect.js'),
path = require('path'),
superagent = require('superagent'),
webdriver = require('selenium-webdriver');
var by = webdriver.By,
until = webdriver.until;
var username = 'admin',
password = 'password';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
describe('Application life cycle test', function () {
this.timeout(0);
var chrome = require('selenium-webdriver/chrome');
var server, browser = new chrome.Driver();
before(function (done) {
var seleniumJar= require('selenium-server-standalone-jar');
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
server = new SeleniumServer(seleniumJar.path, { port: 4444 });
server.start();
done();
});
after(function (done) {
browser.quit();
server.stop();
done();
});
var LOCATION = 'test';
var TEST_TIMEOUT = 10000;
var app;
function exists(selector) {
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT);
}
function visible(selector, callback) {
return exists(selector).then(function () {
return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
});
}
function login(callback) {
browser.manage().deleteAllCookies().then(function () {
return browser.get('https://' + app.fqdn);
}).then(function () {
return visible(by.id('loginButton'));
}).then(function () {
return browser.findElement(by.id('username')).sendKeys(username);
}).then(function () {
return browser.findElement(by.id('passwordPlain')).sendKeys(password);
}).then(function () {
return browser.findElement(by.id('loginButton')).click();
}).then(function () {
return browser.wait(until.elementLocated(by.id('dropdown-configure')), TEST_TIMEOUT);
}).then(function () {
callback();
});
}
function logout(callback) {
var logout_btn = by.xpath('//ul[@class="dropdown-menu"]/li/a[@class="signout"]');
browser.get('https://' + app.fqdn).then(function () {
return visible(by.id('stream'));
}).then(function () {
return browser.findElement(by.className('dropdown-toggle')).click();
}).then(function () {
return visible(logout_btn);
}).then(function () {
return browser.findElement(logout_btn).click();
}).then(function () {
return browser.wait(until.elementLocated(by.id('loginButton')), TEST_TIMEOUT);
}).then(function () {
callback();
});
}
function addSubscription(callback) {
var url = "https://cloudron.io/blog/rss.xml";
browser.get(`https://${app.fqdn}/p/i/?c=subscription`).then(function () {
return visible(by.xpath('//input[@name="url_rss"]'));
}).then(function () {
return browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url);
}).then(function () {
return browser.findElement(by.xpath('//form[@id="add_rss"]/div/button[@type="submit"]')).click();
}).then(function () {
return visible(by.xpath('//div[@id="notification" and @class="notification good"]'));
}).then(function () {
callback();
});
}
function addUser(callback) {
var test_username = 'test';
browser.get(`https://${app.fqdn}/p/i/?c=user&a=manage`).then(function () {
return visible(by.id('new_user_name'));
}).then(function () {
return browser.findElement(by.id('new_user_name')).sendKeys(test_username);
}).then(function () {
return browser.findElement(by.id('new_user_passwordPlain')).sendKeys(password);
}).then(function () {
return browser.findElement(by.xpath('//button[text()="Create"]')).click();
}).then(function () {
return visible(by.xpath('//div[@id="notification" and @class="notification good"]'));
}).then(function () {
callback();
});
}
function enableApi(callback) {
browser.get('https://' + app.fqdn + '/p/i/?c=auth').then(function () {
return browser.findElement(by.id('api_enabled')).click();
}).then(function () {
return browser.findElement(by.xpath('//button[text()="Submit"]')).submit();
}).then(function () {
callback();
});
}
function checkApiConfiguration(callback) {
browser.get('https://' + app.fqdn + '/p/api/greader.php/check%2Fcompatibility').then(function () {
return exists(by.xpath('//pre[text()="PASS"]'));
}).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 subscriptionExists(callback) {
browser.get('https://' + app.fqdn + '/p/i/?get=c_1').then(function () {
return visible(by.xpath('//a[text()="Cloudron.io"]'));
}).then(function () {
callback();
});
}
function getStaticExtensionFile(callback) {
superagent.get(`https://${app.fqdn}/p/ext.php?f=xExtension-StickyFeeds/static/script.js&t=js`)
.buffer(true)
.end(function (err, res) {
expect(err).to.be(null);
expect(res.status).to.be(200);
expect(res.text).to.contain('sticky_feeds'); // relies on the buffer flag above
callback();
});
}
xit('build app', function () {
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('install app', function () {
execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('can get app information', getAppInfo);
it('can login', login);
it('can subscribe', addSubscription);
it('can add users', addUser);
it('can enable API', enableApi);
it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
it('can logout', logout);
it('backup app', function () {
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('restore app', function () {
execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('can login', login);
it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
it('can logout', logout);
it('move to different location', function () {
browser.manage().deleteAllCookies();
execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
expect(app).to.be.an('object');
});
it('can login', login);
it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
it('can logout', logout);
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
// test update
it('can install app', function () {
execSync('cloudron install --new --wait --appstore-id org.freshrss.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('can get app information', getAppInfo);
it('can login', login);
it('can subscribe', addSubscription);
it('can add users', addUser);
it('can update', function () {
execSync('cloudron install --wait --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
expect(app).to.be.an('object');
});
it('can login', login);
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
});