diff --git a/src/app/profile/profile.component.spec.ts b/src/app/profile/profile.component.spec.ts new file mode 100644 index 0000000..66277bd --- /dev/null +++ b/src/app/profile/profile.component.spec.ts @@ -0,0 +1,47 @@ +import {quickCreateComponent} from "../../spec/helpers"; +import {Profile} from "./profile.component"; + +describe("Components", () => { + describe("Profile Component", () => { + + let $rootScope: ng.IRootScopeService; + let $q: ng.IQService; + let profileServiceMock: any; + let $stateParams: any; + + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { + $rootScope = _$rootScope_; + $q = _$q_; + })); + + beforeEach(() => { + $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]); + profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getByIdentifier", "getBoxes", "setCurrentProfile"]); + + let getByIdentifierResponse = $q.defer(); + getByIdentifierResponse.resolve({ data: [{ id: 1 }] }); + let getBoxesResponse = $q.defer(); + getBoxesResponse.resolve({ data: { boxes: [{ id: 2 }] } }); + + profileServiceMock.getByIdentifier = jasmine.createSpy("getByIdentifier").and.returnValue(getByIdentifierResponse.promise); + profileServiceMock.getBoxes = jasmine.createSpy("getBoxes").and.returnValue(getBoxesResponse.promise); + }); + + it("get the profile and store in profile service", done => { + let component: Profile = new Profile(profileServiceMock, $stateParams); + $rootScope.$apply(); + expect(profileServiceMock.getByIdentifier).toHaveBeenCalled(); + expect(profileServiceMock.setCurrentProfile).toHaveBeenCalled(); + expect(component.profile).toEqual({ id: 1 }); + done(); + }); + + it("get the profile boxes", done => { + let component: Profile = new Profile(profileServiceMock, $stateParams); + $rootScope.$apply(); + expect(profileServiceMock.getBoxes).toHaveBeenCalled(); + expect(component.boxes).toEqual([{ id: 2 }]); + done(); + }); + }); +}); diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts index 2065af4..6f13f25 100644 --- a/src/app/profile/profile.component.ts +++ b/src/app/profile/profile.component.ts @@ -69,13 +69,13 @@ import * as noosferoModels from "./../models/interfaces"; } } ]) -@Inject(ProfileService, "$log", "$stateParams") +@Inject(ProfileService, "$stateParams") export class Profile { boxes: noosferoModels.Box[]; profile: noosferoModels.Profile; - constructor(profileService: ProfileService, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) { + constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService) { profileService.getByIdentifier($stateParams["profile"]).then((response: restangular.IResponse) => { this.profile = response.data[0]; profileService.setCurrentProfile(this.profile); diff --git a/src/app/profile/profile.controller.spec.js b/src/app/profile/profile.controller.spec.js deleted file mode 100644 index 2951da4..0000000 --- a/src/app/profile/profile.controller.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -(function() { - 'use strict'; - - describe('controllers', function(){ - // var vm; - - beforeEach(module('angular')); - beforeEach(inject(function() { - // vm = _$controller_('MainController'); - })); - }); -})(); -- libgit2 0.21.2