diff --git a/client/item/src/index/index.spec.js b/client/item/src/index/index.spec.js new file mode 100644 index 000000000..5da3ee154 --- /dev/null +++ b/client/item/src/index/index.spec.js @@ -0,0 +1,63 @@ +import './index.js'; + +describe('Item', () => { + describe('Component vnItemIndex', () => { + let $componentController; + let $state; + let controller; + let $httpBackend; + + beforeEach(() => { + angular.mock.module('item'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => { + $componentController = _$componentController_; + $state = _$state_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + controller = $componentController('vnItemIndex', {$state: $state}); + })); + + describe('onCloneAccept()', () => { + it('should do nothing if response is not ACCEPT', () => { + spyOn(controller.$state, 'go'); + + let response = 'ERROR!'; + controller.itemSelected = 'check me'; + + controller.onCloneAccept(response); + + expect(controller.$state.go).not.toHaveBeenCalledWith(); + expect(controller.itemSelected).toEqual('check me'); + }); + + it('should do nothing if response is ACCEPT but itemSelected is not defined in the controller', () => { + spyOn(controller.$state, 'go'); + + let response = 'ACCEPT'; + controller.itemSelected = undefined; + + controller.onCloneAccept(response); + + expect(controller.$state.go).not.toHaveBeenCalledWith(); + expect(controller.itemSelected).toBeUndefined(); + }); + + it('should perform a post query and then call go() then update itemSelected in the controller', () => { + spyOn(controller.$state, 'go'); + + let response = 'ACCEPT'; + controller.itemSelected = {id: 1}; + + $httpBackend.when('POST', `/item/api/Items/1/clone`).respond({id: 99}); + $httpBackend.expect('POST', `/item/api/Items/1/clone`); + controller.onCloneAccept(response); + $httpBackend.flush(); + + expect(controller.$state.go).toHaveBeenCalledWith('item.card.tags', {id: 99}); + expect(controller.itemSelected).toBeNull(); + }); + }); + }); +}); diff --git a/client/ticket/src/data/step-one/index.spec.js b/client/ticket/src/data/step-one/index.spec.js index 23d889bb9..41c407625 100644 --- a/client/ticket/src/data/step-one/index.spec.js +++ b/client/ticket/src/data/step-one/index.spec.js @@ -41,35 +41,39 @@ describe('Ticket', () => { describe('shipped() setter', () => { it('should set shipped property and call onChangeShipped() method ', () => { + let shipped = new Date(); spyOn(controller, 'onChangeShipped'); controller.ticket = {id: 1}; - controller.shipped = new Date(); + controller.shipped = shipped; - expect(controller.onChangeShipped).toHaveBeenCalledWith(new Date()); + expect(controller.onChangeShipped).toHaveBeenCalledWith(shipped); }); }); describe('landed() setter', () => { it('should set landed property and call onChangeLanded() method ', () => { + let landed = new Date(); spyOn(controller, 'onChangeLanded'); controller.ticket = {id: 1}; - controller.landed = new Date(); + controller.landed = landed; - expect(controller.onChangeLanded).toHaveBeenCalledWith(new Date()); + expect(controller.onChangeLanded).toHaveBeenCalledWith(landed); }); }); describe('onChangeShipped()', () => { it('should return an available landing date', async () => { + let shipped = new Date(); + controller._ticket = { id: 1, - shipped: new Date(), + shipped: shipped, addressFk: 121, agencyModeFk: 2, warehouseFk: 1 }; let data = { - shipped: toJsonDate(new Date()), + shipped: toJsonDate(shipped), addressFk: 121, agencyModeFk: 2, warehouseFk: 1 @@ -77,19 +81,20 @@ describe('Ticket', () => { $httpBackend.whenPOST(`/api/Tickets/getLanded`, data).respond(200); $httpBackend.expectPOST(`/api/Tickets/getLanded`, data); - controller.onChangeShipped(new Date()); + controller.onChangeShipped(shipped); $httpBackend.flush(); }); }); describe('onChangeLanded()', () => { it('should return an available shipment date', async () => { - controller._ticket = {id: 1, landed: new Date(), addressFk: 121, agencyModeFk: 2}; - let data = {landed: new Date(), addressFk: 121, agencyModeFk: 2}; + let landed = new Date(); + controller._ticket = {id: 1, landed: landed, addressFk: 121, agencyModeFk: 2}; + let data = {landed: landed, addressFk: 121, agencyModeFk: 2}; $httpBackend.whenPOST(`/api/Tickets/getShipped`, data).respond(200); $httpBackend.expectPOST(`/api/Tickets/getShipped`, data); - controller.onChangeLanded(new Date()); + controller.onChangeLanded(landed); $httpBackend.flush(); }); });