2019-08-29 11:16:38 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Order Component vnOrderDescriptor', () => {
|
|
|
|
let $httpBackend;
|
|
|
|
let controller;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('order', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2019-08-29 11:16:38 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
controller = $componentController('vnOrderDescriptor');
|
|
|
|
controller.order = {id: 1};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('deleteOrder()', () => {
|
|
|
|
it(`should do nothing if the response isn't ACCEPT`, () => {
|
|
|
|
let response = 'WAGH!';
|
|
|
|
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
spyOn(controller.$state, 'go');
|
|
|
|
controller.deleteOrder(response);
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Order deleted!');
|
|
|
|
expect(controller.$state.go).not.toHaveBeenCalledWith('order.index');
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should perform a DELETE query if the response was ACCEPT`, () => {
|
|
|
|
let response = 'ACCEPT';
|
|
|
|
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
spyOn(controller.$state, 'go');
|
|
|
|
$httpBackend.when('DELETE', `/api/Orders/${controller.order.id}`).respond(200);
|
|
|
|
$httpBackend.expect('DELETE', `/api/Orders/${controller.order.id}`);
|
|
|
|
controller.deleteOrder(response);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order deleted');
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('order.index');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|