Commit 96006ac8fa4eb48cc6ba7fce6cd3f2824ed7f68e

Authored by Victor Costa
1 parent 98db105e

Add tests to profile component

src/app/profile/profile.component.spec.ts 0 → 100644
... ... @@ -0,0 +1,47 @@
  1 +import {quickCreateComponent} from "../../spec/helpers";
  2 +import {Profile} from "./profile.component";
  3 +
  4 +describe("Components", () => {
  5 + describe("Profile Component", () => {
  6 +
  7 + let $rootScope: ng.IRootScopeService;
  8 + let $q: ng.IQService;
  9 + let profileServiceMock: any;
  10 + let $stateParams: any;
  11 +
  12 + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
  13 + $rootScope = _$rootScope_;
  14 + $q = _$q_;
  15 + }));
  16 +
  17 + beforeEach(() => {
  18 + $stateParams = jasmine.createSpyObj("$stateParams", ["profile"]);
  19 + profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getByIdentifier", "getBoxes", "setCurrentProfile"]);
  20 +
  21 + let getByIdentifierResponse = $q.defer();
  22 + getByIdentifierResponse.resolve({ data: [{ id: 1 }] });
  23 + let getBoxesResponse = $q.defer();
  24 + getBoxesResponse.resolve({ data: { boxes: [{ id: 2 }] } });
  25 +
  26 + profileServiceMock.getByIdentifier = jasmine.createSpy("getByIdentifier").and.returnValue(getByIdentifierResponse.promise);
  27 + profileServiceMock.getBoxes = jasmine.createSpy("getBoxes").and.returnValue(getBoxesResponse.promise);
  28 + });
  29 +
  30 + it("get the profile and store in profile service", done => {
  31 + let component: Profile = new Profile(profileServiceMock, $stateParams);
  32 + $rootScope.$apply();
  33 + expect(profileServiceMock.getByIdentifier).toHaveBeenCalled();
  34 + expect(profileServiceMock.setCurrentProfile).toHaveBeenCalled();
  35 + expect(component.profile).toEqual({ id: 1 });
  36 + done();
  37 + });
  38 +
  39 + it("get the profile boxes", done => {
  40 + let component: Profile = new Profile(profileServiceMock, $stateParams);
  41 + $rootScope.$apply();
  42 + expect(profileServiceMock.getBoxes).toHaveBeenCalled();
  43 + expect(component.boxes).toEqual([{ id: 2 }]);
  44 + done();
  45 + });
  46 + });
  47 +});
... ...
src/app/profile/profile.component.ts
... ... @@ -69,13 +69,13 @@ import * as noosferoModels from "./../models/interfaces";
69 69 }
70 70 }
71 71 ])
72   -@Inject(ProfileService, "$log", "$stateParams")
  72 +@Inject(ProfileService, "$stateParams")
73 73 export class Profile {
74 74  
75 75 boxes: noosferoModels.Box[];
76 76 profile: noosferoModels.Profile;
77 77  
78   - constructor(profileService: ProfileService, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) {
  78 + constructor(profileService: ProfileService, $stateParams: ng.ui.IStateParamsService) {
79 79 profileService.getByIdentifier($stateParams["profile"]).then((response: restangular.IResponse) => {
80 80 this.profile = response.data[0];
81 81 profileService.setCurrentProfile(this.profile);
... ...
src/app/profile/profile.controller.spec.js
... ... @@ -1,12 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - describe('controllers', function(){
5   - // var vm;
6   -
7   - beforeEach(module('angular'));
8   - beforeEach(inject(function() {
9   - // vm = _$controller_('MainController');
10   - }));
11   - });
12   -})();