Tarea #510 /volume/index.js Front unit test
This commit is contained in:
parent
93810c381b
commit
e71a90d422
|
@ -0,0 +1,64 @@
|
|||
import './index';
|
||||
|
||||
describe('Order', () => {
|
||||
describe('Component vnOrderVolume', () => {
|
||||
let $componentController;
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $state;
|
||||
let $scope;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('order');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_, $rootScope) => {
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
$scope = $rootScope.$new();
|
||||
$scope.model = {data: [{itemFk: 1}, {itemFk: 2}], accept: () => {
|
||||
return {
|
||||
then: () => {}
|
||||
};
|
||||
}};
|
||||
$scope.descriptor = {show: () => {}};
|
||||
$scope.popover = {relocate: () => {}};
|
||||
$state = _$state_;
|
||||
$state.params.id = 1;
|
||||
controller = $componentController('vnOrderVolume', {$scope: $scope}, {$httpBackend: $httpBackend}, {$state: $state});
|
||||
}));
|
||||
|
||||
it('should join the sale volumes to its respective sale', () => {
|
||||
let response = {volumes: [{itemFk: 1, volume: 0.008}, {itemFk: 2, volume: 0.003}]};
|
||||
$httpBackend.whenGET(`/order/api/Orders/1/getVolumes`).respond(response);
|
||||
$httpBackend.expectGET(`/order/api/Orders/1/getVolumes`);
|
||||
controller.onDataChange();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$scope.model.data[0].volume).toBe(0.008);
|
||||
expect(controller.$scope.model.data[1].volume).toBe(0.003);
|
||||
});
|
||||
describe('showDescriptor()', () => {
|
||||
it('should set $scope.descriptor.itemFk, $scope.descriptor.parent and call $scope.descriptor.show()', () => {
|
||||
let event = {target: 1};
|
||||
let itemFk = 1;
|
||||
spyOn(controller.$scope.descriptor, 'show');
|
||||
controller.showDescriptor(event, itemFk);
|
||||
|
||||
expect(controller.$scope.descriptor.itemFk).toBe(1);
|
||||
expect(controller.$scope.descriptor.parent).toBe(1);
|
||||
expect(controller.$scope.descriptor.show).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onDescriptorLoad()', () => {
|
||||
it('should call $scope.popover.relocate()', () => {
|
||||
spyOn(controller.$scope.popover, 'relocate');
|
||||
controller.onDescriptorLoad();
|
||||
|
||||
expect(controller.$scope.popover.relocate).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue