import './index'; import watcher from 'core/mocks/watcher'; describe('Supplier', () => { describe('Component vnSupplierFiscalData', () => { let $scope; let $element; let controller; beforeEach(ngModule('supplier')); beforeEach(inject(($componentController, $rootScope) => { $scope = $rootScope.$new(); $scope.watcher = watcher; $scope.watcher.orgData = {id: 1}; $element = angular.element(''); controller = $componentController('vnSupplierFiscalData', {$element, $scope}); controller.card = {reload: () => {}}; controller.supplier = { id: 1, name: 'Batman' }; controller._province = {}; controller._town = {}; controller._postcode = {}; })); describe('province() setter', () => { it(`should set countryFk property`, () => { controller.supplier.countryFk = null; controller.province = { id: 1, name: 'New york', country: { id: 2, name: 'USA' } }; expect(controller.supplier.countryFk).toEqual(2); }); }); 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.supplier.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.supplier.provinceFk).toEqual(1); expect(controller.supplier.postCode).toEqual('46001'); }); }); 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' } } } }; expect(controller.supplier.city).toEqual('New York'); expect(controller.supplier.provinceFk).toEqual(1); expect(controller.supplier.countryFk).toEqual(2); }); }); }); });