87 lines
2.9 KiB
JavaScript
87 lines
2.9 KiB
JavaScript
import './index';
|
|
|
|
describe('Client', () => {
|
|
describe('Component vnClientAddressEdit', () => {
|
|
let $state;
|
|
let controller;
|
|
|
|
beforeEach(ngModule('client'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_) => {
|
|
$state = _$state_;
|
|
$state.params.addressId = '1';
|
|
controller = $componentController('vnClientAddressEdit', {$state});
|
|
controller.$.watcher = {
|
|
setDirty: () => {},
|
|
setPristine: () => {},
|
|
realSubmit: () => {},
|
|
check: () => {},
|
|
notifySaved: () => {}
|
|
};
|
|
controller.$.model = {
|
|
remove: () => {},
|
|
save: () => {}
|
|
};
|
|
controller.card = {
|
|
reload: () => {}
|
|
};
|
|
}));
|
|
|
|
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();
|
|
});
|
|
});
|
|
|
|
describe('cancel()', () => {
|
|
it('should call goToIndex()', () => {
|
|
spyOn(controller, 'goToIndex');
|
|
controller.cancel();
|
|
|
|
expect(controller.goToIndex).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('goToIndex()', () => {
|
|
it('should call $state.go("client.card.address.index")', () => {
|
|
spyOn(controller.$state, 'go');
|
|
controller.goToIndex();
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index');
|
|
});
|
|
});
|
|
|
|
describe('postcodeSelection() setter', () => {
|
|
it(`should set the town, province and contry properties`, () => {
|
|
controller.address = {};
|
|
controller._postcodeSelection = {townFk: 2};
|
|
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);
|
|
});
|
|
});
|
|
});
|
|
});
|