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

46 lines
1.7 KiB
JavaScript

import './index.js';
describe('Order Component vnOrderDescriptor', () => {
let $httpBackend;
let $scope;
let controller;
beforeEach(ngModule('order'));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-order-descriptor></vn-order-descriptor>');
controller = $componentController('vnOrderDescriptor', {$element, $scope});
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');
});
});
});