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

43 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-08-29 11:16:38 +00:00
import './index.js';
describe('Order Component vnOrderDescriptor', () => {
let $httpBackend;
let controller;
beforeEach(ngModule('order'));
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()', () => {
2019-10-30 15:57:14 +00:00
it(`should do nothing if the response isn't accept`, () => {
2019-08-29 11:16:38 +00:00
let response = 'WAGH!';
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$state, 'go');
2019-08-29 11:16:38 +00:00
controller.deleteOrder(response);
expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Order deleted!');
expect(controller.$state.go).not.toHaveBeenCalledWith('order.index');
});
2019-10-30 15:57:14 +00:00
it(`should perform a DELETE query if the response was accept`, () => {
let response = 'accept';
2019-08-29 11:16:38 +00:00
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$state, 'go');
$httpBackend.when('DELETE', `Orders/${controller.order.id}`).respond(200);
$httpBackend.expect('DELETE', `Orders/${controller.order.id}`);
2019-08-29 11:16:38 +00:00
controller.deleteOrder(response);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order deleted');
expect(controller.$state.go).toHaveBeenCalledWith('order.index');
});
});
});