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,6 +9,7 @@ describe("Components", () => { | ||
| 9 | let profileServiceMock: any; | 9 | let profileServiceMock: any; |
| 10 | let notificationMock: any; | 10 | let notificationMock: any; |
| 11 | let $stateParams: any; | 11 | let $stateParams: any; |
| 12 | + let $state: any; | ||
| 12 | 13 | ||
| 13 | beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { | 14 | beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { |
| 14 | $rootScope = _$rootScope_; | 15 | $rootScope = _$rootScope_; |
| @@ -16,6 +17,7 @@ describe("Components", () => { | @@ -16,6 +17,7 @@ describe("Components", () => { | ||
| 16 | })); | 17 | })); |
| 17 | 18 | ||
| 18 | beforeEach(() => { | 19 | beforeEach(() => { |
| 20 | + $state = jasmine.createSpyObj("$state", ["transitionTo"]); | ||
| 19 | $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]); | 21 | $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]); |
| 20 | profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["setCurrentProfileByIdentifier", "getBoxes"]); | 22 | profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["setCurrentProfileByIdentifier", "getBoxes"]); |
| 21 | notificationMock = jasmine.createSpyObj("notificationMock", ["error"]); | 23 | notificationMock = jasmine.createSpyObj("notificationMock", ["error"]); |
| @@ -30,7 +32,7 @@ describe("Components", () => { | @@ -30,7 +32,7 @@ describe("Components", () => { | ||
| 30 | }); | 32 | }); |
| 31 | 33 | ||
| 32 | it("get the profile and store in profile service", done => { | 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 | $rootScope.$apply(); | 36 | $rootScope.$apply(); |
| 35 | expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled(); | 37 | expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled(); |
| 36 | expect(component.profile).toEqual({ id: 1 }); | 38 | expect(component.profile).toEqual({ id: 1 }); |
| @@ -38,7 +40,7 @@ describe("Components", () => { | @@ -38,7 +40,7 @@ describe("Components", () => { | ||
| 38 | }); | 40 | }); |
| 39 | 41 | ||
| 40 | it("get the profile boxes", done => { | 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 | $rootScope.$apply(); | 44 | $rootScope.$apply(); |
| 43 | expect(profileServiceMock.getBoxes).toHaveBeenCalled(); | 45 | expect(profileServiceMock.getBoxes).toHaveBeenCalled(); |
| 44 | expect(component.boxes).toEqual([{ id: 2 }]); | 46 | expect(component.boxes).toEqual([{ id: 2 }]); |
| @@ -50,7 +52,7 @@ describe("Components", () => { | @@ -50,7 +52,7 @@ describe("Components", () => { | ||
| 50 | profileResponse.reject(); | 52 | profileResponse.reject(); |
| 51 | profileServiceMock.setCurrentProfileByIdentifier = jasmine.createSpy("setCurrentProfileByIdentifier").and.returnValue(profileResponse.promise); | 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 | $rootScope.$apply(); | 56 | $rootScope.$apply(); |
| 55 | 57 | ||
| 56 | expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled(); | 58 | expect(profileServiceMock.setCurrentProfileByIdentifier).toHaveBeenCalled(); |
src/app/profile/profile.component.ts
| @@ -85,19 +85,20 @@ import {MyProfileComponent} from "./myprofile.component"; | @@ -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 | export class ProfileComponent { | 89 | export class ProfileComponent { |
| 90 | 90 | ||
| 91 | boxes: noosfero.Box[]; | 91 | boxes: noosfero.Box[]; |
| 92 | profile: noosfero.Profile; | 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 | profileService.setCurrentProfileByIdentifier($stateParams["profile"]).then((profile: noosfero.Profile) => { | 95 | profileService.setCurrentProfileByIdentifier($stateParams["profile"]).then((profile: noosfero.Profile) => { |
| 96 | this.profile = profile; | 96 | this.profile = profile; |
| 97 | return profileService.getBoxes(<number>this.profile.id); | 97 | return profileService.getBoxes(<number>this.profile.id); |
| 98 | }).then((response: restangular.IResponse) => { | 98 | }).then((response: restangular.IResponse) => { |
| 99 | this.boxes = response.data.boxes; | 99 | this.boxes = response.data.boxes; |
| 100 | }).catch(() => { | 100 | }).catch(() => { |
| 101 | + $state.transitionTo('main'); | ||
| 101 | notificationService.error({ message: "notification.profile.not_found" }); | 102 | notificationService.error({ message: "notification.profile.not_found" }); |
| 102 | }); | 103 | }); |
| 103 | } | 104 | } |