From 337b4114f0076a710f4657832b6764efcd257645 Mon Sep 17 00:00:00 2001 From: Joan Date: Thu, 9 Aug 2018 14:42:02 +0200 Subject: [PATCH] address & ticket card front unit tests --- client/client/src/address/index/index.spec.js | 42 ++++++++++++ client/ticket/src/card/index.spec.js | 64 +++++++++++++++++++ client/ticket/src/data/step-one/index.spec.js | 4 +- client/ticket/src/expedition/index.spec.js | 42 ++++++++++++ 4 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 client/client/src/address/index/index.spec.js create mode 100644 client/ticket/src/card/index.spec.js create mode 100644 client/ticket/src/expedition/index.spec.js diff --git a/client/client/src/address/index/index.spec.js b/client/client/src/address/index/index.spec.js new file mode 100644 index 000000000..02ad270ab --- /dev/null +++ b/client/client/src/address/index/index.spec.js @@ -0,0 +1,42 @@ +import './index'; + +describe('Client', () => { + describe('Component vnClientAddressIndex', () => { + let $componentController; + let controller; + let $scope; + let $state; + let $httpBackend; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_, _$httpBackend_) => { + $componentController = _$componentController_; + $state = _$state_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + $scope = $rootScope.$new(); + $scope.model = { + refresh: () => {} + }; + controller = $componentController('vnClientAddressIndex', {$state: $state}, {$scope: $scope}); + })); + + describe('setDefault()', () => { + it('should perform a PATCH if the address is active and call the refresh method', () => { + spyOn($scope.model, 'refresh'); + + let address = {id: 1, isActive: true}; + + $httpBackend.when('PATCH', `/client/api/Addresses/1`).respond(200); + $httpBackend.expect('PATCH', `/client/api/Addresses/1`); + controller.setDefault(address); + $httpBackend.flush(); + + expect($scope.model.refresh).toHaveBeenCalledWith(); + }); + }); + }); +}); diff --git a/client/ticket/src/card/index.spec.js b/client/ticket/src/card/index.spec.js new file mode 100644 index 000000000..57219a03e --- /dev/null +++ b/client/ticket/src/card/index.spec.js @@ -0,0 +1,64 @@ +import './index'; + +describe('Ticket', () => { + describe('Component vnTicketCard', () => { + let $componentController; + let controller; + let $state; + let $httpBackend; + + beforeEach(() => { + angular.mock.module('ticket'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => { + $componentController = _$componentController_; + $state = _$state_; + $state.params.id = 1; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + controller = $componentController('vnTicketCard', {$state: $state}); + })); + + describe('getTicket()', () => { + it('should perform a GET query and define the ticket property on controller', () => { + let filter = { + include: [ + {relation: 'warehouse', scope: {fields: ['name']}}, + {relation: 'agencyMode', scope: {fields: ['name']}}, + { + relation: 'client', + scope: { + fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'], + include: { + relation: 'salesPerson', + fields: ['firstName', 'name'] + } + } + }, + { + relation: 'tracking', + scope: { + fields: ['stateFk'], + include: { + relation: 'state', + fields: ['name'] + } + } + } + ] + }; + + filter = encodeURIComponent(JSON.stringify(filter)); + + $httpBackend.when('GET', `/ticket/api/Tickets/1?filter=${filter}`).respond({id: 1}); + $httpBackend.expect('GET', `/ticket/api/Tickets/1?filter=${filter}`); + controller.getTicket(); + $httpBackend.flush(); + + expect(controller.ticket).toBeDefined(); + expect(controller.ticket.id).toEqual(1); + }); + }); + }); +}); diff --git a/client/ticket/src/data/step-one/index.spec.js b/client/ticket/src/data/step-one/index.spec.js index b47494a6b..a48eb64a9 100644 --- a/client/ticket/src/data/step-one/index.spec.js +++ b/client/ticket/src/data/step-one/index.spec.js @@ -1,6 +1,6 @@ import './index.js'; -describe('ticket', () => { +describe('Ticket', () => { describe('Component vnTicketDataStepOne', () => { let $componentController; let $state; @@ -20,7 +20,7 @@ describe('ticket', () => { })); describe('ticket() setter', () => { - it('should set ticket property and call onChangeAddress() method ', () => { + it('should set ticket property and call onChangeAddress() method', () => { spyOn(controller, 'onChangeAddress'); controller.ticket = {id: 1, clientFk: 101}; diff --git a/client/ticket/src/expedition/index.spec.js b/client/ticket/src/expedition/index.spec.js new file mode 100644 index 000000000..eb8608e9f --- /dev/null +++ b/client/ticket/src/expedition/index.spec.js @@ -0,0 +1,42 @@ +import './index'; + +describe('Ticket', () => { + describe('Component vnTicketExpedition', () => { + let $componentController; + let controller; + let $scope; + let $state; + let $httpBackend; + + beforeEach(() => { + angular.mock.module('ticket'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_, _$httpBackend_) => { + $componentController = _$componentController_; + $state = _$state_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + $scope = $rootScope.$new(); + $scope.model = { + refresh: () => {} + }; + controller = $componentController('vnTicketExpedition', {$state: $state}, {$scope: $scope}); + })); + + describe('deleteExpedition()', () => { + it('should perform a DELETE query', () => { + spyOn($scope.model, 'refresh'); + + let expedition = {id: 1}; + + $httpBackend.when('DELETE', `/ticket/api/Expeditions/1`).respond(200); + $httpBackend.expect('DELETE', `/ticket/api/Expeditions/1`); + controller.deleteExpedition(expedition); + $httpBackend.flush(); + + expect($scope.model.refresh).toHaveBeenCalledWith(); + }); + }); + }); +});