2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2017-08-31 17:15:17 +00:00
|
|
|
|
2017-09-04 13:06:43 +00:00
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientCreate', () => {
|
|
|
|
let $scope;
|
|
|
|
let $state;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2017-08-31 17:15:17 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2017-08-31 17:15:17 +00:00
|
|
|
|
2020-03-20 11:00:53 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$state_) => {
|
2017-09-04 13:06:43 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$state = _$state_;
|
|
|
|
$scope.watcher = {
|
|
|
|
submit: () => {
|
|
|
|
return {
|
|
|
|
then: callback => {
|
|
|
|
callback({data: {id: '1234'}});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2020-03-17 10:17:50 +00:00
|
|
|
const $element = angular.element('<vn-client-create></vn-client-create>');
|
|
|
|
controller = $componentController('vnClientCreate', {$element, $scope});
|
2017-09-04 13:06:43 +00:00
|
|
|
}));
|
2017-08-31 17:15:17 +00:00
|
|
|
|
2017-09-04 13:06:43 +00:00
|
|
|
it('should define and set scope, state and client properties', () => {
|
|
|
|
expect(controller.$).toBe($scope);
|
|
|
|
expect(controller.$state).toBe($state);
|
|
|
|
expect(controller.client.active).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it(`should call submit() on the watcher then expect a callback`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn($state, 'go');
|
2017-09-04 13:06:43 +00:00
|
|
|
controller.onSubmit();
|
2017-09-20 12:01:33 +00:00
|
|
|
|
2018-05-23 12:26:51 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.basicData', {id: '1234'});
|
2017-09-04 13:06:43 +00:00
|
|
|
});
|
2017-09-04 10:46:19 +00:00
|
|
|
});
|
2019-07-08 12:07:09 +00:00
|
|
|
|
2020-03-03 14:03:54 +00:00
|
|
|
describe('province() setter', () => {
|
|
|
|
it(`should set countryFk property`, () => {
|
2020-05-21 09:14:34 +00:00
|
|
|
controller.client.countryFk = null;
|
2020-03-03 14:03:54 +00:00
|
|
|
controller.province = {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.client.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.client.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.client.provinceFk).toEqual(1);
|
|
|
|
expect(controller.client.postcode).toEqual('46001');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('postcode() setter', () => {
|
|
|
|
it(`should set the town, provinceFk and contryFk properties`, () => {
|
|
|
|
controller.postcode = {
|
2019-07-08 12:07:09 +00:00
|
|
|
townFk: 1,
|
|
|
|
code: 46001,
|
|
|
|
town: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New York',
|
|
|
|
province: {
|
|
|
|
id: 1,
|
|
|
|
name: 'New york',
|
|
|
|
country: {
|
|
|
|
id: 2,
|
|
|
|
name: 'USA'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.client.city).toEqual('New York');
|
|
|
|
expect(controller.client.provinceFk).toEqual(1);
|
|
|
|
expect(controller.client.countryFk).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
2017-08-31 17:15:17 +00:00
|
|
|
});
|
|
|
|
});
|