Merge branch 'fix_tests' into 'master'

Fix tests

See merge request !2
This commit is contained in:
dswd 2017-06-02 22:15:50 +00:00
commit 47a9de45c9

View file

@ -33,7 +33,7 @@ describe('Application life cycle test', function () {
var app, reponame = 'testrepo';
var username = process.env.USERNAME;
var password = process.env.PASSWORD;
var TIMEOUT = process.env.TIMEOUT || 5000;
var TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 5000;
var email, token;
before(function (done) {
@ -64,11 +64,11 @@ describe('Application life cycle test', function () {
}
function setAvatar(done) {
browser.get('https://' + app.fqdn + '/user/settings/avatar');
browser.findElement(by.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png')).then(function () {
browser.findElement(by.xpath('//button[contains(text(), "Update Avatar Setting")]')).click();
browser.get('https://' + app.fqdn + '/user/settings/avatar').then(function () {
return browser.findElement(by.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png'));
}).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Update Avatar Setting")]')).click();
}).then(function () {
browser.wait(until.elementLocated(by.xpath('//p[contains(text(),"updated successfully")]')), TIMEOUT).then(function () { done(); });
});
}
@ -82,18 +82,92 @@ describe('Application life cycle test', function () {
}
function editFile(done) {
browser.get('https://' + app.fqdn + '/' + username + '/' + reponame + '/_edit/master/newfile');
browser.get('https://' + app.fqdn + '/' + username + '/' + reponame + '/_edit/master/newfile').then(function () {
var cm = browser.findElement(by.xpath('//div[contains(@class,"CodeMirror")]'));
var text = 'yo';
browser.executeScript('arguments[0].CodeMirror.setValue("' + text + '");', cm).then(function () {
browser.findElement(by.xpath('//input[@name="commit_summary"]')).sendKeys('Dummy edit');
browser.findElement(by.xpath('//button[contains(text(), "Commit Changes")]')).click();
return browser.executeScript('arguments[0].CodeMirror.setValue("' + text + '");', cm);
}).then(function () {
return browser.findElement(by.xpath('//input[@name="commit_summary"]')).sendKeys('Dummy edit');
}).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Commit Changes")]')).click();
}).then(function () {
waitForUrl('https://' + app.fqdn + '/' + username + '/' + reponame + '/src/master/newfile', done);
});
}
function login(done) {
browser.get('https://' + app.fqdn + '/user/login').then(function () {
return browser.findElement(by.id('user_name')).sendKeys(username);
}).then(function () {
return browser.findElement(by.id('password')).sendKeys(password);
}).then(function () {
return browser.findElement(by.tagName('form')).submit();
}).then(function () {
return browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT);
}).then(function () {
done();
});
}
function addPublicKey(done) {
var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
browser.get('https://' + app.fqdn + '/user/settings/ssh').then(function () {
return browser.findElement(by.xpath('//div[text()="Add Key"]')).click();
}).then(function () {
return browser.findElement(by.id('ssh-key-title')).sendKeys('testkey');
}).then(function () {
return browser.findElement(by.id('ssh-key-content')).sendKeys(publicKey.trim()); // #3480
}).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
}).then(function () {
return browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), TIMEOUT);
}).then(function () {
done();
});
}
function createRepo(done) {
browser.get('https://' + app.fqdn).then(function () {
return browser.findElement(by.linkText('New Repository')).click();
}).then(function () {
return browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), TIMEOUT);
}).then(function () {
return browser.findElement(by.id('repo_name')).sendKeys(reponame);
}).then(function () {
return browser.findElement(by.id('auto-init')).click();
}).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
}).then(function () {
browser.wait(function () {
return browser.getCurrentUrl().then(function (url) {
return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
});
}, TIMEOUT);
}).then(function () {
done();
});
}
function checkCloneUrl(done) {
browser.get('https://' + app.fqdn + '/' + username + '/' + reponame).then(function () {
return browser.findElement(by.id('repo-clone-ssh')).click();
}).then(function () {
return browser.findElement(by.id('repo-clone-url')).getAttribute('value');
}).then(function (cloneUrl) {
expect(cloneUrl).to.be('ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
done();
});
}
function checkGitClone(done) {
rimraf.sync(repodir);
var env = Object.create(process.env);
env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
done();
}
xit('build app', function () {
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
@ -121,7 +195,6 @@ describe('Application life cycle test', function () {
});
});
it('install app', function () {
execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
@ -143,57 +216,17 @@ describe('Application life cycle test', function () {
});
});
it('can login', function (done) {
browser.get('https://' + app.fqdn + '/user/login');
browser.findElement(by.id('user_name')).sendKeys(username);
browser.findElement(by.id('password')).sendKeys(password);
browser.findElement(by.tagName('form')).submit();
browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT).then(function () { done(); });
});
it('can login', login);
it('can set avatar', setAvatar);
it('can get avatar', checkAvatar);
it('can add public key', function (done) {
browser.get('https://' + app.fqdn + '/user/settings/ssh');
var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
it('can add public key', addPublicKey);
browser.findElement(by.xpath('//div[text()="Add Key"]')).click();
browser.findElement(by.id('ssh-key-title')).sendKeys('testkey');
browser.findElement(by.id('ssh-key-content')).sendKeys(publicKey.trim()); // #3480
browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), TIMEOUT).then(function () { done(); });
});
it('can create repo', createRepo);
it('can create repo', function (done) {
browser.get('https://' + app.fqdn);
browser.findElement(by.linkText('New Repository')).click();
browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), TIMEOUT);
browser.findElement(by.id('repo_name')).sendKeys(reponame);
browser.findElement(by.id('auto-init')).click();
browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
browser.wait(function () {
return browser.getCurrentUrl().then(function (url) {
return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
});
}, TIMEOUT).then(function () { done(); });
});
it('displays correct clone url', checkCloneUrl);
it('displays correct clone url', function (done) {
browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
browser.findElement(by.id('repo-clone-ssh')).click();
browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
expect(cloneUrl).to.be('ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
done();
});
});
it('can clone the url', function (done) {
var env = Object.create(process.env);
env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
done();
});
it('can clone the url', checkGitClone);
it('can add and push a file', function (done) {
var env = Object.create(process.env);
@ -207,18 +240,13 @@ describe('Application life cycle test', function () {
it('can edit file', editFile);
it('can restart app', function (done) {
execSync('cloudron restart');
execSync('cloudron restart --wait');
done();
});
it('can clone the url', function (done) {
var env = Object.create(process.env);
env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
expect(fs.existsSync(repodir + '/newfile')).to.be(true);
rimraf.sync(repodir);
done();
});
it('can clone the url', checkCloneUrl);
it('can clone the url', checkGitClone);
it('file exists in repo', function () { expect(fs.existsSync(repodir + '/newfile')).to.be(true); });
it('backup app', function () {
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
@ -229,15 +257,8 @@ describe('Application life cycle test', function () {
});
it('can get avatar', checkAvatar);
it('can clone the url', function (done) {
var env = Object.create(process.env);
env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
expect(fs.existsSync(repodir + '/newfile')).to.be(true);
rimraf.sync(repodir);
done();
});
it('can clone the url', checkGitClone);
it('file exists in repo', function () { expect(fs.existsSync(repodir + '/newfile')).to.be(true); });
it('move to different location', function () {
browser.manage().deleteAllCookies();
@ -247,33 +268,11 @@ describe('Application life cycle test', function () {
expect(app).to.be.an('object');
});
it('can login', function (done) {
browser.get('https://' + app.fqdn + '/user/login');
browser.findElement(by.id('user_name')).sendKeys(username);
browser.findElement(by.id('password')).sendKeys(password);
browser.findElement(by.tagName('form')).submit();
browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT).then(function () { done(); });
});
it('can login', login);
it('can get avatar', checkAvatar);
it('displays correct clone url', function (done) {
browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
browser.findElement(by.id('repo-clone-ssh')).click();
browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
expect(cloneUrl).to.be('ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
done();
});
});
it('can clone the url', function (done) {
var env = Object.create(process.env);
env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
execSync('git clone ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
expect(fs.existsSync(repodir + '/newfile')).to.be(true);
rimraf.sync(repodir);
done();
});
it('displays correct clone url', checkCloneUrl);
it('can clone the url', checkGitClone);
it('file exists in repo', function () { expect(fs.existsSync(repodir + '/newfile')).to.be(true); });
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
@ -287,11 +286,8 @@ describe('Application life cycle test', function () {
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
expect(app).to.be.an('object');
browser.get('https://' + app.fqdn + '/user/login');
browser.findElement(by.id('user_name')).sendKeys(email);
browser.findElement(by.id('password')).sendKeys(password);
browser.findElement(by.tagName('form')).submit();
browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT).then(function () {
login(function (error) {
if (error) return done(error);
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
done();
});