2018-08-09 10:46:50 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Order', () => {
|
|
|
|
describe('Component vnOrderCard', () => {
|
|
|
|
let $componentController;
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('order');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
|
|
|
|
$componentController = _$componentController_;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2018-08-09 12:18:15 +00:00
|
|
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
2018-08-09 10:46:50 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.card = {createOrder: () => {}};
|
|
|
|
$state = {params: {id: 1}};
|
|
|
|
controller = $componentController('vnOrderCard', {$scope: $scope, $state: $state});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('getOrder()', () => {
|
|
|
|
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));
|
|
|
|
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond({id: 1});
|
|
|
|
controller.getOrder();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.order).toEqual({id: 1});
|
|
|
|
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);
|
|
|
|
controller.getOrder();
|
|
|
|
$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`, () => {
|
|
|
|
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond({total: '20M'});
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|