71 lines
2.4 KiB
JavaScript
71 lines
2.4 KiB
JavaScript
import './index';
|
|
|
|
describe('Client', () => {
|
|
describe('Component vnClientCreate', () => {
|
|
let $componentController;
|
|
let $scope;
|
|
let $state;
|
|
let controller;
|
|
|
|
beforeEach(angular.mock.module('client', $translateProvider => {
|
|
$translateProvider.translations('en', {});
|
|
}));
|
|
|
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => {
|
|
$componentController = _$componentController_;
|
|
$scope = $rootScope.$new();
|
|
$state = _$state_;
|
|
$scope.watcher = {
|
|
submit: () => {
|
|
return {
|
|
then: callback => {
|
|
callback({data: {id: '1234'}});
|
|
}
|
|
};
|
|
}
|
|
};
|
|
controller = $componentController('vnClientCreate', {$scope: $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`, () => {
|
|
spyOn($state, 'go');
|
|
controller.onSubmit();
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.basicData', {id: '1234'});
|
|
});
|
|
});
|
|
|
|
describe('postcodeSelection() setter', () => {
|
|
it(`should set the town, province and contry properties`, () => {
|
|
controller.postcodeSelection = {
|
|
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);
|
|
});
|
|
});
|
|
});
|
|
});
|