From d24058bab10ccc45fc3c06077ad5961d6af69593 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Mon, 5 Feb 2018 16:53:41 +0100 Subject: [PATCH] front unit tests for item card, item create and started over production index --- client/item/src/card/item-card.spec.js | 33 ++++++++++++ client/item/src/create/item-create.spec.js | 46 ++++++++++++++++ client/production/src/index/index.js | 63 ++++++++++------------ client/production/src/index/index.spec.js | 39 ++++++++++++++ 4 files changed, 147 insertions(+), 34 deletions(-) create mode 100644 client/item/src/card/item-card.spec.js create mode 100644 client/item/src/create/item-create.spec.js create mode 100644 client/production/src/index/index.spec.js diff --git a/client/item/src/card/item-card.spec.js b/client/item/src/card/item-card.spec.js new file mode 100644 index 000000000..5447d007e --- /dev/null +++ b/client/item/src/card/item-card.spec.js @@ -0,0 +1,33 @@ +import './item-card.js'; + +describe('Item', () => { + describe('Component vnItemCard', () => { + let $componentController; + let $httpBackend; + let $state; + let controller; + + beforeEach(() => { + angular.mock.module('item'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => { + $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + $state = _$state_; + controller = $componentController('vnItemCard', {$state: $state}); + })); + + describe('$onInit()', () => { + it('should request to patch the propagation of tax status', () => { + controller.client = {id: 123, isEqualizated: false}; + $httpBackend.whenGET('/item/api/Items/undefined?filter={"include":[{"relation":"itemType"},{"relation":"origin"},{"relation":"ink"},{"relation":"producer"},{"relation":"intrastat"},{"relation":"expence"},{"relation":"taxClass"},{"relation":"itemTag","scope":{"order":"priority ASC","include":{"relation":"tag"}}}]}').respond({data: 'item'}); + $httpBackend.expectGET('/item/api/Items/undefined?filter={"include":[{"relation":"itemType"},{"relation":"origin"},{"relation":"ink"},{"relation":"producer"},{"relation":"intrastat"},{"relation":"expence"},{"relation":"taxClass"},{"relation":"itemTag","scope":{"order":"priority ASC","include":{"relation":"tag"}}}]}'); + controller.$onInit(); + $httpBackend.flush(); + + expect(controller.item).toEqual({data: 'item'}); + }); + }); + }); +}); diff --git a/client/item/src/create/item-create.spec.js b/client/item/src/create/item-create.spec.js new file mode 100644 index 000000000..bff09cad5 --- /dev/null +++ b/client/item/src/create/item-create.spec.js @@ -0,0 +1,46 @@ +import './item-create.js'; + +describe('Item', () => { + describe('Component vnItemCreate', () => { + let $componentController; + let $scope; + let $state; + let controller; + + beforeEach(() => { + angular.mock.module('item'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => { + $componentController = _$componentController_; + $scope = $rootScope.$new(); + $state = _$state_; + $scope.watcher = { + submit: () => { + return { + then: callback => { + callback({data: {id: 1}}); + } + }; + } + }; + controller = $componentController('vnItemCreate', {$scope: $scope}); + })); + + it('should define and set scope, state and item properties', () => { + expect(controller.$).toEqual($scope); + expect(controller.$state).toEqual($state); + expect(controller.item).toEqual({relevancy: 0}); + }); + + describe('onSubmit()', () => { + it(`should call submit() on the watcher then expect a callback`, () => { + spyOn($state, 'go'); + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('item.card.data', {id: 1}); + }); + }); + }); +}); + diff --git a/client/production/src/index/index.js b/client/production/src/index/index.js index 48aa3f9ae..bf111e9f0 100644 --- a/client/production/src/index/index.js +++ b/client/production/src/index/index.js @@ -8,7 +8,7 @@ export default class ProductionIndex { this.$http = $http; this.filter = {}; this.tickets = []; - + this.checkAll = 0; this.footer = { total: null, @@ -35,58 +35,53 @@ export default class ProductionIndex { } // Actions Callbacks - _changeState(ids, sateteId, stateName, index) { - this.$http.put(`/production/api/TicketStates/${sateteId}/changeState`, {tickets: ids}).then( - () => { - index.forEach( - val => { - this.tickets[val].state = stateName; - this.tickets[val].stateFk = sateteId; - } - ); - } - ); + + _changeState(ids, stateId, stateName, index) { + this.$http.put(`/production/api/TicketStates/${stateId}/changeState`, {tickets: ids}).then(() => { + index.forEach(val => { + this.tickets[val].state = stateName; + this.tickets[val].stateFk = stateId; + }); + }); } + _sendMessage(tickets) { - this.$http.post(`/production/api/FakeProductions/messageSend`, {tickets: tickets}).then( - () => { - this.vnApp.showMessage(this.$translate.instant('Success: message send!')); - } - ); + this.$http.post(`/production/api/FakeProductions/messageSend`, {tickets: tickets}).then(() => { + this.vnApp.showMessage(this.$translate.instant('Success: message send!')); + }); } + _changeTime(ids, time, index) { - this.$http.put(`/production/api/Tickets/${time}/changeTime`, {tickets: ids}).then( - () => { - index.forEach( - val => { - this.tickets[val].hour = time; - } - ); - } - ); + this.$http.put(`/production/api/Tickets/${time}/changeTime`, {tickets: ids}).then(() => { + index.forEach(val => { + this.tickets[val].hour = time; + }); + }); } + searchTickets(filter) { this.$.index.filter.filter = Object.assign({}, this.filter, filter || {}); this.checkAll = 0; - this.$.index.accept().then( - json => { - this.tickets = json.tickets; - this.footer.lines = json.lines; - this.footer.meters = json.m3; - this.footer.total = json.total; - } - ); + this.$.index.accept().then(json => { + this.tickets = json.tickets; + this.footer.lines = json.lines; + this.footer.meters = json.m3; + this.footer.total = json.total; + }); } + refreshTickets() { this.filter = {}; this.filter.warehouseFk = this.$.displayValue = this.userProfile.warehouseId; } + onChangeWareHouse(warehouse) { if (warehouse && warehouse != this.filter.warehouseFk) { this.filter.warehouseFk = warehouse; this.searchTickets(this.filter); } } + $onInit() { for (let i = 1; i <= 24; i++) { let hour = [i].join(''); diff --git a/client/production/src/index/index.spec.js b/client/production/src/index/index.spec.js new file mode 100644 index 000000000..deb9eedaf --- /dev/null +++ b/client/production/src/index/index.spec.js @@ -0,0 +1,39 @@ +import './index.js'; + +describe('Production', () => { + describe('Component vnProductionIndex', () => { + let $componentController; + let $httpBackend; + let $scope; + let controller; + let $element; + let aclConstant; + + beforeEach(() => { + angular.mock.module('production'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => { + $element = angular.element('
'); + $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + $scope = $rootScope.$new(); + aclConstant = {userProfile: {warehouseId: 1}}; + controller = $componentController('vnProductionIndex', {$scope: $scope, $element: $element, aclConstant: aclConstant}); + })); + + describe('_changeState()', () => { + it('should request to update the ticket state', () => { + let ids = [1, 2, 3, 4]; + let stateId = 1; + let stateName = 'the state!'; + let index = []; + controller.tickets = ['ticketVal']; + $httpBackend.whenPUT('/production/api/TicketStates/1/changeState', {tickets: ids}).respond({data: 'ticketVal'}); + $httpBackend.expectPUT('/production/api/TicketStates/1/changeState', {tickets: ids}); + controller._changeState(ids, stateId, stateName, index); + $httpBackend.flush(); + }); + }); + }); +});