add frontTest

This commit is contained in:
Vicent Llopis 2022-03-17 14:51:49 +01:00
parent a32f7b5ef1
commit bc65beaa76
2 changed files with 42 additions and 79 deletions

View File

@ -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('<vn-supplier-address-create></vn-supplier-address-create>');
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('<vn-supplier-agency-term-create></vn-supplier-agency-term-create>');
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');
});
});
});

View File

@ -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('<vn-supplier-agency-term-index></vn-supplier-agency-term-index>');
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();
});
});
});
});