diff --git a/src/app/environment/environment-home.component.ts b/src/app/environment/environment-home.component.ts index baffb31..eb22086 100644 --- a/src/app/environment/environment-home.component.ts +++ b/src/app/environment/environment-home.component.ts @@ -22,12 +22,9 @@ export class EnvironmentHomeComponent { environment: noosfero.Environment; constructor(private environmentService: EnvironmentService, private $sce: ng.ISCEService) { - console.debug("Constructor from EnvironmentHomeComponent"); - environmentService.getByIdentifier("default").then((result: noosfero.Environment) => { this.environment = result; - console.debug("Environment ::", result); - }) + }); } getEnvironmentDescription() { diff --git a/src/app/environment/environment.component.spec.ts b/src/app/environment/environment.component.spec.ts new file mode 100644 index 0000000..8a64298 --- /dev/null +++ b/src/app/environment/environment.component.spec.ts @@ -0,0 +1,60 @@ +import {quickCreateComponent} from "../../spec/helpers"; +import {EnvironmentComponent} from "./environment.component"; + +describe("Components", () => { + describe("Environment Component", () => { + + let $rootScope: ng.IRootScopeService; + let $q: ng.IQService; + let environmentServiceMock: any; + let notificationMock: any; + let $state: any; + + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { + $rootScope = _$rootScope_; + $q = _$q_; + })); + + beforeEach(() => { + $state = jasmine.createSpyObj("$state", ["transitionTo"]); + environmentServiceMock = jasmine.createSpyObj("environmentServiceMock", ["getByIdentifier", "getBoxes"]); + notificationMock = jasmine.createSpyObj("notificationMock", ["error"]); + + let environmentResponse = $q.defer(); + environmentResponse.resolve({ id: 1 }); + let getBoxesResponse = $q.defer(); + getBoxesResponse.resolve({ data: { boxes: [{ id: 2 }] } }); + + environmentServiceMock.getByIdentifier('default').and.returnValue(environmentResponse.promise); + environmentServiceMock.getBoxes = jasmine.createSpy("getBoxes").and.returnValue(getBoxesResponse.promise); + }); + + it("get the default environment", done => { + let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock); + $rootScope.$apply(); + expect(component.environment).toEqual({ id: 1 }); + done(); + }); + + it("get the environment boxes", done => { + let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock); + $rootScope.$apply(); + expect(environmentServiceMock.getBoxes).toHaveBeenCalled(); + expect(component.boxes).toEqual([{ id: 3 }]); + done(); + }); + + it("display notification error when the environment wasn't found", done => { + let environmentResponse = $q.defer(); + environmentResponse.reject(); + + let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock); + $rootScope.$apply(); + + expect(notificationMock.error).toHaveBeenCalled(); + expect(component.environment).toBeUndefined(); + done(); + }); + + }); +}); diff --git a/src/app/environment/environment.component.ts b/src/app/environment/environment.component.ts index fee1d30..d05df28 100644 --- a/src/app/environment/environment.component.ts +++ b/src/app/environment/environment.component.ts @@ -38,13 +38,10 @@ export class EnvironmentComponent { environment: noosfero.Environment; constructor(environmentService: EnvironmentService, $state: ng.ui.IStateService, notificationService: NotificationService) { - //console.debug("Creating EnvironmentComponent..."); let boxesPromisse = environmentService.getByIdentifier("default").then((environment: noosfero.Environment) => { - //console.debug("Set current environment by identifier callback.: ", environment); this.environment = environment; return environmentService.getBoxes(this.environment.id); }).then((boxes: noosfero.Box[]) => { - //console.debug("Set environment boxes in callback: ", boxes); this.boxes = boxes; }).catch(() => { $state.transitionTo('main'); diff --git a/src/lib/ng-noosfero-api/http/environment.service.ts b/src/lib/ng-noosfero-api/http/environment.service.ts index 8ec6250..4567594 100644 --- a/src/lib/ng-noosfero-api/http/environment.service.ts +++ b/src/lib/ng-noosfero-api/http/environment.service.ts @@ -19,10 +19,7 @@ export class EnvironmentService { } getByIdentifier(identifier: string): ng.IPromise { - console.debug("Getting the current environment by identifier in service: " + identifier); let p = this.restangular.one('environment').customGET(identifier); - console.debug("Return promise: ", p); - let deferred = this.$q.defer(); p.then(this.getHandleSuccessFunction(deferred)); p.catch(this.getHandleErrorFunction(deferred)); @@ -30,10 +27,7 @@ export class EnvironmentService { } getBoxes(id: number) { - console.debug("Getting the environment [${id}] boxes in service", id); let p = this.restangular.one('environments', id).customGET("boxes"); - console.debug("Return boxes promise in service: ", p); - let deferred = this.$q.defer(); p.then(this.getHandleSuccessFunctionKeyArray("boxes", deferred)); p.catch(this.getHandleErrorFunction(deferred)); -- libgit2 0.21.2