Commit 5368292db8eb99227dcd5088b46e94160a37acd9
1 parent
5f327c27
Exists in
master
and in
34 other branches
Add tests to profile home component
Showing
2 changed files
with
61 additions
and
3 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,58 @@ |
| 1 | +import {quickCreateComponent} from "../../spec/helpers"; | |
| 2 | +import {ProfileHome} from "./profile-home.component"; | |
| 3 | + | |
| 4 | +describe("Components", () => { | |
| 5 | + describe("Profile Home Component", () => { | |
| 6 | + | |
| 7 | + let $rootScope: ng.IRootScopeService; | |
| 8 | + let $q: ng.IQService; | |
| 9 | + let homePageResponse: ng.IDeferred<any>; | |
| 10 | + let profileServiceMock: any; | |
| 11 | + let $state: any; | |
| 12 | + | |
| 13 | + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { | |
| 14 | + $rootScope = _$rootScope_; | |
| 15 | + $q = _$q_; | |
| 16 | + })); | |
| 17 | + | |
| 18 | + beforeEach(() => { | |
| 19 | + $state = jasmine.createSpyObj("$state", ["transitionTo"]); | |
| 20 | + profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile", "getHomePage"]); | |
| 21 | + | |
| 22 | + let currentProfileResponse = $q.defer(); | |
| 23 | + currentProfileResponse.resolve({ identifier: "profile" }); | |
| 24 | + homePageResponse = $q.defer(); | |
| 25 | + | |
| 26 | + profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(currentProfileResponse.promise); | |
| 27 | + profileServiceMock.getHomePage = jasmine.createSpy("getHomePage").and.returnValue(homePageResponse.promise); | |
| 28 | + }); | |
| 29 | + | |
| 30 | + it("transition to profile homepage when there is a homepage setted", done => { | |
| 31 | + homePageResponse.resolve({ data: { article: { path: "something" } } }); | |
| 32 | + | |
| 33 | + let component: ProfileHome = new ProfileHome(profileServiceMock, $state); | |
| 34 | + $rootScope.$apply(); | |
| 35 | + expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); | |
| 36 | + expect(profileServiceMock.getHomePage).toHaveBeenCalled(); | |
| 37 | + | |
| 38 | + expect($state.transitionTo). | |
| 39 | + toHaveBeenCalledWith("main.profile.page", | |
| 40 | + { page: "something", profile: "profile" }, { location: false }); | |
| 41 | + done(); | |
| 42 | + }); | |
| 43 | + | |
| 44 | + it("transition to profile info page when there is no homepage setted", done => { | |
| 45 | + homePageResponse.resolve({ data: {} }); | |
| 46 | + | |
| 47 | + let component: ProfileHome = new ProfileHome(profileServiceMock, $state); | |
| 48 | + $rootScope.$apply(); | |
| 49 | + expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); | |
| 50 | + expect(profileServiceMock.getHomePage).toHaveBeenCalled(); | |
| 51 | + | |
| 52 | + expect($state.transitionTo). | |
| 53 | + toHaveBeenCalledWith("main.profile.info", | |
| 54 | + { profile: "profile" }, { location: false }); | |
| 55 | + done(); | |
| 56 | + }); | |
| 57 | + }); | |
| 58 | +}); | ... | ... |
src/app/profile/profile-home.component.ts
| ... | ... | @@ -8,15 +8,15 @@ import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; |
| 8 | 8 | template: "<div></div>", |
| 9 | 9 | providers: [provide('profileService', { useClass: ProfileService })] |
| 10 | 10 | }) |
| 11 | -@Inject(ProfileService, "$log", "$stateParams", "$scope", "$state") | |
| 11 | +@Inject(ProfileService, "$state") | |
| 12 | 12 | export class ProfileHome { |
| 13 | 13 | |
| 14 | 14 | profile: Profile; |
| 15 | 15 | |
| 16 | - constructor(profileService: ProfileService, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) { | |
| 16 | + constructor(profileService: ProfileService, $state: ng.ui.IStateService) { | |
| 17 | 17 | profileService.getCurrentProfile().then((profile: Profile) => { |
| 18 | 18 | this.profile = profile; |
| 19 | - return profileService.get(this.profile.id).customGET('home_page', { fields: 'path' }); | |
| 19 | + return profileService.getHomePage(this.profile.id, { fields: 'path' }); | |
| 20 | 20 | }).then((response: restangular.IResponse) => { |
| 21 | 21 | if (response.data.article) { |
| 22 | 22 | $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false }); | ... | ... |