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

43 lines
1.5 KiB
JavaScript

import './index.js';
describe('Order Component vnOrderDescriptor', () => {
let $httpBackend;
let controller;
beforeEach(ngModule('order'));
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!';
jest.spyOn(controller.vnApp, 'showSuccess');
jest.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';
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}`);
controller.deleteOrder(response);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order deleted');
expect(controller.$state.go).toHaveBeenCalledWith('order.index');
});
});
});