123 lines
4.0 KiB
JavaScript
123 lines
4.0 KiB
JavaScript
|
import './index';
|
||
|
|
||
|
describe('Client', () => {
|
||
|
describe('Component vnClientCreate', () => {
|
||
|
let $scope;
|
||
|
let $state;
|
||
|
let controller;
|
||
|
|
||
|
beforeEach(ngModule('client'));
|
||
|
|
||
|
beforeEach(inject(($componentController, $rootScope, _$state_) => {
|
||
|
$scope = $rootScope.$new();
|
||
|
$state = _$state_;
|
||
|
$scope.watcher = {
|
||
|
submit: () => {
|
||
|
return {
|
||
|
then: callback => {
|
||
|
callback({data: {id: '1234'}});
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
const $element = angular.element('<vn-client-create></vn-client-create>');
|
||
|
controller = $componentController('vnClientCreate', {$element, $scope});
|
||
|
}));
|
||
|
|
||
|
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`, () => {
|
||
|
jest.spyOn($state, 'go');
|
||
|
controller.onSubmit();
|
||
|
|
||
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.basicData', {id: '1234'});
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('province() setter', () => {
|
||
|
it(`should set countryFk property`, () => {
|
||
|
controller.client.countryFk = null;
|
||
|
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 = {
|
||
|
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);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|