minio-app/test/test.js

215 lines
7.9 KiB
JavaScript

#!/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);
const LOCATION = 'test';
const TEST_TIMEOUT = 10000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
const BUCKET = 'cloudrontestbucket';
var app;
var browser;
before(function () {
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
});
after(function () {
browser.quit();
});
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 pageLoaded() {
return browser.wait(until.elementLocated(By.className('page-load pl-0 pl-1')), TEST_TIMEOUT);
}
function visible(selector) {
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT).then(function () {
return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
});
}
function login(accessKey, secretKey, callback) {
browser.manage().deleteAllCookies();
browser.get('https://' + app.fqdn).then(function () {
return visible(By.id('accessKey'));
}).then(function () {
return browser.findElement(By.id('accessKey')).sendKeys(accessKey);
}).then(function () {
return browser.findElement(By.id('secretKey')).sendKeys(secretKey);
}).then(function () {
// return browser.findElement(By.className('lw-btn')).click();
return browser.findElement(By.tagName('form')).submit();
}).then(function () {
return browser.wait(until.elementLocated(By.id('top-right-menu')), TEST_TIMEOUT);
}).then(function () {
callback();
});
}
function logout(callback) {
browser.get('https://' + app.fqdn);
pageLoaded().then(function () {
return visible(By.id('top-right-menu'));
}).then(function () {
return browser.findElement(By.id('top-right-menu')).click();
}).then(function () {
if (app.manifest.version === '1.137.0') {
return visible(By.xpath('//*[text()="Sign Out "]'));
} else {
return visible(By.xpath('//*[contains(text(), "Logout")]'));
}
}).then(function () {
if (app.manifest.version === '1.137.0') {
return browser.findElement(By.xpath('//*[text()="Sign Out "]')).click();
} else {
return browser.findElement(By.xpath('//*[contains(text(),"Logout")]')).click();
}
}).then(function () {
return browser.wait(until.elementLocated(By.id('accessKey')), TEST_TIMEOUT);
}).then(function () {
callback();
});
}
function addBucket(callback) {
browser.get('https://' + app.fqdn);
pageLoaded().then(function () {
return visible(By.className('fa-plus'));
}).then(function () {
return browser.findElement(By.className('fa-plus')).click();
}).then(function () {
const c = 'fa-hdd';
return visible(By.className(c));
}).then(function () {
const c = 'fa-hdd';
return browser.findElement(By.className(c)).click();
}).then(function () {
return visible(By.xpath('//*[@class="modal-body"]/form/div/input'));
}).then(function () {
return browser.findElement(By.xpath('//*[@class="modal-body"]/form/div/input')).sendKeys(BUCKET);
}).then(function () {
return browser.findElement(By.xpath('//*[@class="modal-body"]/form')).submit();
}).then(function () {
return visible(By.xpath('//*[@class="main"]/a[text()="' + BUCKET + '"]'));
}).then(function () {
callback();
});
}
function checkBucket(callback) {
browser.get('https://' + app.fqdn);
pageLoaded().then(function () {
return browser.findElement(By.xpath(`//a[contains(text(), ${BUCKET})]`));
}).then(function () {
callback();
});
}
function openSettings(callback) {
browser.get('https://' + app.fqdn);
pageLoaded().then(function () {
return visible(By.id('top-right-menu'));
}).then(function () {
return browser.findElement(By.id('top-right-menu')).click();
}).then(function () {
return visible(By.xpath('//*[contains(text(), "Change Password")]'));
}).then(function () {
return browser.findElement(By.xpath('//*[contains(text(),"Change Password")]')).click();
}).then(function () {
return browser.wait(until.elementLocated(By.xpath('//*[contains(text(), "Change Password")]')), TEST_TIMEOUT);
}).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 login', login.bind(null, 'minioadmin', 'minioadmin'));
it('can add bucket', addBucket);
it('can open settings', openSettings);
it('can logout', logout);
it('can change credentials', function () {
execSync(`cloudron exec --app ${app.id} -- /app/code/minio-credentials set minioakey minioskey`, EXEC_ARGS);
});
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
it('can login', login.bind(null, 'minioakey', 'minioskey'));
it('has bucket', checkBucket);
it('can logout', logout);
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
it('restore app', function () {
const backups = JSON.parse(execSync(`cloudron backup list --raw --app ${app.id}`));
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
getAppInfo();
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
});
it('can login', login.bind(null, 'minioakey', 'minioskey'));
it('has bucket', checkBucket);
it('can open settings', openSettings);
it('can logout', logout);
it('move to different location', function () {
browser.manage().deleteAllCookies();
execSync('cloudron configure --location ' + LOCATION + '2', EXEC_ARGS);
});
it('can get app information', getAppInfo);
it('can login', login.bind(null, 'minioakey', 'minioskey'));
it('has bucket', checkBucket);
it('can logout', logout);
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
// test update
it('can install app', function () { execSync('cloudron install --appstore-id io.minio.cloudronapp --location ' + LOCATION, EXEC_ARGS); });
it('can get app information', getAppInfo);
it('can login', login.bind(null, 'minioadmin', 'minioadmin'));
it('can add buckets', addBucket);
it('can logout', logout);
it('can update', function () { execSync('cloudron update --app ' + LOCATION, EXEC_ARGS); });
it('can get app information', getAppInfo);
it('can login', login.bind(null, 'minioadmin', 'minioadmin'));
it('has bucket', checkBucket);
it('can logout', logout);
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
});