From bc65beaa76af60172b6efe5c7bf639ad56bba3f5 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 17 Mar 2022 14:51:49 +0100 Subject: [PATCH] add frontTest --- .../front/agency-term/create/index.spec.js | 84 ++----------------- .../front/agency-term/index/index.spec.js | 37 ++++++++ 2 files changed, 42 insertions(+), 79 deletions(-) create mode 100644 modules/supplier/front/agency-term/index/index.spec.js diff --git a/modules/supplier/front/agency-term/create/index.spec.js b/modules/supplier/front/agency-term/create/index.spec.js index 026de37691..682e1cc582 100644 --- a/modules/supplier/front/agency-term/create/index.spec.js +++ b/modules/supplier/front/agency-term/create/index.spec.js @@ -6,96 +6,22 @@ describe('Supplier', () => { let $scope; let controller; let $element; - let $state; beforeEach(ngModule('supplier')); beforeEach(inject(($componentController, $rootScope, _$state_) => { $scope = $rootScope.$new(); - $state = _$state_; - $state.params.id = '1234'; - $element = angular.element(''); - controller = $componentController('vnSupplierAddressCreate', {$element, $scope}); - controller.$.watcher = watcher; - controller.$.watcher.submit = () => { - return { - then: callback => { - callback({data: {id: 124}}); - } - }; - }; - controller.supplier = {id: 1}; + $scope.watcher = watcher; + $element = angular.element(''); + controller = $componentController('vnSupplierAgencyTermCreate', {$element, $scope}); })); describe('onSubmit()', () => { - it('should perform a PATCH and then redirect to the main section', () => { + it(`should redirect to 'supplier.card.agencyTerm.index' state`, () => { jest.spyOn(controller.$state, 'go'); controller.onSubmit(); - expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.address.index'); - }); - }); - - describe('town() setter', () => { - it(`should set provinceFk property`, () => { - controller.town = { - provinceFk: 1, - code: 46001, - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - }, - postcodes: [] - }; - - expect(controller.address.provinceFk).toEqual(1); - }); - - it(`should set provinceFk property and fill the postalCode if there's just one`, () => { - controller.town = { - provinceFk: 1, - code: 46001, - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - }, - postcodes: [{code: '46001'}] - }; - - expect(controller.address.provinceFk).toEqual(1); - expect(controller.address.postalCode).toEqual('46001'); - }); - }); - - describe('postcode() setter', () => { - it(`should set the town and province properties`, () => { - controller.postcode = { - townFk: 1, - code: 46001, - town: { - id: 1, - name: 'New York', - province: { - id: 1, - name: 'New york', - country: { - id: 2, - name: 'USA' - } - } - } - }; - - expect(controller.address.city).toEqual('New York'); - expect(controller.address.provinceFk).toEqual(1); + expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.agencyTerm.index'); }); }); }); diff --git a/modules/supplier/front/agency-term/index/index.spec.js b/modules/supplier/front/agency-term/index/index.spec.js new file mode 100644 index 0000000000..3e9ea4c1e2 --- /dev/null +++ b/modules/supplier/front/agency-term/index/index.spec.js @@ -0,0 +1,37 @@ +import './index'; +import watcher from 'core/mocks/watcher'; +import crudModel from 'core/mocks/crud-model'; + +describe('Supplier', () => { + describe('Component vnSupplierAddressCreate', () => { + let $scope; + let controller; + let $element; + + beforeEach(ngModule('supplier')); + + beforeEach(inject(($componentController, $rootScope, _$state_) => { + $scope = $rootScope.$new(); + $scope.model = crudModel; + $scope.watcher = watcher; + $element = angular.element(''); + controller = $componentController('vnSupplierAgencyTermIndex', {$element, $scope}); + })); + + describe('onSubmit()', () => { + it('should make HTTP POST request to save values', () => { + jest.spyOn($scope.watcher, 'check'); + jest.spyOn($scope.watcher, 'notifySaved'); + jest.spyOn($scope.watcher, 'updateOriginalData'); + jest.spyOn($scope.model, 'save'); + + controller.onSubmit(); + + expect($scope.model.save).toHaveBeenCalledWith(); + expect($scope.watcher.updateOriginalData).toHaveBeenCalledWith(); + expect($scope.watcher.check).toHaveBeenCalledWith(); + expect($scope.watcher.notifySaved).toHaveBeenCalledWith(); + }); + }); + }); +});