2018-08-09 10:46:50 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Order', () => {
|
|
|
|
describe('Component vnOrderCard', () => {
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('order'));
|
2018-08-09 10:46:50 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
|
2018-08-09 10:46:50 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.card = {createOrder: () => {}};
|
|
|
|
$state = {params: {id: 1}};
|
2018-12-22 10:59:26 +00:00
|
|
|
controller = $componentController('vnOrderCard', {$scope, $state});
|
2018-08-09 10:46:50 +00:00
|
|
|
}));
|
|
|
|
|
2018-10-03 06:00:19 +00:00
|
|
|
describe('getCard()', () => {
|
2018-08-09 10:46:50 +00:00
|
|
|
it(`should make a query, save the data in order and call get order if the response has data`, () => {
|
|
|
|
spyOn(controller, 'getTotal');
|
|
|
|
let json = encodeURIComponent(JSON.stringify(controller.filter));
|
2018-12-10 07:43:57 +00:00
|
|
|
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond({rows: [1, 2, 3]});
|
2018-10-03 06:00:19 +00:00
|
|
|
controller.getCard();
|
2018-08-09 10:46:50 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2018-12-10 07:43:57 +00:00
|
|
|
expect(controller.order).toEqual({rows: [1, 2, 3]});
|
2018-08-09 10:46:50 +00:00
|
|
|
expect(controller.getTotal).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should make a query and not call getTotal if the response is not defined`, () => {
|
|
|
|
spyOn(controller, 'getTotal');
|
|
|
|
let json = encodeURIComponent(JSON.stringify(controller.filter));
|
|
|
|
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond(undefined);
|
2018-10-03 06:00:19 +00:00
|
|
|
controller.getCard();
|
2018-08-09 10:46:50 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.order).toEqual({});
|
|
|
|
expect(controller.getTotal).not.toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getTotal()', () => {
|
|
|
|
it(`should make a query and save the data in order.total`, () => {
|
2018-10-10 10:55:04 +00:00
|
|
|
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond('20M');
|
2018-08-09 10:46:50 +00:00
|
|
|
controller.getTotal();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.order.total).toEqual('20M');
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should make a query and not save the respones if is not defined`, () => {
|
|
|
|
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond();
|
|
|
|
controller.getTotal();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.order.total).toEqual(undefined);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|