2019-08-29 11:16:38 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Order Component vnOrderDescriptor', () => {
|
|
|
|
let $httpBackend;
|
2020-03-17 14:18:02 +00:00
|
|
|
let $scope;
|
2019-08-29 11:16:38 +00:00
|
|
|
let controller;
|
|
|
|
|
2020-03-17 14:18:02 +00:00
|
|
|
beforeEach(ngModule('order'));
|
2019-08-29 11:16:38 +00:00
|
|
|
|
2020-03-17 14:18:02 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => {
|
2019-08-29 11:16:38 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-03-17 14:18:02 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
const $element = angular.element('<vn-order-descriptor></vn-order-descriptor>');
|
|
|
|
controller = $componentController('vnOrderDescriptor', {$element, $scope});
|
2019-08-29 11:16:38 +00:00
|
|
|
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');
|
2019-10-24 22:53:53 +00:00
|
|
|
$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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|