Commit c3feee1acd64a2ec1f5941b9c09e10ea0deaca35

Authored by Carlos Purificação
1 parent 24a44ec4

Fixed tests

src/app/admin/layout-edit/designMode.service.spec.ts
1 1 import {DesignModeService} from './designMode.service';
  2 +import {INoosferoLocalStorage} from "./../../shared/models/interfaces";
2 3  
3 4 describe('DesignMode Service', () => {
4 5 let service: DesignModeService;
5 6  
  7 + let $localStorage = <INoosferoLocalStorage>{ currentUser: null, settings: { designMode: false } };
6 8 beforeEach(() => {
7   - service = new DesignModeService();
  9 + service = new DesignModeService($localStorage);
8 10 });
9 11  
10 12 it('has the designModeOn equals false as default', () => {
... ... @@ -18,12 +20,14 @@ describe(&#39;DesignMode Service&#39;, () =&gt; {
18 20 });
19 21  
20 22 it('emits the onToggle event when changing the designModeOn property', () => {
  23 + service.setInDesignMode(false);
21 24 spyOn(service.onToggle, 'next').and.stub();
22 25 service.setInDesignMode(true);
23 26 expect(service.onToggle.next).toHaveBeenCalled();
24 27 });
25 28  
26 29 it('does not emit onToggle event when there is no change on designModeOn property', () => {
  30 + service.setInDesignMode(false);
27 31 spyOn(service.onToggle, 'next').and.stub();
28 32 service.setInDesignMode(false);
29 33 expect(service.onToggle.next).not.toHaveBeenCalled();
... ...
src/app/admin/layout-edit/designModeToggler.component.spec.ts
... ... @@ -2,6 +2,7 @@ import {ComponentTestHelper, createClass} from &#39;../../../spec/component-test-hel
2 2 import * as helpers from '../../../spec/helpers';
3 3 import {DesignModeTogglerComponent} from './designModeToggler.component';
4 4 import {DesignModeService} from './designMode.service';
  5 +import {INoosferoLocalStorage} from "./../../shared/models/interfaces";
5 6  
6 7 describe('DesignModeToggler Component', () => {
7 8 const htmlTemplate: string = '<noosfero-design-toggler></noosfero-design-toggler>';
... ... @@ -14,8 +15,9 @@ describe(&#39;DesignModeToggler Component&#39;, () =&gt; {
14 15 });
15 16  
16 17 let designModeService: DesignModeService;
  18 + let $localStorage = <INoosferoLocalStorage>{ currentUser: null, settings: { designMode: false } };
17 19 beforeEach((done) => {
18   - designModeService = new DesignModeService();
  20 + designModeService = new DesignModeService($localStorage);
19 21 let cls = createClass({
20 22 template: htmlTemplate,
21 23 directives: [DesignModeTogglerComponent],
... ... @@ -36,6 +38,7 @@ describe(&#39;DesignModeToggler Component&#39;, () =&gt; {
36 38 });
37 39  
38 40 it('emits event with value "true" when changing inDesignMode to On', (done) => {
  41 + designModeService.setInDesignMode(false);
39 42 designModeService.onToggle.subscribe((designModeOn: boolean) => {
40 43 expect(designModeOn).toBeTruthy();
41 44 done();
... ...
src/app/layout/blocks/block.component.spec.ts
... ... @@ -2,6 +2,7 @@ import {Component} from &#39;ng-forward&#39;;
2 2 import {BlockComponent} from './block.component';
3 3 import * as helpers from "../../../spec/helpers";
4 4 import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper';
  5 +import {DesignModeService} from '../../admin/layout-edit/designMode.service';
5 6  
6 7 const htmlTemplate: string = '<noosfero-block [block]="ctrl.block" [owner]="ctrl.profile"></noosfero-block>';
7 8  
... ... @@ -32,16 +33,17 @@ describe(&quot;Boxes Component&quot;, () =&gt; {
32 33 helpers.createProviderToValue('TranslatorService', translatorService),
33 34 helpers.createProviderToValue('$uibModal', helpers.mocks.$modal),
34 35 helpers.createProviderToValue('BlockService', blockService),
35   - helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService)
  36 + helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService),
  37 + helpers.createProviderToValue('DesignModeService', helpers.mocks.designModeService)
36 38 ]
37 39 });
38 40 helper = new ComponentTestHelper<BlockComponent>(cls, done);
39 41 });
40   -
41 42 let translatorService = jasmine.createSpyObj("translatorService", ["currentLanguage"]);
42 43 let blockService = jasmine.createSpyObj("blockService", ["update"]);
43 44 let state = jasmine.createSpyObj("state", ["current"]);
44 45 state.current = { name: "" };
  46 +
45 47  
46 48 it("set isHomepage as false by default", () => {
47 49 expect(helper.component.isHomepage).toBeFalsy();
... ...
src/app/layout/blocks/block.component.ts
... ... @@ -11,7 +11,8 @@ import { DesignModeService } from &quot;../../admin/layout-edit/designMode.service&quot;;
11 11 templateUrl: 'app/layout/blocks/block.html',
12 12 directives: [BlockEditionComponent]
13 13 })
14   -@Inject("$uibModal", "$scope", "$state", "$rootScope", BlockService, NotificationService, AuthService, SessionService, TranslatorService, DesignModeService)
  14 +@Inject("$uibModal", "$scope", "$state", "$rootScope", BlockService, NotificationService,
  15 +AuthService, SessionService, TranslatorService, DesignModeService)
15 16 export class BlockComponent {
16 17  
17 18 @Input() block: noosfero.Block;
... ...
src/app/layout/navbar/navbar.spec.ts
... ... @@ -9,6 +9,8 @@ import {SessionService, AuthService, AuthController, AuthEvents} from &quot;./../../l
9 9  
10 10 import events from 'ng-forward/cjs/events/events';
11 11  
  12 +import {DesignModeService} from '../../admin/layout-edit/designMode.service';
  13 +
12 14 describe("Components", () => {
13 15  
14 16 describe("Navbar Component", () => {
... ... @@ -22,6 +24,7 @@ describe(&quot;Components&quot;, () =&gt; {
22 24 let authService: any;
23 25 let stateService: any;
24 26 let sessionService: SessionService;
  27 + let designModeService: DesignModeService;
25 28  
26 29 let provideFunc = provide;
27 30  
... ... @@ -37,6 +40,7 @@ describe(&quot;Components&quot;, () =&gt; {
37 40 authService = helpers.mocks.authService;
38 41 stateService = jasmine.createSpyObj("$state", ["go"]);
39 42 sessionService = <any>helpers.mocks.sessionWithCurrentUser(user);
  43 + designModeService = helpers.mocks.designModeService;
40 44 });
41 45  
42 46  
... ... @@ -76,6 +80,9 @@ describe(&quot;Components&quot;, () =&gt; {
76 80 }),
77 81 provide('TranslatorService', {
78 82 useValue: helpers.mocks.translatorService
  83 + }),
  84 + provide('DesignModeService', {
  85 + useValue: helpers.mocks.designModeService
79 86 })
80 87 ].concat(helpers.provideFilters("translateFilter")),
81 88 directives: [Navbar],
... ...
src/app/layout/services/body-state-classes.service.spec.ts
... ... @@ -5,11 +5,13 @@ import {AuthEvents} from &quot;./../../login/auth-events&quot;;
5 5  
6 6 import {EventEmitter} from 'ng-forward';
7 7 import {DesignModeService} from './../../admin/layout-edit/designMode.service';
  8 +import {INoosferoLocalStorage} from "./../../shared/models/interfaces";
8 9  
9 10 describe("BodyStateClasses Service", () => {
10 11  
11 12 let currentStateName = "main";
12 13 let bodyStateClasseService: BodyStateClassesService;
  14 + let $localStorage = <INoosferoLocalStorage>{ currentUser: null, settings: { designMode: false } };
13 15 let $rootScope: ng.IRootScopeService = <any>{},
14 16 $document: ng.IDocumentService = <any>{},
15 17 $state: ng.ui.IStateService = <any>{
... ... @@ -20,7 +22,8 @@ describe(&quot;BodyStateClasses Service&quot;, () =&gt; {
20 22 authService: any = helpers.mocks.authService,
21 23 bodyEl: { className: string },
22 24 bodyElJq: any,
23   - designModeService = new DesignModeService();
  25 +
  26 + designModeService = new DesignModeService($localStorage);
24 27  
25 28  
26 29  
... ...
src/app/login/session.service.spec.ts
... ... @@ -13,7 +13,7 @@ describe(&quot;Services&quot;, () =&gt; {
13 13 let $log: any;
14 14  
15 15 beforeEach(() => {
16   - $localStorage = <INoosferoLocalStorage>{ currentUser: null };
  16 + $localStorage = <INoosferoLocalStorage>{ currentUser: null, settings: null };
17 17 $log = jasmine.createSpyObj('$log', ['debug']);
18 18 });
19 19  
... ...
src/app/profile/custom-content/custom-content.component.spec.ts
1 1 import {CustomContentComponent} from './custom-content.component';
2 2 import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper';
3 3 import * as helpers from "../../../spec/helpers";
  4 +import {DesignModeService} from '../../admin/layout-edit/designMode.service';
4 5  
5 6 const htmlTemplate: string = '<custom-content [attribute]="\'custom_footer\'" [profile]="ctrl.profile"></custom-content>';
6 7  
... ... @@ -22,7 +23,8 @@ describe(&quot;Components&quot;, () =&gt; {
22 23 providers: [
23 24 helpers.createProviderToValue("$uibModal", helpers.mocks.$modal),
24 25 helpers.createProviderToValue("ProfileService", profileService),
25   - helpers.createProviderToValue("NotificationService", notificationService)
  26 + helpers.createProviderToValue("NotificationService", notificationService),
  27 + helpers.createProviderToValue("DesignModeService", helpers.mocks.designModeService)
26 28 ]
27 29 });
28 30 helper = new ComponentTestHelper<CustomContentComponent>(cls, done);
... ...
src/spec/mocks.ts
... ... @@ -193,6 +193,17 @@ export var mocks: any = {
193 193 currentUser: () => { return user; }
194 194 };
195 195 },
  196 + designModeService: {
  197 + modeFn: null,
  198 + onToggle: {
  199 + subscribe: (fn: Function) => {
  200 + mocks.designModeService.modeFn = fn;
  201 + },
  202 + next: (param: any) => {
  203 + mocks.designModeService.modeFn(param);
  204 + }
  205 + }
  206 + },
196 207 $translate: {
197 208 use: (lang?: string) => {
198 209 return lang ? Promise.resolve(lang) : "en";
... ...