salix/modules/supplier/front/fiscal-data/index.spec.js

110 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-10-30 14:11:45 +00:00
import './index';
import watcher from 'core/mocks/watcher';
describe('Supplier', () => {
describe('Component vnSupplierFiscalData', () => {
let $scope;
let $element;
let controller;
beforeEach(ngModule('supplier'));
2020-11-02 07:16:42 +00:00
beforeEach(inject(($componentController, $rootScope) => {
2020-10-30 14:11:45 +00:00
$scope = $rootScope.$new();
$scope.watcher = watcher;
2020-11-02 07:16:42 +00:00
$scope.watcher.orgData = {id: 1};
2020-10-30 14:11:45 +00:00
$element = angular.element('<vn-supplier-fiscal-data></supplier-fiscal-data>');
2020-11-02 07:16:42 +00:00
controller = $componentController('vnSupplierFiscalData', {$element, $scope});
2020-10-30 14:11:45 +00:00
controller.card = {reload: () => {}};
2020-11-02 07:16:42 +00:00
controller.supplier = {
id: 1,
name: 'Batman'
2020-10-30 14:11:45 +00:00
};
controller._province = {};
controller._town = {};
controller._postcode = {};
}));
describe('province() setter', () => {
it(`should set countryFk property`, () => {
2020-11-02 07:16:42 +00:00
controller.supplier.countryFk = null;
2020-10-30 14:11:45 +00:00
controller.province = {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
};
2020-11-02 07:16:42 +00:00
expect(controller.supplier.countryFk).toEqual(2);
2020-10-30 14:11:45 +00:00
});
});
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: []
};
2020-11-02 07:16:42 +00:00
expect(controller.supplier.provinceFk).toEqual(1);
2020-10-30 14:11:45 +00:00
});
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'}]
};
2020-11-02 07:16:42 +00:00
expect(controller.supplier.provinceFk).toEqual(1);
expect(controller.supplier.postCode).toEqual('46001');
2020-10-30 14:11:45 +00:00
});
});
describe('postcode() setter', () => {
it(`should set the town, provinceFk and contryFk properties`, () => {
controller.postcode = {
townFk: 1,
code: 46001,
town: {
id: 1,
name: 'New York',
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
}
}
};
2020-11-02 07:16:42 +00:00
expect(controller.supplier.city).toEqual('New York');
expect(controller.supplier.provinceFk).toEqual(1);
expect(controller.supplier.countryFk).toEqual(2);
2020-10-30 14:11:45 +00:00
});
});
});
});