salix/modules/order/front/descriptor/index.spec.js

45 lines
1.6 KiB
JavaScript

import './index.js';
describe('Order Component vnOrderDescriptor', () => {
let $httpBackend;
let controller;
beforeEach(angular.mock.module('order', $translateProvider => {
$translateProvider.translations('en', {});
}));
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');
});
});
});