Commit eb78feb65e75f6e616fcd11ac280bcff55e2ffbd
Exists in
master
and in
30 other branches
Merge branch 'master' of softwarepublico.gov.br:noosfero-themes/angular-theme
Showing
4 changed files
with
61 additions
and
13 deletions
Show diff stats
src/app/environment/environment-home.component.ts
... | ... | @@ -22,12 +22,9 @@ export class EnvironmentHomeComponent { |
22 | 22 | environment: noosfero.Environment; |
23 | 23 | |
24 | 24 | constructor(private environmentService: EnvironmentService, private $sce: ng.ISCEService) { |
25 | - console.debug("Constructor from EnvironmentHomeComponent"); | |
26 | - | |
27 | 25 | environmentService.getByIdentifier("default").then((result: noosfero.Environment) => { |
28 | 26 | this.environment = result; |
29 | - console.debug("Environment ::", result); | |
30 | - }) | |
27 | + }); | |
31 | 28 | } |
32 | 29 | |
33 | 30 | getEnvironmentDescription() { | ... | ... |
... | ... | @@ -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 | 38 | environment: noosfero.Environment; |
39 | 39 | |
40 | 40 | constructor(environmentService: EnvironmentService, $state: ng.ui.IStateService, notificationService: NotificationService) { |
41 | - //console.debug("Creating EnvironmentComponent..."); | |
42 | 41 | let boxesPromisse = environmentService.getByIdentifier("default").then((environment: noosfero.Environment) => { |
43 | - //console.debug("Set current environment by identifier callback.: ", environment); | |
44 | 42 | this.environment = environment; |
45 | 43 | return environmentService.getBoxes(this.environment.id); |
46 | 44 | }).then((boxes: noosfero.Box[]) => { |
47 | - //console.debug("Set environment boxes in callback: ", boxes); | |
48 | 45 | this.boxes = boxes; |
49 | 46 | }).catch(() => { |
50 | 47 | $state.transitionTo('main'); | ... | ... |
src/lib/ng-noosfero-api/http/environment.service.ts
... | ... | @@ -19,10 +19,7 @@ export class EnvironmentService { |
19 | 19 | } |
20 | 20 | |
21 | 21 | getByIdentifier(identifier: string): ng.IPromise<noosfero.Environment> { |
22 | - console.debug("Getting the current environment by identifier in service: " + identifier); | |
23 | 22 | let p = this.restangular.one('environment').customGET(identifier); |
24 | - console.debug("Return promise: ", p); | |
25 | - | |
26 | 23 | let deferred = this.$q.defer<noosfero.Environment>(); |
27 | 24 | p.then(this.getHandleSuccessFunction<noosfero.Environment>(deferred)); |
28 | 25 | p.catch(this.getHandleErrorFunction<noosfero.Environment>(deferred)); |
... | ... | @@ -30,10 +27,7 @@ export class EnvironmentService { |
30 | 27 | } |
31 | 28 | |
32 | 29 | getBoxes(id: number) { |
33 | - console.debug("Getting the environment [${id}] boxes in service", id); | |
34 | 30 | let p = this.restangular.one('environments', id).customGET("boxes"); |
35 | - console.debug("Return boxes promise in service: ", p); | |
36 | - | |
37 | 31 | let deferred = this.$q.defer<noosfero.Box[]>(); |
38 | 32 | p.then(this.getHandleSuccessFunctionKeyArray<noosfero.Box[]>("boxes", deferred)); |
39 | 33 | p.catch(this.getHandleErrorFunction<noosfero.Box[]>(deferred)); | ... | ... |