This commit is contained in:
Carlos Jimenez Ruiz 2019-02-12 14:40:13 +01:00
parent 8ef6db9017
commit 9c0613e8e7
3 changed files with 102 additions and 119 deletions

View File

@ -28,19 +28,5 @@ describe('factory vnModuleLoader', () => {
expect(result).toEqual(jasmine.any(Promise)); expect(result).toEqual(jasmine.any(Promise));
}); });
it('should return an error if the module wasnt loaded', done => {
vnModuleLoader._loaded.myModule = false;
vnModuleLoader.load('myModule', {myValidations: () => {}})
.then(() => {
done.fail('this must fail');
})
.catch(error => {
expect(error.toString()).toEqual(`Error: Module dependency loop detected: myModule`);
done();
});
$scope.$apply();
});
}); });
}); });

View File

@ -1,126 +1,125 @@
import './index.js'; import './index.js';
describe('Item', () => { describe('ticket Component vnTicketDescriptorPopover', () => {
describe('Component vnTicketDescriptorPopover', () => { let $httpBackend;
let $httpBackend; let $scope;
let $scope; let controller;
let controller; let $element;
let $element; let $timeout;
let $timeout;
beforeEach(ngModule('item')); beforeEach(ngModule('ticket'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$timeout = _$timeout_; $timeout = _$timeout_;
$element = angular.element(`<div></div>`); $element = angular.element(`<div></div>`);
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$scope.popover = {relocate: () => {}, show: () => {}}; $scope.popover = {relocate: () => {}, show: () => {}};
controller = $componentController('vnTicketDescriptorPopover', {$scope, $element}); controller = $componentController('vnTicketDescriptorPopover', {$scope, $element});
})); }));
describe('ticketFk()', () => { describe('ticketFk()', () => {
it(`should not apply any changes if the received id is the same stored in _ticketFk`, () => { it(`should not apply any changes if the received id is the same stored in _ticketFk`, () => {
controller.ticket = 'I exist!'; controller.ticket = 'I exist!';
controller._ticketFk = 1; controller._ticketFk = 1;
spyOn(controller, 'getCard'); spyOn(controller, 'getCard');
controller.ticketFk = 1; controller.ticketFk = 1;
expect(controller.ticket).toEqual('I exist!'); expect(controller.ticket).toEqual('I exist!');
expect(controller._ticketFk).toEqual(1); expect(controller._ticketFk).toEqual(1);
expect(controller.getCard).not.toHaveBeenCalled(); expect(controller.getCard).not.toHaveBeenCalled();
});
it(`should set the received id into _ticketFk, set the ticket to null and then call getCard()`, () => {
controller.ticket = `Please don't`;
controller._ticketFk = 1;
spyOn(controller, 'getCard');
controller.ticketFk = 999;
expect(controller.ticket).toBeNull();
expect(controller._ticketFk).toEqual(999);
expect(controller.getCard).toHaveBeenCalledWith();
});
}); });
describe('ticket()', () => { it(`should set the received id into _ticketFk, set the ticket to null and then call getCard()`, () => {
it(`should save the ticket into _ticket and then call relocate()`, () => { controller.ticket = `Please don't`;
spyOn(controller.$.popover, 'relocate'); controller._ticketFk = 1;
controller.ticket = `i'm the ticket!`; spyOn(controller, 'getCard');
$timeout.flush(); controller.ticketFk = 999;
expect(controller._ticket).toEqual(`i'm the ticket!`); expect(controller.ticket).toBeNull();
expect(controller.$.popover.relocate).toHaveBeenCalledWith(); expect(controller._ticketFk).toEqual(999);
}); expect(controller.getCard).toHaveBeenCalledWith();
}); });
});
describe('show()', () => { describe('ticket()', () => {
it(`should call the show()`, () => { it(`should save the ticket into _ticket and then call relocate()`, () => {
spyOn(controller.$.popover, 'show'); spyOn(controller.$.popover, 'relocate');
controller.show(); controller.ticket = `i'm the ticket!`;
$timeout.flush();
expect(controller.$.popover.show).toHaveBeenCalledWith(); expect(controller._ticket).toEqual(`i'm the ticket!`);
}); expect(controller.$.popover.relocate).toHaveBeenCalledWith();
}); });
});
describe('getCard()', () => { describe('show()', () => {
it(`should perform a get query to store the ticket data into the controller`, () => { it(`should call the show()`, () => {
controller.ticketFk = 1; spyOn(controller.$.popover, 'show');
controller.canceler = null; controller.show();
let response = {};
let filter = { expect(controller.$.popover.show).toHaveBeenCalledWith();
include: [ });
{ });
relation: 'warehouse',
scope: { describe('getCard()', () => {
fields: ['name'] it(`should perform a get query to store the ticket data into the controller`, () => {
} controller.ticketFk = 1;
}, controller.canceler = null;
{ let response = {};
relation: 'agencyMode',
scope: { let filter = {
fields: ['name'] include: [
} {
}, relation: 'warehouse',
{ scope: {
relation: 'client', fields: ['name']
scope: { }
fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'], },
include: { {
relation: 'salesPerson', relation: 'agencyMode',
scope: { scope: {
fields: ['userFk'], fields: ['name']
include: { }
relation: 'user', },
scope: { {
fields: ['nickname'] relation: 'client',
} scope: {
fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'],
include: {
relation: 'salesPerson',
scope: {
fields: ['userFk'],
include: {
relation: 'user',
scope: {
fields: ['nickname']
} }
} }
} }
} }
}, }
{ },
relation: 'state', {
scope: { relation: 'state',
fields: ['stateFk'], scope: {
include: { fields: ['stateFk'],
relation: 'state', include: {
fields: ['id', 'name'], relation: 'state',
} fields: ['id', 'name'],
} }
} }
] }
}; ]
let json = encodeURIComponent(JSON.stringify(filter)); };
$httpBackend.when('GET', `/ticket/api/Tickets/${controller._ticketFk}?filter=${json}`).respond(response); let json = encodeURIComponent(JSON.stringify(filter));
$httpBackend.expect('GET', `/ticket/api/Tickets/${controller._ticketFk}?filter=${json}`); $httpBackend.when('GET', `/ticket/api/Tickets/${controller._ticketFk}?filter=${json}`).respond(response);
controller.getCard(); $httpBackend.expect('GET', `/ticket/api/Tickets/${controller._ticketFk}?filter=${json}`);
$httpBackend.flush(); controller.getCard();
$httpBackend.flush();
expect(controller.ticket).toEqual(response); expect(controller.ticket).toEqual(response);
});
}); });
}); });
}); });

View File

@ -1,12 +1,10 @@
import './index.js'; import './index.js';
describe('Item Component vnTicketDescriptor', () => { describe('Ticket Component vnTicketDescriptor', () => {
let $httpBackend; let $httpBackend;
let controller; let controller;
beforeEach(() => { beforeEach(ngModule('ticket'));
ngModule('item');
});
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;