From 102c26aa50f07efb88574e606955da91bd8107c5 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 8 Mar 2016 17:36:32 -0300 Subject: [PATCH] Add tests to cms component --- src/app/cms/cms.component.spec.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/app/cms/cms.component.ts | 1 - 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/app/cms/cms.component.spec.ts diff --git a/src/app/cms/cms.component.spec.ts b/src/app/cms/cms.component.spec.ts new file mode 100644 index 0000000..605bf91 --- /dev/null +++ b/src/app/cms/cms.component.spec.ts @@ -0,0 +1,54 @@ +import {quickCreateComponent} from "../../spec/helpers"; +import {Cms} from "./cms.component"; + +describe("Components", () => { + describe("Cms Component", () => { + + let $rootScope: ng.IRootScopeService; + let $q: ng.IQService; + let articleServiceMock: any; + let profileServiceMock: any; + let $state: any; + let sweetAlert: any; + + beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => { + $rootScope = _$rootScope_; + $q = _$q_; + })); + + beforeEach(() => { + $state = jasmine.createSpyObj("$state", ["transitionTo"]); + sweetAlert = jasmine.createSpyObj("SweetAlert", ["swal"]); + profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile"]); + articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["create"]); + + let getCurrentProfileResponse = $q.defer(); + getCurrentProfileResponse.resolve({ id: 1 }); + + let articleCreate = $q.defer(); + articleCreate.resolve({ data: { article: { path: "path", profile: { identifier: "profile" } } } }); + + profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise); + articleServiceMock.create = jasmine.createSpy("create").and.returnValue(articleCreate.promise); + }); + + it("create an article in the current profile when save", done => { + let component: Cms = new Cms(articleServiceMock, profileServiceMock, $state, sweetAlert); + component.save(); + $rootScope.$apply(); + expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); + expect(articleServiceMock.create).toHaveBeenCalledWith(1, component.article); + done(); + }); + + it("got to the new article page and display an alert when saving sucessfully", done => { + let component: Cms = new Cms(articleServiceMock, profileServiceMock, $state, sweetAlert); + component.save(); + $rootScope.$apply(); + expect($state.transitionTo).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "profile" }); + expect(sweetAlert.swal).toHaveBeenCalled(); + done(); + }); + + }); +}); diff --git a/src/app/cms/cms.component.ts b/src/app/cms/cms.component.ts index 9f2a9e6..4dad48b 100644 --- a/src/app/cms/cms.component.ts +++ b/src/app/cms/cms.component.ts @@ -15,7 +15,6 @@ import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; export class Cms { article: any = {}; - profile: any; constructor(private articleService: ArticleService, private profileService: ProfileService, -- libgit2 0.21.2