Commit 1a54ec07f55dcbfafc1e895c55d62c45927145eb

Authored by Carlos Purificação
1 parent 0716bd47

Removed logs to console

src/app/environment/environment-home.component.ts
@@ -22,12 +22,9 @@ export class EnvironmentHomeComponent { @@ -22,12 +22,9 @@ export class EnvironmentHomeComponent {
22 environment: noosfero.Environment; 22 environment: noosfero.Environment;
23 23
24 constructor(private environmentService: EnvironmentService, private $sce: ng.ISCEService) { 24 constructor(private environmentService: EnvironmentService, private $sce: ng.ISCEService) {
25 - console.debug("Constructor from EnvironmentHomeComponent");  
26 -  
27 environmentService.getByIdentifier("default").then((result: noosfero.Environment) => { 25 environmentService.getByIdentifier("default").then((result: noosfero.Environment) => {
28 this.environment = result; 26 this.environment = result;
29 - console.debug("Environment ::", result);  
30 - }) 27 + });
31 } 28 }
32 29
33 getEnvironmentDescription() { 30 getEnvironmentDescription() {
src/app/environment/environment.component.spec.ts 0 → 100644
@@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
  1 +import {quickCreateComponent} from "../../spec/helpers";
  2 +import {EnvironmentComponent} from "./environment.component";
  3 +
  4 +describe("Components", () => {
  5 + describe("Environment Component", () => {
  6 +
  7 + let $rootScope: ng.IRootScopeService;
  8 + let $q: ng.IQService;
  9 + let environmentServiceMock: any;
  10 + let notificationMock: 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 + environmentServiceMock = jasmine.createSpyObj("environmentServiceMock", ["getByIdentifier", "getBoxes"]);
  21 + notificationMock = jasmine.createSpyObj("notificationMock", ["error"]);
  22 +
  23 + let environmentResponse = $q.defer();
  24 + environmentResponse.resolve({ id: 1 });
  25 + let getBoxesResponse = $q.defer();
  26 + getBoxesResponse.resolve({ data: { boxes: [{ id: 2 }] } });
  27 +
  28 + environmentServiceMock.getByIdentifier('default').and.returnValue(environmentResponse.promise);
  29 + environmentServiceMock.getBoxes = jasmine.createSpy("getBoxes").and.returnValue(getBoxesResponse.promise);
  30 + });
  31 +
  32 + it("get the default environment", done => {
  33 + let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock);
  34 + $rootScope.$apply();
  35 + expect(component.environment).toEqual({ id: 1 });
  36 + done();
  37 + });
  38 +
  39 + it("get the environment boxes", done => {
  40 + let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock);
  41 + $rootScope.$apply();
  42 + expect(environmentServiceMock.getBoxes).toHaveBeenCalled();
  43 + expect(component.boxes).toEqual([{ id: 3 }]);
  44 + done();
  45 + });
  46 +
  47 + it("display notification error when the environment wasn't found", done => {
  48 + let environmentResponse = $q.defer();
  49 + environmentResponse.reject();
  50 +
  51 + let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock);
  52 + $rootScope.$apply();
  53 +
  54 + expect(notificationMock.error).toHaveBeenCalled();
  55 + expect(component.environment).toBeUndefined();
  56 + done();
  57 + });
  58 +
  59 + });
  60 +});
src/app/environment/environment.component.ts
@@ -38,13 +38,10 @@ export class EnvironmentComponent { @@ -38,13 +38,10 @@ export class EnvironmentComponent {
38 environment: noosfero.Environment; 38 environment: noosfero.Environment;
39 39
40 constructor(environmentService: EnvironmentService, $state: ng.ui.IStateService, notificationService: NotificationService) { 40 constructor(environmentService: EnvironmentService, $state: ng.ui.IStateService, notificationService: NotificationService) {
41 - //console.debug("Creating EnvironmentComponent...");  
42 let boxesPromisse = environmentService.getByIdentifier("default").then((environment: noosfero.Environment) => { 41 let boxesPromisse = environmentService.getByIdentifier("default").then((environment: noosfero.Environment) => {
43 - //console.debug("Set current environment by identifier callback.: ", environment);  
44 this.environment = environment; 42 this.environment = environment;
45 return environmentService.getBoxes(this.environment.id); 43 return environmentService.getBoxes(this.environment.id);
46 }).then((boxes: noosfero.Box[]) => { 44 }).then((boxes: noosfero.Box[]) => {
47 - //console.debug("Set environment boxes in callback: ", boxes);  
48 this.boxes = boxes; 45 this.boxes = boxes;
49 }).catch(() => { 46 }).catch(() => {
50 $state.transitionTo('main'); 47 $state.transitionTo('main');
src/lib/ng-noosfero-api/http/environment.service.ts
@@ -19,10 +19,7 @@ export class EnvironmentService { @@ -19,10 +19,7 @@ export class EnvironmentService {
19 } 19 }
20 20
21 getByIdentifier(identifier: string): ng.IPromise<noosfero.Environment> { 21 getByIdentifier(identifier: string): ng.IPromise<noosfero.Environment> {
22 - console.debug("Getting the current environment by identifier in service: " + identifier);  
23 let p = this.restangular.one('environment').customGET(identifier); 22 let p = this.restangular.one('environment').customGET(identifier);
24 - console.debug("Return promise: ", p);  
25 -  
26 let deferred = this.$q.defer<noosfero.Environment>(); 23 let deferred = this.$q.defer<noosfero.Environment>();
27 p.then(this.getHandleSuccessFunction<noosfero.Environment>(deferred)); 24 p.then(this.getHandleSuccessFunction<noosfero.Environment>(deferred));
28 p.catch(this.getHandleErrorFunction<noosfero.Environment>(deferred)); 25 p.catch(this.getHandleErrorFunction<noosfero.Environment>(deferred));
@@ -30,10 +27,7 @@ export class EnvironmentService { @@ -30,10 +27,7 @@ export class EnvironmentService {
30 } 27 }
31 28
32 getBoxes(id: number) { 29 getBoxes(id: number) {
33 - console.debug("Getting the environment [${id}] boxes in service", id);  
34 let p = this.restangular.one('environments', id).customGET("boxes"); 30 let p = this.restangular.one('environments', id).customGET("boxes");
35 - console.debug("Return boxes promise in service: ", p);  
36 -  
37 let deferred = this.$q.defer<noosfero.Box[]>(); 31 let deferred = this.$q.defer<noosfero.Box[]>();
38 p.then(this.getHandleSuccessFunctionKeyArray<noosfero.Box[]>("boxes", deferred)); 32 p.then(this.getHandleSuccessFunctionKeyArray<noosfero.Box[]>("boxes", deferred));
39 p.catch(this.getHandleErrorFunction<noosfero.Box[]>(deferred)); 33 p.catch(this.getHandleErrorFunction<noosfero.Box[]>(deferred));