Commit a4dac9eca7f123137a34fa9f0d5b3ebfd8fd302a
1 parent
224b593d
Exists in
master
and in
7 other branches
Added unit tests and minor refactories
Showing
8 changed files
with
131 additions
and
9 deletions
Show diff stats
src/app/account/register-component.html
| ... | ... | @@ -51,7 +51,7 @@ |
| 51 | 51 | <div class="form-group col-md-6 register-field" ng-class="ctrl.isInvalid(signupForm.passwordConfirm)"> |
| 52 | 52 | <div class="input-group"> |
| 53 | 53 | <span class="input-group-addon"><i class="fa fa-unlock-alt"></i></span> |
| 54 | - <input type="password" class="form-control" id="passwordConfirm" name="passwordConfirm" match-password="password" placeholder="{{'account.register.passwordConfirmationLabel' | translate}}" ng-model="ctrl.account.password_confirmation" required> | |
| 54 | + <input type="password" class="form-control" id="passwordConfirm" name="passwordConfirm" match-password="password" placeholder="{{'account.register.passwordConfirmationLabel' | translate}}" ng-model="ctrl.account.passwordConfirmation" required> | |
| 55 | 55 | </div> |
| 56 | 56 | <div class="help-block" ng-show="signupForm.passwordConfirm.$touched" ng-messages="signupForm.passwordConfirm.$error"> |
| 57 | 57 | <ul class="list-unstyled"> | ... | ... |
| ... | ... | @@ -0,0 +1,52 @@ |
| 1 | +import { ComponentTestHelper, createClass } from "../../spec/component-test-helper"; | |
| 2 | +import * as helpers from "../../spec/helpers"; | |
| 3 | +import { RegisterComponent } from "./register.component"; | |
| 4 | +// import {RegisterService} from "../../lib/ng-noosfero-api/http/register.service" | |
| 5 | + | |
| 6 | + | |
| 7 | +describe("Register Component", () => { | |
| 8 | + const htmlTemplate: string = '<noosfero-register></noosfero-register>'; | |
| 9 | + | |
| 10 | + let helper: ComponentTestHelper<RegisterComponent>; | |
| 11 | + let registerService = helpers.mocks.registerService; | |
| 12 | + let stateService = jasmine.createSpyObj("$state", ["transitionTo"]); | |
| 13 | + let notificationService = helpers.mocks.notificationService; | |
| 14 | + notificationService.success = jasmine.createSpy('success'); | |
| 15 | + notificationService.error = jasmine.createSpy('error'); | |
| 16 | + | |
| 17 | + | |
| 18 | + let account: any = { | |
| 19 | + id: 1, | |
| 20 | + login: 'test', | |
| 21 | + email: 'test@email.com', | |
| 22 | + password: 'xxx', | |
| 23 | + passwordConfirmation: 'xxx' | |
| 24 | + }; | |
| 25 | + | |
| 26 | + beforeEach(() => { | |
| 27 | + angular.mock.module('templates'); | |
| 28 | + angular.mock.module('ngSanitize'); | |
| 29 | + angular.mock.module('ngMessages'); | |
| 30 | + angular.mock.module('ngPassword'); | |
| 31 | + }); | |
| 32 | + | |
| 33 | + beforeEach((done) => { | |
| 34 | + let cls = createClass({ | |
| 35 | + template: htmlTemplate, | |
| 36 | + directives: [RegisterComponent], | |
| 37 | + providers: [ | |
| 38 | + helpers.createProviderToValue('$state', stateService), | |
| 39 | + helpers.createProviderToValue('$uibModal', helpers.mocks.$modal), | |
| 40 | + helpers.createProviderToValue('RegisterService', registerService), | |
| 41 | + helpers.createProviderToValue('NotificationService', notificationService), | |
| 42 | + helpers.createProviderToValue('EnvironmentService', helpers.mocks.environmentService) | |
| 43 | + ] | |
| 44 | + }); | |
| 45 | + helper = new ComponentTestHelper<RegisterComponent>(cls, done); | |
| 46 | + }); | |
| 47 | + | |
| 48 | + it('register page was rendered', () => { | |
| 49 | + expect(helper.debugElement.query('div.register-page').length).toEqual(1); | |
| 50 | + }); | |
| 51 | + | |
| 52 | +}); | ... | ... |
src/app/account/register.component.ts
| ... | ... | @@ -26,15 +26,16 @@ export class RegisterComponent { |
| 26 | 26 | private $scope: ng.IScope, |
| 27 | 27 | public registerService: RegisterService, |
| 28 | 28 | private notificationService: NotificationService, |
| 29 | - private environmentService: EnvironmentService, | |
| 29 | + private environmentService: EnvironmentService | |
| 30 | 30 | ) { |
| 31 | 31 | this.account = {}; |
| 32 | 32 | this.environment = environmentService.getCurrentEnvironment(); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | signup() { |
| 36 | - if (this.account.password === this.account.password_confirmation) { | |
| 36 | + if (this.account.password === this.account.passwordConfirmation) { | |
| 37 | 37 | this.registerService.createAccount(this.account).then((response) => { |
| 38 | + | |
| 38 | 39 | if (response.status === 201) { |
| 39 | 40 | this.$state.transitionTo('main.environment'); |
| 40 | 41 | this.notificationService.success({ title: "account.register.success.title", message: "account.register.success.message" }); |
| ... | ... | @@ -47,7 +48,7 @@ export class RegisterComponent { |
| 47 | 48 | } |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - isInvalid(field: Object): Object { | |
| 51 | + isInvalid(field: any): any { | |
| 51 | 52 | return { 'has-error': field['$touched'] && field['$invalid'] }; |
| 52 | 53 | } |
| 53 | 54 | ... | ... |
src/app/account/register.controller.ts
| ... | ... | @@ -0,0 +1,39 @@ |
| 1 | +import { RegisterService } from "./register.service"; | |
| 2 | + | |
| 3 | +describe("Services", () => { | |
| 4 | + | |
| 5 | + describe("Register Service", () => { | |
| 6 | + | |
| 7 | + let $httpBackend: ng.IHttpBackendService; | |
| 8 | + let registerService: RegisterService; | |
| 9 | + let $rootScope: ng.IRootScopeService; | |
| 10 | + let user: any = { | |
| 11 | + id: 1, | |
| 12 | + login: 'test', | |
| 13 | + email: 'test@email.com' | |
| 14 | + }; | |
| 15 | + | |
| 16 | + beforeEach(angular.mock.module("main", ($translateProvider: angular.translate.ITranslateProvider) => { | |
| 17 | + $translateProvider.translations('en', {}); | |
| 18 | + })); | |
| 19 | + | |
| 20 | + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _RegisterService_: RegisterService, _$rootScope_: ng.IRootScopeService) => { | |
| 21 | + $httpBackend = _$httpBackend_; | |
| 22 | + registerService = _RegisterService_; | |
| 23 | + $rootScope = _$rootScope_; | |
| 24 | + })); | |
| 25 | + | |
| 26 | + describe("Succesfull requests", () => { | |
| 27 | + | |
| 28 | + it("should creaet a new account", (done) => { | |
| 29 | + | |
| 30 | + $httpBackend.expectPOST(`/api/v1/register?email=${user.email}&id=${user.id}&login=${user.login}`).respond(201, [{ login: "test" }]); | |
| 31 | + registerService.createAccount(user).then((response: restangular.IResponse) => { | |
| 32 | + expect(response.data[0].login).toEqual("test"); | |
| 33 | + done(); | |
| 34 | + }); | |
| 35 | + $httpBackend.flush(); | |
| 36 | + }); | |
| 37 | + }); | |
| 38 | + }); | |
| 39 | +}); | ... | ... |
src/lib/ng-noosfero-api/http/register.service.ts
src/lib/ng-noosfero-api/interfaces/environment.ts
| ... | ... | @@ -5,7 +5,7 @@ namespace noosfero { |
| 5 | 5 | * @name noofero.Environment |
| 6 | 6 | * @description |
| 7 | 7 | * A representation of a Noosfero Environment. |
| 8 | - */ | |
| 8 | + */ | |
| 9 | 9 | export interface Environment extends RestModel { |
| 10 | 10 | /** |
| 11 | 11 | * @ngdoc property |
| ... | ... | @@ -23,6 +23,21 @@ namespace noosfero { |
| 23 | 23 | * @returns {string} The Environment layout (e.g. default, rightbar) |
| 24 | 24 | */ |
| 25 | 25 | layout_template: string; |
| 26 | + | |
| 27 | + /** | |
| 28 | + * @ngdoc property | |
| 29 | + * @name signup_intro | |
| 30 | + * @propertyOf noofero.Environment | |
| 31 | + * @returns {string} The Environment signup introduction HTML (e.g. Welcome to Noosfero...!!) | |
| 32 | + */ | |
| 33 | + signup_intro: string; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @ngdoc property | |
| 37 | + * @name host | |
| 38 | + * @propertyOf noofero.Environment | |
| 39 | + * @returns {string} The Environment default domain address with 'http://' prefix (e.g. http://localhost) | |
| 40 | + */ | |
| 41 | + host: string; | |
| 26 | 42 | } |
| 27 | 43 | } |
| 28 | - | ... | ... |
src/spec/mocks.ts
| ... | ... | @@ -40,6 +40,11 @@ export var mocks: any = { |
| 40 | 40 | return this.modalInstance; |
| 41 | 41 | } |
| 42 | 42 | }, |
| 43 | + registerService: { | |
| 44 | + createAccount: (user: noosfero.User) => { | |
| 45 | + return Promise.resolve({ status: 201 }); | |
| 46 | + } | |
| 47 | + }, | |
| 43 | 48 | authService: { |
| 44 | 49 | loginSuccess: { |
| 45 | 50 | event: Function, |
| ... | ... | @@ -145,6 +150,15 @@ export var mocks: any = { |
| 145 | 150 | return mocks.promiseResultTemplate({ |
| 146 | 151 | people: {} |
| 147 | 152 | }); |
| 153 | + }, | |
| 154 | + getCurrentEnvironment: (): any => { | |
| 155 | + return { | |
| 156 | + id: 1, | |
| 157 | + settings: {}, | |
| 158 | + layout_template: '', | |
| 159 | + signup_intro: 'Welcome to Noosfero', | |
| 160 | + host: 'http://localhost' | |
| 161 | + }; | |
| 148 | 162 | } |
| 149 | 163 | }, |
| 150 | 164 | profileService: { |
| ... | ... | @@ -240,6 +254,7 @@ export var mocks: any = { |
| 240 | 254 | }, |
| 241 | 255 | notificationService: { |
| 242 | 256 | success: () => { }, |
| 243 | - confirmation: () => { } | |
| 257 | + confirmation: () => { }, | |
| 258 | + error: () => { } | |
| 244 | 259 | } |
| 245 | 260 | }; | ... | ... |