2019-07-08 12:07:09 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientPostcode', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $element;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2019-07-08 12:07:09 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$element = angular.element('<vn-dialog></vn-dialog>');
|
|
|
|
controller = $componentController('vnClientPostcode', {$element});
|
|
|
|
controller.client = {id: 101};
|
|
|
|
}));
|
|
|
|
|
2020-03-03 14:03:54 +00:00
|
|
|
describe('onAccept()', () => {
|
2019-07-08 12:07:09 +00:00
|
|
|
it('should perform a POST query and show a success snackbar', () => {
|
|
|
|
let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
|
|
|
controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
|
|
|
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showMessage');
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('PATCH', `postcodes`, params).respond(200, params);
|
|
|
|
$httpBackend.expect('PATCH', `postcodes`, params).respond(params);
|
2019-07-08 12:07:09 +00:00
|
|
|
|
2020-03-03 14:03:54 +00:00
|
|
|
controller.onAccept();
|
2019-07-08 12:07:09 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|