54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
import './index';
|
|
import watcher from 'core/mocks/watcher';
|
|
|
|
describe('Client', () => {
|
|
describe('Component vnClientAddressCreate', () => {
|
|
let controller;
|
|
let $componentController;
|
|
let $state;
|
|
|
|
beforeEach(ngModule('client'));
|
|
|
|
beforeEach(angular.mock.inject((_$componentController_, _$state_) => {
|
|
$componentController = _$componentController_;
|
|
$state = _$state_;
|
|
$state.params.id = '1234';
|
|
controller = $componentController('vnClientAddressCreate', {$state});
|
|
controller.$scope.watcher = watcher;
|
|
controller.$scope.watcher.submit = () => {
|
|
return {
|
|
then: callback => {
|
|
callback({data: {id: 124}});
|
|
}
|
|
};
|
|
};
|
|
controller.client = {id: 101, defaultAddressFk: 121};
|
|
}));
|
|
|
|
it('should define and set address property', () => {
|
|
expect(controller.data.address.clientFk).toBe(1234);
|
|
expect(controller.data.address.isActive).toBe(true);
|
|
});
|
|
|
|
describe('onSubmit()', () => {
|
|
it('should perform a PATCH and not set value to defaultAddressFk property', () => {
|
|
spyOn(controller.$state, 'go');
|
|
controller.data.isDefaultAddress = false;
|
|
controller.onSubmit();
|
|
|
|
expect(controller.client.defaultAddressFk).toEqual(121);
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
|
|
});
|
|
|
|
it('should perform a PATCH and set a value to defaultAddressFk property', () => {
|
|
spyOn(controller.$state, 'go');
|
|
controller.data.isDefaultAddress = true;
|
|
controller.onSubmit();
|
|
|
|
expect(controller.client.defaultAddressFk).toEqual(124);
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
|
|
});
|
|
});
|
|
});
|
|
});
|