Ver Fonte

Make initial tests work

Johannes Zellner há 8 anos atrás
pai
commit
20a76776a1
2 ficheiros alterados com 32 adições e 121 exclusões
  1. 26 121
      test/test.js
  2. 6 0
      test/test.php

+ 26 - 121
test/test.js

@@ -5,6 +5,7 @@
 var execSync = require('child_process').execSync,
     expect = require('expect.js'),
     path = require('path'),
+    util = require('util'),
     webdriver = require('selenium-webdriver');
 
 var by = webdriver.By,
@@ -39,8 +40,6 @@ describe('Application life cycle test', function () {
     });
 
     var LOCATION = 'test';
-    var EVENT_TITLE = 'Meet the Cloudron Founders';
-    var CONTACT_CN = 'Max Mustermann';
     var TEST_TIMEOUT = 50000;
     var app;
 
@@ -52,6 +51,22 @@ describe('Application life cycle test', function () {
         });
     }
 
+    function welcomePage(callback) {
+        browser.get('https://' + app.fqdn);
+
+        waitForElement(by.xpath('//*[text()="Cloudron LAMP App"]'), function () {
+            waitForElement(by.xpath('//*[text()="PHP Version 7.0.15-0ubuntu0.16.04.2"]'), callback);
+        });
+    }
+
+    function uploadedFileExists(callback) {
+        browser.get('https://' + app.fqdn + '/test.php');
+
+        waitForElement(by.xpath('//*[text()="this works"]'), function () {
+            waitForElement(by.xpath('//*[text()="' + app.fqdn + '"]'), callback);
+        });
+    }
+
     xit('build app', function () {
         execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
     });
@@ -68,77 +83,13 @@ describe('Application life cycle test', function () {
         expect(app).to.be.an('object');
     });
 
-    it('can login', function (done) {
-        browser.manage().deleteAllCookies();
-        browser.get('https://' + app.fqdn);
-
-        waitForElement(by.id('input_1'),function () {
-            browser.findElement(by.id('input_1')).sendKeys(process.env.USERNAME);
-            browser.findElement(by.id('input_2')).sendKeys(process.env.PASSWORD);
-            browser.findElement(by.name('loginForm')).submit();
-            browser.wait(until.elementLocated(by.xpath('//*[@aria-label="New Event"]')), TEST_TIMEOUT).then(function () { done(); });
-        });
-    });
-
-    it('can create event', function (done) {
-        browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Calendar/view');
-
-        waitForElement(by.xpath('//*[@aria-label="New Event"]'), function () {
-            browser.findElement(by.xpath('//*[@aria-label="New Event"]')).click();
-
-            // open animation
-            browser.sleep(2000).then(function () {
-
-                waitForElement(by.xpath('//*[@aria-label="Create a new event"]'), function () {
-                    browser.findElement(by.xpath('//*[@aria-label="Create a new event"]')).click();
-
-                    waitForElement(by.xpath('//*[@ng-model="editor.component.summary"]'), function () {
-                        browser.findElement(by.xpath('//*[@ng-model="editor.component.summary"]')).sendKeys(EVENT_TITLE);
-                        browser.findElement(by.xpath('//*[@ng-model="editor.component.summary"]')).submit();
-
-                        waitForElement(by.xpath('//*[@aria-label="' + EVENT_TITLE + '"]'), done);
-                    });
-                });
-            });
-        });
-    });
-
-    it('event is present', function (done) {
-        browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Calendar/view');
-
-        waitForElement(by.xpath('//*[@aria-label="' + EVENT_TITLE + '"]'), done);
-    });
-
-    it('can create contact', function (done) {
-        browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Contacts/view#/addressbooks/personal/card/new');
-
-        waitForElement(by.xpath('//*[@aria-label="New Contact"]'), function () {
-            browser.findElement(by.xpath('//*[@aria-label="New Contact"]')).click();
-
-            // open animation
-            browser.sleep(2000).then(function () {
-
-                waitForElement(by.xpath('//*[@aria-label="Create a new address book card"]'), function () {
-                    browser.findElement(by.xpath('//*[@aria-label="Create a new address book card"]')).click();
-
-                    waitForElement(by.xpath('//*[@ng-model="editor.card.c_cn"]'), function () {
-                        browser.findElement(by.xpath('//*[@ng-model="editor.card.c_cn"]')).sendKeys(CONTACT_CN);
-                        browser.findElement(by.xpath('//*[@aria-label="Save"]')).click();
-
-                        waitForElement(by.xpath('//*[text()="' + CONTACT_CN + '"]'), done);
-                    });
-                });
-            });
-        });
-    });
-
-    it('contact is present', function (done) {
-        browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Contacts/view');
-
-        waitForElement(by.xpath('//*[text()="' + CONTACT_CN + '"]'), function () {
-            done();
-        });
+    it('can view welcome page', welcomePage);
+    it('can upload file with sftp', function () {
+        // remove from known hosts in case this test was run on other apps with the same domain already
+        execSync(util.format('sed -i \'/%s/d\' -i ~/.ssh/known_hosts', app.fqdn));
+        execSync(util.format('lftp sftp://%s:%s@%s:%s  -e "set sftp:auto-confirm yes; cd public/; put test.php; bye"', process.env.USERNAME, process.env.PASSWORD, app.fqdn, app.portBindings.SFTP_PORT));
     });
+    it('can get uploaded file', uploadedFileExists);
 
     it('backup app', function () {
         execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
@@ -148,63 +99,17 @@ describe('Application life cycle test', function () {
         execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
     });
 
-    it('can login', function (done) {
-        browser.manage().deleteAllCookies();
-        browser.get('https://' + app.fqdn);
-
-        waitForElement(by.id('input_1'), function () {
-            browser.findElement(by.id('input_1')).sendKeys(process.env.USERNAME);
-            browser.findElement(by.id('input_2')).sendKeys(process.env.PASSWORD);
-            browser.findElement(by.name('loginForm')).submit();
-
-            waitForElement(by.xpath('//*[@aria-label="New Event"]'), done);
-        });
-    });
-
-    it('event is still present', function (done) {
-        browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Calendar/view');
-
-        waitForElement(by.xpath('//*[@aria-label="' + EVENT_TITLE + '"]'), done);
-    });
-
-    it('contact is still present', function (done) {
-        browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Contacts/view');
-
-        waitForElement(by.xpath('//*[text()="' + CONTACT_CN + '"]'), done);
-    });
+    it('can get uploaded file', uploadedFileExists);
 
     it('move to different location', function () {
         browser.manage().deleteAllCookies();
-        execSync('cloudron configure --wait --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
+        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', function (done) {
-        browser.manage().deleteAllCookies();
-        browser.get('https://' + app.fqdn);
-
-        waitForElement(by.id('input_1'), function () {
-            browser.findElement(by.id('input_1')).sendKeys(process.env.USERNAME);
-            browser.findElement(by.id('input_2')).sendKeys(process.env.PASSWORD);
-            browser.findElement(by.name('loginForm')).submit();
-
-            waitForElement(by.xpath('//*[@aria-label="New Event"]'), done);
-        });
-    });
-
-    it('event is still present', function (done) {
-        browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Calendar/view');
-
-        waitForElement(by.xpath('//*[@aria-label="' + EVENT_TITLE + '"]'), done);
-    });
-
-    it('contact is still present', function (done) {
-        browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Contacts/view');
-
-        waitForElement(by.xpath('//*[text()="' + CONTACT_CN + '"]'), done);
-    });
+    it('can get uploaded file', uploadedFileExists);
 
     it('uninstall app', function () {
         execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });

+ 6 - 0
test/test.php

@@ -0,0 +1,6 @@
+<?php
+
+echo "<p>this works</p>";
+echo "<p>" . getenv("APP_DOMAIN") . "</p>";
+
+?>