2018-08-30 06:50:03 +00:00
|
|
|
import './index.js';
|
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
describe('ticket Component vnTicketDescriptorPopover', () => {
|
|
|
|
let $httpBackend;
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
let $element;
|
|
|
|
let $timeout;
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$timeout = _$timeout_;
|
|
|
|
$element = angular.element(`<div></div>`);
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.popover = {relocate: () => {}, show: () => {}};
|
|
|
|
controller = $componentController('vnTicketDescriptorPopover', {$scope, $element});
|
|
|
|
}));
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
describe('ticketFk()', () => {
|
|
|
|
it(`should not apply any changes if the received id is the same stored in _ticketFk`, () => {
|
|
|
|
controller.ticket = 'I exist!';
|
|
|
|
controller._ticketFk = 1;
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getCard');
|
2019-02-12 13:40:13 +00:00
|
|
|
controller.ticketFk = 1;
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
expect(controller.ticket).toEqual('I exist!');
|
|
|
|
expect(controller._ticketFk).toEqual(1);
|
|
|
|
expect(controller.getCard).not.toHaveBeenCalled();
|
|
|
|
});
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
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;
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getCard');
|
2019-02-12 13:40:13 +00:00
|
|
|
controller.ticketFk = 999;
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
expect(controller.ticket).toBeNull();
|
|
|
|
expect(controller._ticketFk).toEqual(999);
|
|
|
|
expect(controller.getCard).toHaveBeenCalledWith();
|
2018-08-30 06:50:03 +00:00
|
|
|
});
|
2019-02-12 13:40:13 +00:00
|
|
|
});
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
describe('ticket()', () => {
|
|
|
|
it(`should save the ticket into _ticket and then call relocate()`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.popover, 'relocate');
|
2019-02-12 13:40:13 +00:00
|
|
|
controller.ticket = `i'm the ticket!`;
|
|
|
|
$timeout.flush();
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
expect(controller._ticket).toEqual(`i'm the ticket!`);
|
|
|
|
expect(controller.$.popover.relocate).toHaveBeenCalledWith();
|
2018-08-30 06:50:03 +00:00
|
|
|
});
|
2019-02-12 13:40:13 +00:00
|
|
|
});
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
describe('show()', () => {
|
|
|
|
it(`should call the show()`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.popover, 'show');
|
2019-02-12 13:40:13 +00:00
|
|
|
controller.show();
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
expect(controller.$.popover.show).toHaveBeenCalledWith();
|
2018-10-18 09:41:25 +00:00
|
|
|
});
|
2019-02-12 13:40:13 +00:00
|
|
|
});
|
2018-10-18 09:41:25 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
describe('getCard()', () => {
|
|
|
|
it(`should perform a get query to store the ticket data into the controller`, () => {
|
|
|
|
controller.ticketFk = 1;
|
|
|
|
controller.canceler = null;
|
|
|
|
let response = {};
|
2018-10-18 09:41:25 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
let filter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'warehouse',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'agencyMode',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'client',
|
|
|
|
scope: {
|
|
|
|
fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'],
|
|
|
|
include: {
|
|
|
|
relation: 'salesPerson',
|
|
|
|
scope: {
|
|
|
|
fields: ['userFk'],
|
|
|
|
include: {
|
|
|
|
relation: 'user',
|
|
|
|
scope: {
|
|
|
|
fields: ['nickname']
|
2019-01-31 13:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-18 09:41:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-12 13:40:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'state',
|
|
|
|
scope: {
|
|
|
|
fields: ['stateFk'],
|
|
|
|
include: {
|
|
|
|
relation: 'state',
|
|
|
|
fields: ['id', 'name'],
|
2018-10-18 09:41:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-12 13:40:13 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
let json = encodeURIComponent(JSON.stringify(filter));
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `Tickets/${controller._ticketFk}?filter=${json}`).respond(response);
|
|
|
|
$httpBackend.expect('GET', `Tickets/${controller._ticketFk}?filter=${json}`);
|
2019-02-12 13:40:13 +00:00
|
|
|
controller.getCard();
|
|
|
|
$httpBackend.flush();
|
2018-10-18 09:41:25 +00:00
|
|
|
|
2019-02-12 13:40:13 +00:00
|
|
|
expect(controller.ticket).toEqual(response);
|
2018-08-30 06:50:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-02-12 13:40:13 +00:00
|
|
|
|