test.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var execSync = require('child_process').execSync,
  4. expect = require('expect.js'),
  5. path = require('path'),
  6. superagent = require('superagent'),
  7. webdriver = require('selenium-webdriver');
  8. var by = webdriver.By,
  9. Keys = webdriver.Key,
  10. until = webdriver.until;
  11. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  12. describe('Application life cycle test', function () {
  13. this.timeout(0);
  14. var chrome = require('selenium-webdriver/chrome');
  15. var server, browser = new chrome.Driver(), uploadedImageUrl;
  16. var username = 'admin', password = 'changeme';
  17. before(function (done) {
  18. var seleniumJar= require('selenium-server-standalone-jar');
  19. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  20. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  21. server.start();
  22. done();
  23. });
  24. after(function (done) {
  25. browser.quit();
  26. server.stop();
  27. done();
  28. });
  29. var LOCATION = 'nodebbtest';
  30. var TEST_TIMEOUT = parseInt(process.env.TEST_TIMEOUT, 10) || 10000;
  31. var app;
  32. var email, token;
  33. function login(done) {
  34. browser.manage().deleteAllCookies();
  35. browser.get('https://' + app.fqdn + '/login');
  36. browser.executeScript('localStorage.clear();')
  37. browser.get('https://' + app.fqdn + '/login');
  38. browser.sleep(5000); // takes some time for username to be visible
  39. browser.wait(until.elementLocated(by.id('username')), TEST_TIMEOUT).then(function () {
  40. browser.findElement(by.id('username')).sendKeys(username);
  41. browser.findElement(by.id('password')).sendKeys(password);
  42. browser.findElement(by.id('login')).click();
  43. browser.wait(until.elementLocated(by.xpath('//a[contains(text(), "Announcements")]')), TEST_TIMEOUT).then(function () { done(); });
  44. });
  45. }
  46. function checkMailPlugin(done) {
  47. browser.get('https://' + app.fqdn + '/admin/emailers/local');
  48. browser.sleep(4000);
  49. browser.wait(until.elementLocated(by.id('emailer:local:host')), TEST_TIMEOUT).then(function () {
  50. browser.findElement(by.id('emailer:local:host')).getAttribute('value').then(function (val) {
  51. if (val !== 'mail') return done(new Error('Incorrect mail server value: ' + val));
  52. done();
  53. });
  54. });
  55. }
  56. // function restartForum()
  57. function installCustomPlugin(done) {
  58. execSync('cloudron exec -- /usr/local/bin/gosu cloudron:cloudron npm install nodebb-plugin-beep', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  59. browser.get('https://' + app.fqdn + '/admin/extend/plugins#installed');
  60. browser.wait(until.elementLocated(by.xpath('//ul[contains(@class, "installed")]//strong[text()="nodebb-plugin-beep"]')), TEST_TIMEOUT).then(function () {
  61. browser.sleep(10000).then(function () {
  62. browser.findElement(by.xpath('//li[@id="nodebb-plugin-beep"]//button[@data-action="toggleActive"]')).click(); // activate the plugin
  63. browser.sleep(3000).then(function() { done(); }); // wait for the action to succeed
  64. });
  65. });
  66. }
  67. function listCustomPlugin(done) {
  68. browser.get('https://' + app.fqdn + '/admin/extend/plugins#installed');
  69. browser.wait(until.elementLocated(by.xpath('//ul[contains(@class, "installed")]//strong[text()="nodebb-plugin-beep"]')), TEST_TIMEOUT).then(function () {
  70. done();
  71. });
  72. }
  73. // function uploadImage()
  74. xit('build app', function () {
  75. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  76. });
  77. it('install app', function () {
  78. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  79. });
  80. it('can get app information', function () {
  81. var inspect = JSON.parse(execSync('cloudron inspect'));
  82. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  83. expect(app).to.be.an('object');
  84. });
  85. it('can login', login);
  86. it('check mail plugin', checkMailPlugin);
  87. it('can install custom plugin', installCustomPlugin);
  88. it('can list custom plugin', listCustomPlugin);
  89. it('backup app', function () {
  90. execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  91. });
  92. it('restore app', function () {
  93. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  94. });
  95. it('can login', login);
  96. it('can list custom plugin', listCustomPlugin);
  97. it('can restart app', function (done) {
  98. execSync('cloudron restart');
  99. done();
  100. });
  101. it('can login', login);
  102. it('can list custom plugin', listCustomPlugin);
  103. it('move to different location', function () {
  104. execSync('cloudron install --wait --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  105. var inspect = JSON.parse(execSync('cloudron inspect'));
  106. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  107. expect(app).to.be.an('object');
  108. });
  109. it('can login', login);
  110. it('can list custom plugin', listCustomPlugin);
  111. it('uninstall app', function () {
  112. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  113. });
  114. });