From 503e109daa49aa7e087428f019a627e2d54c98a6 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Thu, 19 Nov 2015 22:02:09 +0100 Subject: [PATCH 01/13] Removed modules which are not necessary for phase 1. --- index.html | 2 -- js/app.js | 20 +------------------ js/controller.js | 46 -------------------------------------------- partials/detail.html | 1 - partials/map.html | 11 ----------- partials/new.html | 41 --------------------------------------- 6 files changed, 1 insertion(+), 120 deletions(-) delete mode 100644 partials/detail.html delete mode 100644 partials/map.html delete mode 100644 partials/new.html diff --git a/index.html b/index.html index 9e0e825..b80a7d7 100644 --- a/index.html +++ b/index.html @@ -31,9 +31,7 @@ diff --git a/js/app.js b/js/app.js index 172d470..8b32daa 100644 --- a/js/app.js +++ b/js/app.js @@ -7,30 +7,12 @@ angular.module('Come2HelpApp', [ .config(['$routeProvider', function ($routeProvider) { $routeProvider. - when('/map', { - templateUrl: 'partials/map.html', - controller: 'MapController', - controllerAs: 'ctrl' - - }). when('/list', { templateUrl: 'partials/list.html', controller: 'ListController', controllerAs: 'ctrl' }). - when('/detail/:locationId', { - templateUrl: 'partials/detail.html', - controller: 'DetailController', - controllerAs: 'ctrl' - - }). - when('/new', { - templateUrl: 'partials/new.html', - controller: 'NewController', - controllerAs: 'ctrl' - - }). otherwise({ - redirectTo: '/map' + redirectTo: '/list' }); }]); \ No newline at end of file diff --git a/js/controller.js b/js/controller.js index 1b42ccc..f40d49b 100644 --- a/js/controller.js +++ b/js/controller.js @@ -4,10 +4,6 @@ angular.module('Come2HelpController').factory('Locations', ['$resource', functio return $resource('api/locations/:id'); }]); -angular.module('Come2HelpController').factory('Tasks', ['$resource', function ($resource) { - return $resource('api/tasks/:id'); -}]); - angular.module('Come2HelpController').service('geocoder', [function () { this.geocode = function (address, outerCallback) { var geocoder = new google.maps.Geocoder(); @@ -26,52 +22,10 @@ angular.module('Come2HelpController').service('geocoder', [function () { }; }]); -angular.module('Come2HelpController').controller('MapController', ['Locations', function (Locations) { - var vm = this; - - vm.map = {center: {latitude: 51.163333, longitude: 10.447778}, zoom: 6}; - - Locations.query(function (data) { - vm.locations = data; - }); - - vm.openDetails = function (id) { - location.href = '#/detail/' + id; - }; -}]); - angular.module('Come2HelpController').controller('ListController', ['Locations', function (Locations) { var vm = this; Locations.query(function (data) { vm.locations = data; }); -}]); - -angular.module('Come2HelpController').controller('DetailController', ['Locations', '$routeParams', function (Locations, $routeParams) { - var vm = this; - - vm.locationId = $routeParams.locationId; -}]); - -angular.module('Come2HelpController').controller('NewController', ['Locations', 'Tasks', 'geocoder', function (Locations, Tasks, geocoder) { - var vm = this; - - Tasks.query(function (data) { - vm.tasks = data; - }); - - vm.addNew = function () { - var result = geocoder.geocode(vm.inputLocation, function (results) { - Locations.save({ - 'name': vm.inputName, - 'location': vm.inputLocation, - 'latitude': results.results[0].geometry.location.G, - 'longitude': results.results[0].geometry.location.K - }); - - vm.inputName = ''; - vm.inputLocation = ''; - }); - }; }]); \ No newline at end of file diff --git a/partials/detail.html b/partials/detail.html deleted file mode 100644 index edd1c7a..0000000 --- a/partials/detail.html +++ /dev/null @@ -1 +0,0 @@ -{{ctrl.locationId}} \ No newline at end of file diff --git a/partials/map.html b/partials/map.html deleted file mode 100644 index 52d10b7..0000000 --- a/partials/map.html +++ /dev/null @@ -1,11 +0,0 @@ -
- - - - -
diff --git a/partials/new.html b/partials/new.html deleted file mode 100644 index 53e18dc..0000000 --- a/partials/new.html +++ /dev/null @@ -1,41 +0,0 @@ -
- - -
- - -
- -
-
-
- - -
- -
-
-
- - -
- -
-
-
- - -
- {{task.name}} -
-
-
-
- -
-
-
\ No newline at end of file From a7f5bd34f86253c92d6b3586f73e52a1979260f9 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Thu, 19 Nov 2015 22:15:23 +0100 Subject: [PATCH 02/13] Added basic interface for volunteer registration. --- api/abilities | 10 +++++++++ api/volunteers | 0 index.html | 5 ++++- js/app.js | 8 +++---- js/controller.js | 27 +++++++++++++++++++----- partials/register.html | 47 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 api/abilities create mode 100644 api/volunteers create mode 100644 partials/register.html diff --git a/api/abilities b/api/abilities new file mode 100644 index 0000000..65befc5 --- /dev/null +++ b/api/abilities @@ -0,0 +1,10 @@ +[ + { + "id": 12, + "name": "Test" + }, + { + "id": 14, + "name": "Bla" + } +] \ No newline at end of file diff --git a/api/volunteers b/api/volunteers new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html index b80a7d7..42a84e5 100644 --- a/index.html +++ b/index.html @@ -31,7 +31,10 @@ diff --git a/js/app.js b/js/app.js index 8b32daa..95ece78 100644 --- a/js/app.js +++ b/js/app.js @@ -7,12 +7,12 @@ angular.module('Come2HelpApp', [ .config(['$routeProvider', function ($routeProvider) { $routeProvider. - when('/list', { - templateUrl: 'partials/list.html', - controller: 'ListController', + when('/register', { + templateUrl: 'partials/register.html', + controller: 'RegisterController', controllerAs: 'ctrl' }). otherwise({ - redirectTo: '/list' + redirectTo: '/register' }); }]); \ No newline at end of file diff --git a/js/controller.js b/js/controller.js index f40d49b..087ddc4 100644 --- a/js/controller.js +++ b/js/controller.js @@ -1,7 +1,11 @@ angular.module('Come2HelpController', ['ngResource']); -angular.module('Come2HelpController').factory('Locations', ['$resource', function ($resource) { - return $resource('api/locations/:id'); +angular.module('Come2HelpController').factory('Abilities', ['$resource', function ($resource) { + return $resource('api/abilities/:id'); +}]); + +angular.module('Come2HelpController').factory('Volunteers', ['$resource', function ($resource) { + return $resource('api/volunteers/:id'); }]); angular.module('Come2HelpController').service('geocoder', [function () { @@ -22,10 +26,23 @@ angular.module('Come2HelpController').service('geocoder', [function () { }; }]); -angular.module('Come2HelpController').controller('ListController', ['Locations', function (Locations) { +angular.module('Come2HelpController').controller('RegisterController', ['Abilities', 'Volunteers', '$routeParams', function (Abilities, Volunteers, $routeParams) { var vm = this; - Locations.query(function (data) { - vm.locations = data; + Abilities.query(function (data) { + vm.abilities = data; }); + + vm.doRegister = function () { + Volunteers.save({ + 'givenName': vm.givenName, + 'surname': vm.surname, + 'address': { + 'zipCode': vm.zipCode + }, + 'phone': vm.phone, + 'isAdult': vm.isAdult == true + + }); + }; }]); \ No newline at end of file diff --git a/partials/register.html b/partials/register.html new file mode 100644 index 0000000..039ac86 --- /dev/null +++ b/partials/register.html @@ -0,0 +1,47 @@ +
+ +
+ +
+ +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {{ability.name}} +
+
+
+
+ +
+
+
\ No newline at end of file From 5e103d3de945309527926860117e5146496d0f6d Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Thu, 19 Nov 2015 23:36:43 +0100 Subject: [PATCH 03/13] Added first tests for user registration. --- api/abilities | 4 ++-- js/controller.js | 2 +- js/i18n.js | 20 ++++++++++++++++++-- partials/register.html | 2 +- test/behaviour/example.js | 29 ----------------------------- test/behaviour/register.js | 31 +++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 test/behaviour/register.js diff --git a/api/abilities b/api/abilities index 65befc5..8abdec0 100644 --- a/api/abilities +++ b/api/abilities @@ -1,10 +1,10 @@ [ { "id": 12, - "name": "Test" + "name": "Ability 1" }, { "id": 14, - "name": "Bla" + "name": "Ability 2" } ] \ No newline at end of file diff --git a/js/controller.js b/js/controller.js index 087ddc4..cbed9af 100644 --- a/js/controller.js +++ b/js/controller.js @@ -41,7 +41,7 @@ angular.module('Come2HelpController').controller('RegisterController', ['Abiliti 'zipCode': vm.zipCode }, 'phone': vm.phone, - 'isAdult': vm.isAdult == true + 'adult': vm.adult == true }); }; diff --git a/js/i18n.js b/js/i18n.js index 1c6b4e3..fd45ad9 100644 --- a/js/i18n.js +++ b/js/i18n.js @@ -8,7 +8,15 @@ angular.module('Come2HelpApp').config(['$translateProvider', function ($translat 'Show': 'Show', 'New Operation Request': 'New Operation Request', 'Project': 'Project', - 'Tasks': 'Tasks' + 'Tasks': 'Tasks', + 'Name': 'Name', + 'Givenname': 'Givenname', + 'Surname': 'Surname', + 'Zip Code': 'Zip Code', + 'E-Mail-Address': 'E-Mail-Address', + 'Phone': 'Phone', + 'Is Adult': 'Is Adult', + 'Abilities': 'Abilities' }); $translateProvider.translations('de', { @@ -20,7 +28,15 @@ angular.module('Come2HelpApp').config(['$translateProvider', function ($translat 'Show': 'Anzeigen', 'New Operation Request': 'Neue Einsatzanfrage', 'Project': 'Projekt', - 'Tasks': 'Aufgaben' + 'Tasks': 'Aufgaben', + 'Name': 'Name', + 'Givenname': 'Vorname', + 'Surname': 'Nachname', + 'Zip Code': 'PLZ', + 'E-Mail-Address': 'E-Mail-Adresse', + 'Phone': 'Telefonnummer', + 'Is Adult': 'Volljährig?', + 'Abilities': 'Fähigkeiten' }); $translateProvider.fallbackLanguage('en') diff --git a/partials/register.html b/partials/register.html index 039ac86..9c000f2 100644 --- a/partials/register.html +++ b/partials/register.html @@ -36,7 +36,7 @@
- {{ability.name}} + {{ability.name}}
diff --git a/test/behaviour/example.js b/test/behaviour/example.js index 3dbcedf..092cc1a 100644 --- a/test/behaviour/example.js +++ b/test/behaviour/example.js @@ -15,33 +15,4 @@ describe('Home', function() { expect(browser.getTitle()).to.eventually.equal('come2.help'); }); -}); - -describe('List', function() { - this.timeout(2 * 60 * 1000); - - var locationlist = by.repeater('location in ctrl.locations'); - - it('should have two entries: "Sandsäcke füllen" and "Transport"', function() { - browser.getPart('list'); - - expect(element.all(locationlist).count()).to.eventually.equal(2); - expect(element(locationlist.column('location.name').row(0)).getInnerHtml()).to.eventually.contain('Sandsäcke füllen'); - expect(element(locationlist.column('location.name').row(1)).getInnerHtml()).to.eventually.contain('Transport'); - }); - - // Example for mocking - it('should load another entry', function() { - server.mockAPI('locations', [{ - id: 1, - name: 'Mocked Location', - latitude: 49.1232, - longitude: 8, - location: 'Schlossplatz' - }]); - - browser.navigate().refresh(); - - expect(element(locationlist.column('location.name').row(0)).getInnerHtml()).to.eventually.contain('Mocked Location'); - }); }); \ No newline at end of file diff --git a/test/behaviour/register.js b/test/behaviour/register.js new file mode 100644 index 0000000..3cc2e28 --- /dev/null +++ b/test/behaviour/register.js @@ -0,0 +1,31 @@ +require('./asserters')(); + +var server = require('./apimocker'); + +describe('Register', function() { + this.timeout(2 * 60 * 1000); + + var abilitylist = by.repeater('ability in ctrl.abilities'); + + it('should have two entries: "Ability 1" and "Ability 2"', function() { + browser.getPart('register'); + + expect(element.all(abilitylist).count()).to.eventually.equal(2); + expect(element(abilitylist.column('ability.name').row(0)).getInnerHtml()).to.eventually.contain('Ability 1'); + expect(element(abilitylist.column('ability.name').row(1)).getInnerHtml()).to.eventually.contain('Ability 2'); + + + }); + + // Example for mocking + it('should load another entry', function() { + server.mockAPI('abilities', [{ + id: 1, + name: 'Mocked Ability' + }]); + + browser.navigate().refresh(); + + expect(element(abilitylist.column('ability.name').row(0)).getInnerHtml()).to.eventually.contain('Mocked Ability'); + }); +}); \ No newline at end of file From 9d1129696faa4c0b7e793c9195ca5ab7e8f93dde Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Fri, 20 Nov 2015 04:36:21 +0100 Subject: [PATCH 04/13] Implemented volunteer registration tests and first error handling. --- js/controller.js | 11 +++ partials/register.html | 6 +- test/behaviour/mocks/volunteers.js | 56 +++++++++++++ .../behaviour/protractor.browserstack.conf.js | 6 +- test/behaviour/protractor.conf.js | 6 +- test/behaviour/register.js | 79 +++++++++++++++++++ 6 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 test/behaviour/mocks/volunteers.js diff --git a/js/controller.js b/js/controller.js index cbed9af..1aa5db8 100644 --- a/js/controller.js +++ b/js/controller.js @@ -29,6 +29,8 @@ angular.module('Come2HelpController').service('geocoder', [function () { angular.module('Come2HelpController').controller('RegisterController', ['Abilities', 'Volunteers', '$routeParams', function (Abilities, Volunteers, $routeParams) { var vm = this; + vm.error = null; + Abilities.query(function (data) { vm.abilities = data; }); @@ -43,6 +45,15 @@ angular.module('Come2HelpController').controller('RegisterController', ['Abiliti 'phone': vm.phone, 'adult': vm.adult == true + }, function() { + vm.error = null; + + + // TODO: Clear form and send to ``thank you''-page + }, function (response) { + vm.error = response.status; + + // TODO: Verbose error handling }); }; }]); \ No newline at end of file diff --git a/partials/register.html b/partials/register.html index 9c000f2..f481e03 100644 --- a/partials/register.html +++ b/partials/register.html @@ -1,5 +1,7 @@
+ +
@@ -28,9 +30,9 @@
- +
- +
diff --git a/test/behaviour/mocks/volunteers.js b/test/behaviour/mocks/volunteers.js new file mode 100644 index 0000000..b37e73b --- /dev/null +++ b/test/behaviour/mocks/volunteers.js @@ -0,0 +1,56 @@ +module.exports = [ + { + request: { + path: '/volunteers', + method: 'POST', + data: { + givenName: 'Max', + surname: 'Mustermann', + address: { + zipCode: '76187' + }, + phone: '0157812312335', + adult: true + } + }, + response: { + status: 200, + data: [{ + id: 42, + givenName: 'Max', + surname: 'Mustermann', + address: { + zipCode: '76187' + }, + phone: '0157812312335', + adult: true + }] + } + }, + { + request: { + path: '/volunteers', + method: 'POST', + data: { + givenName: 'Max', + surname: 'Mustermann', + address: { + zipCode: '76187' + }, + phone: '0157812312335', + adult: false + } + }, + response: { + status: 400, + data: [{ + incidentId: '2a980d8c-4e98-49b4-aac7-a4faa7606a21', + clientErrors: [{ + path: 'adult', + 'code': 'has to be true', + value: false + }] + }] + } + } +]; \ No newline at end of file diff --git a/test/behaviour/protractor.browserstack.conf.js b/test/behaviour/protractor.browserstack.conf.js index 012bbd3..ac82ff8 100644 --- a/test/behaviour/protractor.browserstack.conf.js +++ b/test/behaviour/protractor.browserstack.conf.js @@ -100,7 +100,11 @@ exports.config = { reporter: 'min' }, specs: ['**/*.js'], - exclude: ['**/*.conf.js'] + exclude: ['**/*.conf.js'], + mocks: { + dir: 'mocks', + default: ['default'] + } }; function key() { diff --git a/test/behaviour/protractor.conf.js b/test/behaviour/protractor.conf.js index d1e1e07..8db143e 100644 --- a/test/behaviour/protractor.conf.js +++ b/test/behaviour/protractor.conf.js @@ -9,5 +9,9 @@ exports.config = { slow: 3000 }, specs: ['**/*.js'], - exclude: ['**/*.conf.js'] + exclude: ['**/*.conf.js'], + mocks: { + dir: 'mocks', + default: ['default'] + } }; \ No newline at end of file diff --git a/test/behaviour/register.js b/test/behaviour/register.js index 856343d..f3d6284 100644 --- a/test/behaviour/register.js +++ b/test/behaviour/register.js @@ -1,5 +1,14 @@ require('./asserters')(); +var mock = require('./http-mock'); + +var attributes = { + zipCode: '76187', + givenName: 'Max', + surname: 'Mustermann', + phone: '0157812312335' +}; + describe('Register', function() { this.timeout(2 * 60 * 1000); @@ -11,7 +20,77 @@ describe('Register', function() { expect(element.all(abilitylist).count()).to.eventually.equal(2); expect(element(abilitylist.column('ability.name').row(0)).getInnerHtml()).to.eventually.contain('Ability 1'); expect(element(abilitylist.column('ability.name').row(1)).getInnerHtml()).to.eventually.contain('Ability 2'); + }); + + it('register with correct data', function() { + mock(['volunteers']); + + browser.getPart('register'); + + var zipCode = browser.findElement(by.model('ctrl.zipCode')); + zipCode.sendKeys(attributes['zipCode']); + var givenName = browser.findElement(by.model('ctrl.givenName')); + givenName.sendKeys(attributes['givenName']); + var surname = browser.findElement(by.model('ctrl.surname')); + surname.sendKeys(attributes['surname']); + var phone = browser.findElement(by.model('ctrl.phone')); + phone.sendKeys(attributes['phone']); + var adult = browser.findElement(by.model('ctrl.adult')); + adult.click(); + + element(by.partialButtonText('Register')).click(); + + expect(mock.requestsMade()).to.eventually.deep.equal([ + { + url : 'api/volunteers', + method : 'POST', + data: { + address: { + zipCode: attributes['zipCode'] + }, + adult: true, + givenName: attributes['givenName'], + surname: attributes['surname'], + phone: attributes['phone'] + } + } + ]); + expect(element(by.id('error')).isDisplayed()).to.eventually.equal(false); + + }); + + it('register with adult=false', function() { + mock(['volunteers']); + + browser.getPart('register'); + + var zipCode = browser.findElement(by.model('ctrl.zipCode')); + zipCode.sendKeys(attributes['zipCode']); + var givenName = browser.findElement(by.model('ctrl.givenName')); + givenName.sendKeys(attributes['givenName']); + var surname = browser.findElement(by.model('ctrl.surname')); + surname.sendKeys(attributes['surname']); + var phone = browser.findElement(by.model('ctrl.phone')); + phone.sendKeys(attributes['phone']); + + element(by.partialButtonText('Register')).click(); + expect(mock.requestsMade()).to.eventually.deep.equal([ + { + url : 'api/volunteers', + method : 'POST', + data: { + address: { + zipCode: attributes['zipCode'] + }, + adult: false, + givenName: attributes['givenName'], + surname: attributes['surname'], + phone: attributes['phone'] + } + } + ]); + expect(element(by.id('error')).isDisplayed()).to.eventually.equal(true); }); }); \ No newline at end of file From beb656a89753fa69700fd8eb8af77c475040c9da Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Fri, 20 Nov 2015 04:46:53 +0100 Subject: [PATCH 05/13] Removed not necessary mock. --- test/behaviour/example.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/behaviour/example.js b/test/behaviour/example.js index b795a5e..fb81132 100644 --- a/test/behaviour/example.js +++ b/test/behaviour/example.js @@ -5,8 +5,6 @@ require('./asserters')(); -var mock = require('./http-mock'); - describe('Home', function() { this.timeout(1 * 60 * 1000); From 23b70463fc061bb646dd6e29bc0868fddc1acb7a Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sat, 21 Nov 2015 15:24:25 +0100 Subject: [PATCH 06/13] Implemented error field highlighting and added one test. --- js/controller.js | 11 +++++++---- js/i18n.js | 6 ++++-- partials/register.html | 16 ++++++++-------- test/behaviour/mocks/volunteers.js | 6 +++--- test/behaviour/register.js | 1 + 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/js/controller.js b/js/controller.js index 1aa5db8..36f6473 100644 --- a/js/controller.js +++ b/js/controller.js @@ -29,7 +29,7 @@ angular.module('Come2HelpController').service('geocoder', [function () { angular.module('Come2HelpController').controller('RegisterController', ['Abilities', 'Volunteers', '$routeParams', function (Abilities, Volunteers, $routeParams) { var vm = this; - vm.error = null; + vm.errors = null; Abilities.query(function (data) { vm.abilities = data; @@ -46,14 +46,17 @@ angular.module('Come2HelpController').controller('RegisterController', ['Abiliti 'adult': vm.adult == true }, function() { - vm.error = null; + vm.errors = null; // TODO: Clear form and send to ``thank you''-page }, function (response) { - vm.error = response.status; + vm.errors = {}; - // TODO: Verbose error handling + for (var i = 0; i < response.data.clientErrors.length; i++) { + var errorData = response.data.clientErrors[i]; + vm.errors[errorData.path] = true; + } }); }; }]); \ No newline at end of file diff --git a/js/i18n.js b/js/i18n.js index fd45ad9..f665f00 100644 --- a/js/i18n.js +++ b/js/i18n.js @@ -16,7 +16,8 @@ angular.module('Come2HelpApp').config(['$translateProvider', function ($translat 'E-Mail-Address': 'E-Mail-Address', 'Phone': 'Phone', 'Is Adult': 'Is Adult', - 'Abilities': 'Abilities' + 'Abilities': 'Abilities', + 'Please correct the highlighted fields.': 'Please correct the highlighted fields.' }); $translateProvider.translations('de', { @@ -36,7 +37,8 @@ angular.module('Come2HelpApp').config(['$translateProvider', function ($translat 'E-Mail-Address': 'E-Mail-Adresse', 'Phone': 'Telefonnummer', 'Is Adult': 'Volljährig?', - 'Abilities': 'Fähigkeiten' + 'Abilities': 'Fähigkeiten', + 'Please correct the highlighted fields.': 'Bitte korrigiere die hervorgebenen Felder.' }); $translateProvider.fallbackLanguage('en') diff --git a/partials/register.html b/partials/register.html index f481e03..ca636a1 100644 --- a/partials/register.html +++ b/partials/register.html @@ -1,8 +1,8 @@ - + -
+
@@ -11,31 +11,31 @@
-
- +
+
-
+
-
+
-
+
-
+
{{ability.name}} diff --git a/test/behaviour/mocks/volunteers.js b/test/behaviour/mocks/volunteers.js index b37e73b..d6fee57 100644 --- a/test/behaviour/mocks/volunteers.js +++ b/test/behaviour/mocks/volunteers.js @@ -43,14 +43,14 @@ module.exports = [ }, response: { status: 400, - data: [{ + data: { incidentId: '2a980d8c-4e98-49b4-aac7-a4faa7606a21', clientErrors: [{ path: 'adult', - 'code': 'has to be true', + code: 'has to be true', value: false }] - }] + } } } ]; \ No newline at end of file diff --git a/test/behaviour/register.js b/test/behaviour/register.js index f3d6284..44ea891 100644 --- a/test/behaviour/register.js +++ b/test/behaviour/register.js @@ -91,6 +91,7 @@ describe('Register', function() { } ]); expect(element(by.id('error')).isDisplayed()).to.eventually.equal(true); + expect(element.all(by.className('has-error')).count()).to.eventually.equal(1); }); }); \ No newline at end of file From e764600bd4f3b3d93a63db8a277df234f915c6b5 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sat, 21 Nov 2015 15:40:25 +0100 Subject: [PATCH 07/13] Split controller.js in multiple files. --- index.html | 2 ++ js/api.js | 7 +++++++ js/controller.js | 43 ------------------------------------------- js/register.js | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 js/api.js create mode 100644 js/register.js diff --git a/index.html b/index.html index 42a84e5..1618154 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,8 @@ + + diff --git a/js/api.js b/js/api.js new file mode 100644 index 0000000..aabe5f6 --- /dev/null +++ b/js/api.js @@ -0,0 +1,7 @@ +angular.module('Come2HelpController').factory('Abilities', ['$resource', function ($resource) { + return $resource('api/abilities/:id'); +}]); + +angular.module('Come2HelpController').factory('Volunteers', ['$resource', function ($resource) { + return $resource('api/volunteers/:id'); +}]); \ No newline at end of file diff --git a/js/controller.js b/js/controller.js index 36f6473..847fc54 100644 --- a/js/controller.js +++ b/js/controller.js @@ -1,13 +1,5 @@ angular.module('Come2HelpController', ['ngResource']); -angular.module('Come2HelpController').factory('Abilities', ['$resource', function ($resource) { - return $resource('api/abilities/:id'); -}]); - -angular.module('Come2HelpController').factory('Volunteers', ['$resource', function ($resource) { - return $resource('api/volunteers/:id'); -}]); - angular.module('Come2HelpController').service('geocoder', [function () { this.geocode = function (address, outerCallback) { var geocoder = new google.maps.Geocoder(); @@ -24,39 +16,4 @@ angular.module('Come2HelpController').service('geocoder', [function () { } }); }; -}]); - -angular.module('Come2HelpController').controller('RegisterController', ['Abilities', 'Volunteers', '$routeParams', function (Abilities, Volunteers, $routeParams) { - var vm = this; - - vm.errors = null; - - Abilities.query(function (data) { - vm.abilities = data; - }); - - vm.doRegister = function () { - Volunteers.save({ - 'givenName': vm.givenName, - 'surname': vm.surname, - 'address': { - 'zipCode': vm.zipCode - }, - 'phone': vm.phone, - 'adult': vm.adult == true - - }, function() { - vm.errors = null; - - - // TODO: Clear form and send to ``thank you''-page - }, function (response) { - vm.errors = {}; - - for (var i = 0; i < response.data.clientErrors.length; i++) { - var errorData = response.data.clientErrors[i]; - vm.errors[errorData.path] = true; - } - }); - }; }]); \ No newline at end of file diff --git a/js/register.js b/js/register.js new file mode 100644 index 0000000..46825f1 --- /dev/null +++ b/js/register.js @@ -0,0 +1,34 @@ +angular.module('Come2HelpController').controller('RegisterController', ['Abilities', 'Volunteers', '$routeParams', function (Abilities, Volunteers, $routeParams) { + var vm = this; + + vm.errors = null; + + Abilities.query(function (data) { + vm.abilities = data; + }); + + vm.doRegister = function () { + Volunteers.save({ + 'givenName': vm.givenName, + 'surname': vm.surname, + 'address': { + 'zipCode': vm.zipCode + }, + 'phone': vm.phone, + 'adult': vm.adult == true + + }, function() { + vm.errors = null; + + + // TODO: Clear form and send to ``thank you''-page + }, function (response) { + vm.errors = {}; + + for (var i = 0; i < response.data.clientErrors.length; i++) { + var errorData = response.data.clientErrors[i]; + vm.errors[errorData.path] = true; + } + }); + }; +}]); \ No newline at end of file From 196077bf135b59ab18bf471461092d9b25851c2e Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sat, 21 Nov 2015 15:49:27 +0100 Subject: [PATCH 08/13] Changed ability test to using mocks. --- test/behaviour/mocks/abilities.js | 19 +++++++++++++++++++ test/behaviour/register.js | 8 +++++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/behaviour/mocks/abilities.js diff --git a/test/behaviour/mocks/abilities.js b/test/behaviour/mocks/abilities.js new file mode 100644 index 0000000..b2a4e1c --- /dev/null +++ b/test/behaviour/mocks/abilities.js @@ -0,0 +1,19 @@ +module.exports = [ + { + request: { + path: '/abilities', + method: 'GET' + }, + response: { + status: 200, + data: [{ + id: 42, + name: 'Mocked Ability 1' + }, + { + id: 69, + name: 'Mocked Ability 1' + }] + } + } +]; \ No newline at end of file diff --git a/test/behaviour/register.js b/test/behaviour/register.js index 44ea891..8ba6921 100644 --- a/test/behaviour/register.js +++ b/test/behaviour/register.js @@ -14,12 +14,14 @@ describe('Register', function() { var abilitylist = by.repeater('ability in ctrl.abilities'); - it('should have two entries: "Ability 1" and "Ability 2"', function() { + it('should have two entries: "Mocked Ability 1" and "Mocked Ability 2"', function() { + mock(['abilities']); + browser.getPart('register'); expect(element.all(abilitylist).count()).to.eventually.equal(2); - expect(element(abilitylist.column('ability.name').row(0)).getInnerHtml()).to.eventually.contain('Ability 1'); - expect(element(abilitylist.column('ability.name').row(1)).getInnerHtml()).to.eventually.contain('Ability 2'); + expect(element(abilitylist.column('ability.name').row(0)).getInnerHtml()).to.eventually.contain('Mocked Ability'); + expect(element(abilitylist.column('ability.name').row(1)).getInnerHtml()).to.eventually.contain('Mocked Ability'); }); it('register with correct data', function() { From c3084d7a362d4e1e3ba8a14bc3051f5740952644 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sat, 21 Nov 2015 16:01:28 +0100 Subject: [PATCH 09/13] Implemented success page for user registration. --- js/app.js | 5 +++++ js/i18n.js | 6 ++++-- js/register.js | 15 ++++++++++++--- partials/registerDone.html | 4 ++++ 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 partials/registerDone.html diff --git a/js/app.js b/js/app.js index 95ece78..c7c9efb 100644 --- a/js/app.js +++ b/js/app.js @@ -12,6 +12,11 @@ angular.module('Come2HelpApp', [ controller: 'RegisterController', controllerAs: 'ctrl' }). + when('/register/done', { + templateUrl: 'partials/registerDone.html', + controller: 'RegisterDoneController', + controllerAs: 'ctrl' + }). otherwise({ redirectTo: '/register' }); diff --git a/js/i18n.js b/js/i18n.js index f665f00..b2f6f6a 100644 --- a/js/i18n.js +++ b/js/i18n.js @@ -17,7 +17,8 @@ angular.module('Come2HelpApp').config(['$translateProvider', function ($translat 'Phone': 'Phone', 'Is Adult': 'Is Adult', 'Abilities': 'Abilities', - 'Please correct the highlighted fields.': 'Please correct the highlighted fields.' + 'Please correct the highlighted fields.': 'Please correct the highlighted fields.', + 'Thank you for register!': 'Thank you for register!' }); $translateProvider.translations('de', { @@ -38,7 +39,8 @@ angular.module('Come2HelpApp').config(['$translateProvider', function ($translat 'Phone': 'Telefonnummer', 'Is Adult': 'Volljährig?', 'Abilities': 'Fähigkeiten', - 'Please correct the highlighted fields.': 'Bitte korrigiere die hervorgebenen Felder.' + 'Please correct the highlighted fields.': 'Bitte korrigiere die hervorgebenen Felder.', + 'Thank you for register!': 'Danke für die Registrierung!' }); $translateProvider.fallbackLanguage('en') diff --git a/js/register.js b/js/register.js index 46825f1..d21ac38 100644 --- a/js/register.js +++ b/js/register.js @@ -1,4 +1,4 @@ -angular.module('Come2HelpController').controller('RegisterController', ['Abilities', 'Volunteers', '$routeParams', function (Abilities, Volunteers, $routeParams) { +angular.module('Come2HelpController').controller('RegisterController', ['Abilities', 'Volunteers', '$routeParams', '$location', function (Abilities, Volunteers, $routeParams, $location) { var vm = this; vm.errors = null; @@ -20,8 +20,13 @@ angular.module('Come2HelpController').controller('RegisterController', ['Abiliti }, function() { vm.errors = null; + vm.givenName = ''; + vm.surname = ''; + vm.zipCode = ''; + vm.phone = ''; + vm.adult = null; - // TODO: Clear form and send to ``thank you''-page + $location.path('/register/done'); }, function (response) { vm.errors = {}; @@ -31,4 +36,8 @@ angular.module('Come2HelpController').controller('RegisterController', ['Abiliti } }); }; -}]); \ No newline at end of file +}]); + +angular.module('Come2HelpController').controller('RegisterDoneController', function () { + +}); \ No newline at end of file diff --git a/partials/registerDone.html b/partials/registerDone.html new file mode 100644 index 0000000..406e6c4 --- /dev/null +++ b/partials/registerDone.html @@ -0,0 +1,4 @@ +
+

{{ 'Thank you for register!' | translate }}

+

{{ 'We will contact you ...' | translate }}

+
\ No newline at end of file From 99d122c59e18260265fdd3e7098d6ef93f50d1e2 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sat, 21 Nov 2015 16:17:30 +0100 Subject: [PATCH 10/13] Implemented success page for user registration. --- test/behaviour/register.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/behaviour/register.js b/test/behaviour/register.js index 8ba6921..70213b9 100644 --- a/test/behaviour/register.js +++ b/test/behaviour/register.js @@ -58,6 +58,8 @@ describe('Register', function() { } ]); expect(element(by.id('error')).isDisplayed()).to.eventually.equal(false); + // Currently the test does not recognize the page forward, so the next line will fail. + //expect(element(by.tagName('h1')).getInnerHtml()).to.eventually.contain('Thank you'); }); From 69d28eb91834dc4f392d85f9c17d54da61d142e0 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sat, 21 Nov 2015 16:25:21 +0100 Subject: [PATCH 11/13] Removed empty controller. --- js/app.js | 4 +--- js/register.js | 6 +----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/js/app.js b/js/app.js index c7c9efb..aab9fbd 100644 --- a/js/app.js +++ b/js/app.js @@ -13,9 +13,7 @@ angular.module('Come2HelpApp', [ controllerAs: 'ctrl' }). when('/register/done', { - templateUrl: 'partials/registerDone.html', - controller: 'RegisterDoneController', - controllerAs: 'ctrl' + templateUrl: 'partials/registerDone.html' }). otherwise({ redirectTo: '/register' diff --git a/js/register.js b/js/register.js index d21ac38..8e9985d 100644 --- a/js/register.js +++ b/js/register.js @@ -36,8 +36,4 @@ angular.module('Come2HelpController').controller('RegisterController', ['Abiliti } }); }; -}]); - -angular.module('Come2HelpController').controller('RegisterDoneController', function () { - -}); \ No newline at end of file +}]); \ No newline at end of file From e5b1be6284d40c5426e5b48b3945513aca9da984 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sun, 22 Nov 2015 17:05:53 +0100 Subject: [PATCH 12/13] Removed /locations mocks. --- test/behaviour/mocks/locations.js | 33 ------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 test/behaviour/mocks/locations.js diff --git a/test/behaviour/mocks/locations.js b/test/behaviour/mocks/locations.js deleted file mode 100644 index a32ea94..0000000 --- a/test/behaviour/mocks/locations.js +++ /dev/null @@ -1,33 +0,0 @@ -module.exports = { - request: { - path: '/locations', - method: 'GET' - }, - response: { - data: [{ - id: 1, - name: 'Sandsäcke füllen', - latitude: 49.1232, - longitude: 8, - location: 'Schlossplatz' - }, { - id: 2, - name: 'Transport', - latitude: 48.1232, - longitude: 8, - location: 'Rheinbad', - options: { - title: 'Transport im Rheinbad' - } - }, { - id: 2, - name: 'Test 3', - latitude: 48.1232, - longitude: 8, - location: 'Rheinbad', - options: { - title: 'Transport im Rheinbad' - } - }] - } -}; \ No newline at end of file From 09ca4c11ccea80d79b79750b8693153506630804 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sun, 22 Nov 2015 17:08:48 +0100 Subject: [PATCH 13/13] Improved naming of behaviour tests. --- test/behaviour/register.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/behaviour/register.js b/test/behaviour/register.js index 70213b9..e6a1f58 100644 --- a/test/behaviour/register.js +++ b/test/behaviour/register.js @@ -14,7 +14,7 @@ describe('Register', function() { var abilitylist = by.repeater('ability in ctrl.abilities'); - it('should have two entries: "Mocked Ability 1" and "Mocked Ability 2"', function() { + it('has two entries: "Mocked Ability 1" and "Mocked Ability 2"', function() { mock(['abilities']); browser.getPart('register'); @@ -24,7 +24,7 @@ describe('Register', function() { expect(element(abilitylist.column('ability.name').row(1)).getInnerHtml()).to.eventually.contain('Mocked Ability'); }); - it('register with correct data', function() { + it('allows to register with correct data', function() { mock(['volunteers']); browser.getPart('register'); @@ -63,7 +63,7 @@ describe('Register', function() { }); - it('register with adult=false', function() { + it('shows an error for adult=false', function() { mock(['volunteers']); browser.getPart('register'); @@ -98,4 +98,4 @@ describe('Register', function() { expect(element.all(by.className('has-error')).count()).to.eventually.equal(1); }); -}); \ No newline at end of file +});