2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2017-08-31 06:53:17 +00:00
|
|
|
|
2017-09-04 13:06:43 +00:00
|
|
|
describe('Client', () => {
|
2018-05-24 13:02:38 +00:00
|
|
|
describe('Component vnClientAddressEdit', () => {
|
2017-09-04 13:06:43 +00:00
|
|
|
let $state;
|
2018-08-21 12:13:11 +00:00
|
|
|
let controller;
|
2017-08-31 06:53:17 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2017-08-31 06:53:17 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_) => {
|
2017-09-04 13:06:43 +00:00
|
|
|
$state = _$state_;
|
2018-02-06 14:09:31 +00:00
|
|
|
$state.params.addressId = '1';
|
2018-12-22 10:59:26 +00:00
|
|
|
controller = $componentController('vnClientAddressEdit', {$state});
|
2018-08-21 12:13:11 +00:00
|
|
|
controller.$.watcher = {
|
|
|
|
setDirty: () => {},
|
|
|
|
setPristine: () => {},
|
|
|
|
realSubmit: () => {},
|
|
|
|
check: () => {},
|
|
|
|
notifySaved: () => {}
|
|
|
|
};
|
|
|
|
controller.$.model = {
|
|
|
|
remove: () => {},
|
|
|
|
save: () => {}
|
|
|
|
};
|
|
|
|
controller.card = {
|
|
|
|
reload: () => {}
|
|
|
|
};
|
2017-09-04 13:06:43 +00:00
|
|
|
}));
|
2018-08-21 12:13:11 +00:00
|
|
|
|
|
|
|
describe('removeObservation()', () => {
|
|
|
|
it('should call $.watcher.setDirty() and $.model.remove(index)', () => {
|
|
|
|
spyOn(controller.$.watcher, 'setDirty');
|
|
|
|
spyOn(controller.$.model, 'remove');
|
|
|
|
controller.removeObservation(1);
|
|
|
|
|
|
|
|
expect(controller.$.model.remove).toHaveBeenCalledWith(1);
|
|
|
|
expect(controller.$.watcher.setDirty).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 07:28:38 +00:00
|
|
|
describe('cancel()', () => {
|
|
|
|
it('should call goToIndex()', () => {
|
2018-08-21 12:13:11 +00:00
|
|
|
spyOn(controller, 'goToIndex');
|
2018-10-17 07:28:38 +00:00
|
|
|
controller.cancel();
|
2018-08-21 12:13:11 +00:00
|
|
|
|
|
|
|
expect(controller.goToIndex).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('goToIndex()', () => {
|
|
|
|
it('should call $state.go("client.card.address.index")', () => {
|
|
|
|
spyOn(controller.$state, 'go');
|
|
|
|
controller.goToIndex();
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
|
2018-08-21 12:13:11 +00:00
|
|
|
});
|
|
|
|
});
|
2019-07-08 12:07:09 +00:00
|
|
|
|
|
|
|
describe('postcodeSelection() setter', () => {
|
|
|
|
it(`should set the town, province and contry properties`, () => {
|
|
|
|
controller.address = {};
|
2019-07-17 05:39:08 +00:00
|
|
|
controller._postcodeSelection = {townFk: 2};
|
2019-07-08 12:07:09 +00:00
|
|
|
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.address.city).toEqual('New York');
|
|
|
|
expect(controller.address.provinceFk).toEqual(1);
|
|
|
|
expect(controller.address.countryFk).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
2017-08-31 06:53:17 +00:00
|
|
|
});
|
|
|
|
});
|