From 333e63156eb93ad739fa35ac78cf83296ae40f98 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 22 Sep 2014 10:27:03 +0100 Subject: Fixed unit test; it all actually works. Added a README for running the tests with karma/jasmine. --- webclient/test/README | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 webclient/test/README (limited to 'webclient/test/README') diff --git a/webclient/test/README b/webclient/test/README new file mode 100644 index 0000000000..b1e0d7adea --- /dev/null +++ b/webclient/test/README @@ -0,0 +1,9 @@ +Requires: + - npm + - npm install karma + - npm install jasmine + +Setting up continuous integration / run the tests: + karma start + + -- cgit 1.4.1 From e3152188ef27c1952185764ce0d1c072cb149d99 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 22 Sep 2014 14:29:12 +0100 Subject: Added boilerplate for running end-to-end tests.\nThis is done using Protractor, which looks for a .gitignored file environment-protractor.js which contains the selenium endpoint url. --- .gitignore | 1 + webclient/test/README | 17 +++++++++++++++-- webclient/test/e2e/user.spec.js | 6 ++++++ webclient/test/protractor.conf.js | 6 ++++++ webclient/test/unit/user-controller.spec.js | 6 ++---- 5 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 webclient/test/e2e/user.spec.js create mode 100644 webclient/test/protractor.conf.js (limited to 'webclient/test/README') diff --git a/.gitignore b/.gitignore index dfe8dfedbf..b91b52b615 100644 --- a/.gitignore +++ b/.gitignore @@ -25,5 +25,6 @@ graph/*.png graph/*.dot webclient/config.js +webclient/test/environment-protractor.js uploads diff --git a/webclient/test/README b/webclient/test/README index b1e0d7adea..1813883196 100644 --- a/webclient/test/README +++ b/webclient/test/README @@ -1,9 +1,22 @@ Requires: - - npm + - nodejs/npm - npm install karma - npm install jasmine + - npm install protractor (e2e testing) -Setting up continuous integration / run the tests: +Setting up continuous integration / run the unit tests (make sure you're in +this directory so it can find the config file): karma start +Setting up e2e tests (only if you don't have a selenium server to run the tests +on. If you do, edit the config to point to that url): + webdriver-manager update + webdriver-manager start + +Running e2e tests: + protractor protractor.conf.js + + + + diff --git a/webclient/test/e2e/user.spec.js b/webclient/test/e2e/user.spec.js new file mode 100644 index 0000000000..bbac53899b --- /dev/null +++ b/webclient/test/e2e/user.spec.js @@ -0,0 +1,6 @@ +describe("user page", function() { + it("should have a title", function() { + browser.get("http://matrix.org/alpha/#/login"); + expect(browser.getTitle()).toEqual("[matrix]"); + }); +}); diff --git a/webclient/test/protractor.conf.js b/webclient/test/protractor.conf.js new file mode 100644 index 0000000000..66f4df5407 --- /dev/null +++ b/webclient/test/protractor.conf.js @@ -0,0 +1,6 @@ +var env = require("./environment-protractor.js"); + +exports.config = { + seleniumAddress: env.seleniumAddress, + specs: ['e2e/*.spec.js'] +} diff --git a/webclient/test/unit/user-controller.spec.js b/webclient/test/unit/user-controller.spec.js index 217559114b..798cc4de48 100644 --- a/webclient/test/unit/user-controller.spec.js +++ b/webclient/test/unit/user-controller.spec.js @@ -21,13 +21,12 @@ describe("UserCtrl", function() { getDisplayName: function(uid) { var d = $q.defer(); - // FIXME: everything goes into fire here d.resolve({ data: { displayname: displayName } }); - return d; + return d.promise; }, getProfilePictureUrl: function(uid) { @@ -37,7 +36,7 @@ describe("UserCtrl", function() { avatar_url: avatarUrl } }); - return d; + return d.promise; } }; scope = $rootScope.$new(); @@ -49,7 +48,6 @@ describe("UserCtrl", function() { '$routeParams': routeParams, 'matrixService': matrixService }); - console.log("end inject"); }); }); -- cgit 1.4.1 From 7dfcba164998bf01c5673b244654c082abbe37ba Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 22 Sep 2014 14:36:06 +0100 Subject: Updated test README to include a section on environment-protractor.js The environment file is .gitignored so random selenium servers aren't accidentally pushed. --- webclient/test/README | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'webclient/test/README') diff --git a/webclient/test/README b/webclient/test/README index 1813883196..088181afc0 100644 --- a/webclient/test/README +++ b/webclient/test/README @@ -8,11 +8,17 @@ Setting up continuous integration / run the unit tests (make sure you're in this directory so it can find the config file): karma start + Setting up e2e tests (only if you don't have a selenium server to run the tests on. If you do, edit the config to point to that url): + webdriver-manager update webdriver-manager start + Create a file "environment-protractor.js" in this directory and type: + var seleniumAddress = 'http://localhost:4444/wd/hub'; + + Running e2e tests: protractor protractor.conf.js -- cgit 1.4.1 From 90f5eb12701bb7e623c176aa123aad41652f3417 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 22 Sep 2014 15:00:23 +0100 Subject: Set required environment variables for e2e testing. Added an 'id' to the login button so it can be automatically triggered. Also, added an onPrepare section to protractor.conf to do the login. --- webclient/login/login.html | 2 +- webclient/test/README | 8 ++++++-- webclient/test/protractor.conf.js | 11 ++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) (limited to 'webclient/test/README') diff --git a/webclient/login/login.html b/webclient/login/login.html index 6297ec4d42..6b321f8fc5 100644 --- a/webclient/login/login.html +++ b/webclient/login/login.html @@ -23,7 +23,7 @@


- +

diff --git a/webclient/test/README b/webclient/test/README index 088181afc0..c13010e614 100644 --- a/webclient/test/README +++ b/webclient/test/README @@ -16,8 +16,12 @@ on. If you do, edit the config to point to that url): webdriver-manager start Create a file "environment-protractor.js" in this directory and type: - var seleniumAddress = 'http://localhost:4444/wd/hub'; - + module.exports = { + seleniumAddress: 'http://localhost:4444/wd/hub', + loginUrl: "http://localhost:8008/_matrix/client/#/login", + username: "YOUR_TEST_USERNAME", + password: "YOUR_TEST_PASSWORD" + } Running e2e tests: protractor protractor.conf.js diff --git a/webclient/test/protractor.conf.js b/webclient/test/protractor.conf.js index 66f4df5407..720096b390 100644 --- a/webclient/test/protractor.conf.js +++ b/webclient/test/protractor.conf.js @@ -1,6 +1,11 @@ var env = require("./environment-protractor.js"); - exports.config = { - seleniumAddress: env.seleniumAddress, - specs: ['e2e/*.spec.js'] + seleniumAddress: env.seleniumAddress, + specs: ['e2e/*.spec.js'], + onPrepare: function() { + browser.driver.get(env.loginUrl); + browser.driver.findElement(by.id("user_id")).sendKeys(env.username); + browser.driver.findElement(by.id("password")).sendKeys(env.password); + browser.driver.findElement(by.id("login")).click(); + } } -- cgit 1.4.1 From 95acf63ea38eae6762fb8c7d3ac672661f711dfd Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 22 Sep 2014 16:50:12 +0100 Subject: Add working protractor e2e test. This uses the ignoreSynchronization flag because of the longpoll on the event stream. It would be better to use $interval, but couldn't get that to *reliably* work when testing. I suspect that $interval won't help us here, since there is genuinely an open $http connection, as we're doing a long poll. https://github.com/angular/protractor/issues/49 for more info. --- webclient/test/README | 3 ++- webclient/test/e2e/home.spec.js | 16 ++++++++++++++++ webclient/test/e2e/user.spec.js | 6 ------ webclient/test/protractor.conf.js | 9 ++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 webclient/test/e2e/home.spec.js delete mode 100644 webclient/test/e2e/user.spec.js (limited to 'webclient/test/README') diff --git a/webclient/test/README b/webclient/test/README index c13010e614..1a7bc832c7 100644 --- a/webclient/test/README +++ b/webclient/test/README @@ -18,7 +18,7 @@ on. If you do, edit the config to point to that url): Create a file "environment-protractor.js" in this directory and type: module.exports = { seleniumAddress: 'http://localhost:4444/wd/hub', - loginUrl: "http://localhost:8008/_matrix/client/#/login", + baseUrl: "http://localhost:8008", username: "YOUR_TEST_USERNAME", password: "YOUR_TEST_PASSWORD" } @@ -26,6 +26,7 @@ on. If you do, edit the config to point to that url): Running e2e tests: protractor protractor.conf.js +NOTE: This will create a public room on the target home server. diff --git a/webclient/test/e2e/home.spec.js b/webclient/test/e2e/home.spec.js new file mode 100644 index 0000000000..470237d557 --- /dev/null +++ b/webclient/test/e2e/home.spec.js @@ -0,0 +1,16 @@ +var env = require("../environment-protractor.js"); + +describe("home page", function() { + + beforeEach(function() { + ptor = protractor.getInstance(); + // FIXME we use longpoll on the event stream, and I can't get $interval + // playing nicely with it. Patches welcome to fix this. + ptor.ignoreSynchronization = true; + }); + + it("should have a title", function() { + browser.get(env.baseUrl); + expect(browser.getTitle()).toEqual("[matrix]"); + }); +}); diff --git a/webclient/test/e2e/user.spec.js b/webclient/test/e2e/user.spec.js deleted file mode 100644 index bbac53899b..0000000000 --- a/webclient/test/e2e/user.spec.js +++ /dev/null @@ -1,6 +0,0 @@ -describe("user page", function() { - it("should have a title", function() { - browser.get("http://matrix.org/alpha/#/login"); - expect(browser.getTitle()).toEqual("[matrix]"); - }); -}); diff --git a/webclient/test/protractor.conf.js b/webclient/test/protractor.conf.js index 720096b390..76ae7b712b 100644 --- a/webclient/test/protractor.conf.js +++ b/webclient/test/protractor.conf.js @@ -3,9 +3,16 @@ exports.config = { seleniumAddress: env.seleniumAddress, specs: ['e2e/*.spec.js'], onPrepare: function() { - browser.driver.get(env.loginUrl); + browser.driver.get(env.baseUrl); browser.driver.findElement(by.id("user_id")).sendKeys(env.username); browser.driver.findElement(by.id("password")).sendKeys(env.password); browser.driver.findElement(by.id("login")).click(); + + // wait till the login is done, detect via url change + browser.driver.wait(function() { + return browser.driver.getCurrentUrl().then(function(url) { + return !(/login/.test(url)) + }); + }); } } -- cgit 1.4.1