Commit 102c26aa50f07efb88574e606955da91bd8107c5
1 parent
55ee9557
Exists in
master
and in
1 other branch
Add tests to cms component
Showing
2 changed files
with
54 additions
and
1 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | +import {quickCreateComponent} from "../../spec/helpers"; | |
| 2 | +import {Cms} from "./cms.component"; | |
| 3 | + | |
| 4 | +describe("Components", () => { | |
| 5 | + describe("Cms Component", () => { | |
| 6 | + | |
| 7 | + let $rootScope: ng.IRootScopeService; | |
| 8 | + let $q: ng.IQService; | |
| 9 | + let articleServiceMock: any; | |
| 10 | + let profileServiceMock: any; | |
| 11 | + let $state: any; | |
| 12 | + let sweetAlert: any; | |
| 13 | + | |
| 14 | + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { | |
| 15 | + $rootScope = _$rootScope_; | |
| 16 | + $q = _$q_; | |
| 17 | + })); | |
| 18 | + | |
| 19 | + beforeEach(() => { | |
| 20 | + $state = jasmine.createSpyObj("$state", ["transitionTo"]); | |
| 21 | + sweetAlert = jasmine.createSpyObj("SweetAlert", ["swal"]); | |
| 22 | + profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile"]); | |
| 23 | + articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["create"]); | |
| 24 | + | |
| 25 | + let getCurrentProfileResponse = $q.defer(); | |
| 26 | + getCurrentProfileResponse.resolve({ id: 1 }); | |
| 27 | + | |
| 28 | + let articleCreate = $q.defer(); | |
| 29 | + articleCreate.resolve({ data: { article: { path: "path", profile: { identifier: "profile" } } } }); | |
| 30 | + | |
| 31 | + profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise); | |
| 32 | + articleServiceMock.create = jasmine.createSpy("create").and.returnValue(articleCreate.promise); | |
| 33 | + }); | |
| 34 | + | |
| 35 | + it("create an article in the current profile when save", done => { | |
| 36 | + let component: Cms = new Cms(articleServiceMock, profileServiceMock, $state, sweetAlert); | |
| 37 | + component.save(); | |
| 38 | + $rootScope.$apply(); | |
| 39 | + expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); | |
| 40 | + expect(articleServiceMock.create).toHaveBeenCalledWith(1, component.article); | |
| 41 | + done(); | |
| 42 | + }); | |
| 43 | + | |
| 44 | + it("got to the new article page and display an alert when saving sucessfully", done => { | |
| 45 | + let component: Cms = new Cms(articleServiceMock, profileServiceMock, $state, sweetAlert); | |
| 46 | + component.save(); | |
| 47 | + $rootScope.$apply(); | |
| 48 | + expect($state.transitionTo).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "profile" }); | |
| 49 | + expect(sweetAlert.swal).toHaveBeenCalled(); | |
| 50 | + done(); | |
| 51 | + }); | |
| 52 | + | |
| 53 | + }); | |
| 54 | +}); | ... | ... |
src/app/cms/cms.component.ts
| ... | ... | @@ -15,7 +15,6 @@ import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; |
| 15 | 15 | export class Cms { |
| 16 | 16 | |
| 17 | 17 | article: any = {}; |
| 18 | - profile: any; | |
| 19 | 18 | |
| 20 | 19 | constructor(private articleService: ArticleService, |
| 21 | 20 | private profileService: ProfileService, | ... | ... |