From 5782eaea6c62c4677ec14540d8669fa03bd01957 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 21 Mar 2016 13:59:02 -0300 Subject: [PATCH] Go to homepage when a profile has not been found --- src/app/profile/profile.component.spec.ts | 8 +++++--- src/app/profile/profile.component.ts | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/profile/profile.component.spec.ts b/src/app/profile/profile.component.spec.ts index 0af4c18..af0df31 100644 --- a/src/app/profile/profile.component.spec.ts +++ b/src/app/profile/profile.component.spec.ts @@ -9,6 +9,7 @@ describe("Components", () => { let profileServiceMock: any; let notificationMock: any; let $stateParams: any; + let $state: any; beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { $rootScope = _$rootScope_; @@ -16,6 +17,7 @@ describe("Components", () => { })); beforeEach(() => { + $state = jasmine.createSpyObj("$state", ["transitionTo"]); $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]); profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["setCurrentProfileByIdentifier", "getBoxes"]); notificationMock = jasmine.createSpyObj("notificationMock", ["error"]); @@ -30,7 +32,7 @@ describe("Components", () => { }); it("get the profile and store in profile service", done => { - let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock); + let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock); $rootScope.$apply(); expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled(); expect(component.profile).toEqual({ id: 1 }); @@ -38,7 +40,7 @@ describe("Components", () => { }); it("get the profile boxes", done => { - let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock); + let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock); $rootScope.$apply(); expect(profileServiceMock.getBoxes).toHaveBeenCalled(); expect(component.boxes).toEqual([{ id: 2 }]); @@ -50,7 +52,7 @@ describe("Components", () => { profileResponse.reject(); profileServiceMock.setCurrentProfileByIdentifier = jasmine.createSpy("setCurrentProfileByIdentifier").and.returnValue(profileResponse.promise); - let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock); + let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock); $rootScope.$apply(); expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled(); diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts index 8db9a67..672c37f 100644 --- a/src/app/profile/profile.component.ts +++ b/src/app/profile/profile.component.ts @@ -85,19 +85,20 @@ import {MyProfileComponent} from "./myprofile.component"; } } ]) -@Inject(ProfileService, "$stateParams") +@Inject(ProfileService, "$stateParams", "$state") export class ProfileComponent { boxes: noosfero.Box[]; profile: noosfero.Profile; - constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService, notificationService: NotificationService) { + constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService, $state: ng.ui.IStateService, notificationService: NotificationService) { profileService.setCurrentProfileByIdentifier($stateParams["profile"]).then((profile: noosfero.Profile) => { this.profile = profile; return profileService.getBoxes(this.profile.id); }).then((response: restangular.IResponse) => { this.boxes = response.data.boxes; }).catch(() => { + $state.transitionTo('main'); notificationService.error({ message: "notification.profile.not_found" }); }); } -- libgit2 0.21.2