add frontTest
This commit is contained in:
parent
a32f7b5ef1
commit
bc65beaa76
|
@ -6,96 +6,22 @@ describe('Supplier', () => {
|
||||||
let $scope;
|
let $scope;
|
||||||
let controller;
|
let controller;
|
||||||
let $element;
|
let $element;
|
||||||
let $state;
|
|
||||||
|
|
||||||
beforeEach(ngModule('supplier'));
|
beforeEach(ngModule('supplier'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, $rootScope, _$state_) => {
|
beforeEach(inject(($componentController, $rootScope, _$state_) => {
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$state = _$state_;
|
$scope.watcher = watcher;
|
||||||
$state.params.id = '1234';
|
$element = angular.element('<vn-supplier-agency-term-create></vn-supplier-agency-term-create>');
|
||||||
$element = angular.element('<vn-supplier-address-create></vn-supplier-address-create>');
|
controller = $componentController('vnSupplierAgencyTermCreate', {$element, $scope});
|
||||||
controller = $componentController('vnSupplierAddressCreate', {$element, $scope});
|
|
||||||
controller.$.watcher = watcher;
|
|
||||||
controller.$.watcher.submit = () => {
|
|
||||||
return {
|
|
||||||
then: callback => {
|
|
||||||
callback({data: {id: 124}});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
controller.supplier = {id: 1};
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('onSubmit()', () => {
|
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');
|
jest.spyOn(controller.$state, 'go');
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
|
|
||||||
expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.address.index');
|
expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.agencyTerm.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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue