Commit 5782eaea6c62c4677ec14540d8669fa03bd01957
1 parent
347a72e4
Exists in
master
and in
30 other branches
Go to homepage when a profile has not been found
Showing
2 changed files
with
8 additions
and
5 deletions
Show diff stats
src/app/profile/profile.component.spec.ts
... | ... | @@ -9,6 +9,7 @@ describe("Components", () => { |
9 | 9 | let profileServiceMock: any; |
10 | 10 | let notificationMock: any; |
11 | 11 | let $stateParams: any; |
12 | + let $state: any; | |
12 | 13 | |
13 | 14 | beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { |
14 | 15 | $rootScope = _$rootScope_; |
... | ... | @@ -16,6 +17,7 @@ describe("Components", () => { |
16 | 17 | })); |
17 | 18 | |
18 | 19 | beforeEach(() => { |
20 | + $state = jasmine.createSpyObj("$state", ["transitionTo"]); | |
19 | 21 | $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]); |
20 | 22 | profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["setCurrentProfileByIdentifier", "getBoxes"]); |
21 | 23 | notificationMock = jasmine.createSpyObj("notificationMock", ["error"]); |
... | ... | @@ -30,7 +32,7 @@ describe("Components", () => { |
30 | 32 | }); |
31 | 33 | |
32 | 34 | it("get the profile and store in profile service", done => { |
33 | - let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock); | |
35 | + let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock); | |
34 | 36 | $rootScope.$apply(); |
35 | 37 | expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled(); |
36 | 38 | expect(component.profile).toEqual({ id: 1 }); |
... | ... | @@ -38,7 +40,7 @@ describe("Components", () => { |
38 | 40 | }); |
39 | 41 | |
40 | 42 | it("get the profile boxes", done => { |
41 | - let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock); | |
43 | + let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock); | |
42 | 44 | $rootScope.$apply(); |
43 | 45 | expect(profileServiceMock.getBoxes).toHaveBeenCalled(); |
44 | 46 | expect(component.boxes).toEqual([{ id: 2 }]); |
... | ... | @@ -50,7 +52,7 @@ describe("Components", () => { |
50 | 52 | profileResponse.reject(); |
51 | 53 | profileServiceMock.setCurrentProfileByIdentifier = jasmine.createSpy("setCurrentProfileByIdentifier").and.returnValue(profileResponse.promise); |
52 | 54 | |
53 | - let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, notificationMock); | |
55 | + let component: ProfileComponent = new ProfileComponent(profileServiceMock, $stateParams, $state, notificationMock); | |
54 | 56 | $rootScope.$apply(); |
55 | 57 | |
56 | 58 | expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled(); | ... | ... |
src/app/profile/profile.component.ts
... | ... | @@ -85,19 +85,20 @@ import {MyProfileComponent} from "./myprofile.component"; |
85 | 85 | } |
86 | 86 | } |
87 | 87 | ]) |
88 | -@Inject(ProfileService, "$stateParams") | |
88 | +@Inject(ProfileService, "$stateParams", "$state") | |
89 | 89 | export class ProfileComponent { |
90 | 90 | |
91 | 91 | boxes: noosfero.Box[]; |
92 | 92 | profile: noosfero.Profile; |
93 | 93 | |
94 | - constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService, notificationService: NotificationService) { | |
94 | + constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService, $state: ng.ui.IStateService, notificationService: NotificationService) { | |
95 | 95 | profileService.setCurrentProfileByIdentifier($stateParams["profile"]).then((profile: noosfero.Profile) => { |
96 | 96 | this.profile = profile; |
97 | 97 | return profileService.getBoxes(<number>this.profile.id); |
98 | 98 | }).then((response: restangular.IResponse) => { |
99 | 99 | this.boxes = response.data.boxes; |
100 | 100 | }).catch(() => { |
101 | + $state.transitionTo('main'); | |
101 | 102 | notificationService.error({ message: "notification.profile.not_found" }); |
102 | 103 | }); |
103 | 104 | } | ... | ... |