From 86805769fe9afd45619f234e5da5b14d092ca65d Mon Sep 17 00:00:00 2001 From: gerard Date: Tue, 21 Aug 2018 13:13:51 +0200 Subject: [PATCH] Tarea #505 /summary/index.js Front unit test --- client/item/src/summary/index.spec.js | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 client/item/src/summary/index.spec.js diff --git a/client/item/src/summary/index.spec.js b/client/item/src/summary/index.spec.js new file mode 100644 index 000000000..92f374a78 --- /dev/null +++ b/client/item/src/summary/index.spec.js @@ -0,0 +1,41 @@ +import './index.js'; + +describe('Item', () => { + describe('Component summary', () => { + let $componentController; + let controller; + let $httpBackend; + + beforeEach(() => { + angular.mock.module('item'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { + $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + controller = $componentController('vnItemSummary'); + controller.item = {id: 1}; + })); + + describe('getSummary()', () => { + it("should perform a query to set summary", () => { + $httpBackend.when('GET', `/item/api/Items/1/getSummary`).respond(200, 24); + $httpBackend.expect('GET', `/item/api/Items/1/getSummary`); + controller.getSummary(); + $httpBackend.flush(); + + expect(controller.summary).toEqual(24); + }); + }); + + describe('$onChanges()', () => { + it("should call getSummary when item.id is defined", () => { + spyOn(controller, 'getSummary'); + controller.$onChanges(); + + expect(controller.getSummary).toHaveBeenCalledWith(); + }); + }); + }); +});