2018-05-25 08:03:45 +00:00
|
|
|
import './index.js';
|
2019-04-29 08:21:36 +00:00
|
|
|
describe('Component vnTicketIndex', () => {
|
2018-11-06 13:27:16 +00:00
|
|
|
let controller;
|
2020-06-17 13:38:37 +00:00
|
|
|
let $httpBackend;
|
2018-10-30 12:58:02 +00:00
|
|
|
let $window;
|
|
|
|
let tickets = [{
|
|
|
|
id: 1,
|
|
|
|
clientFk: 1,
|
2021-03-10 18:25:26 +00:00
|
|
|
checked: false,
|
|
|
|
totalWithVat: 10.5
|
2019-04-25 05:57:26 +00:00
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
clientFk: 1,
|
2021-03-10 18:25:26 +00:00
|
|
|
checked: true,
|
2023-06-13 09:37:35 +00:00
|
|
|
totalWithVat: 20.5,
|
|
|
|
stateFk: 1
|
2019-04-25 05:57:26 +00:00
|
|
|
}, {
|
|
|
|
id: 3,
|
|
|
|
clientFk: 1,
|
2021-03-10 18:25:26 +00:00
|
|
|
checked: true,
|
2023-06-13 09:37:35 +00:00
|
|
|
totalWithVat: 30,
|
|
|
|
stateFk: 1
|
2018-10-30 12:58:02 +00:00
|
|
|
}];
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2020-06-17 13:38:37 +00:00
|
|
|
beforeEach(inject(($componentController, _$window_, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
2018-10-30 12:58:02 +00:00
|
|
|
$window = _$window_;
|
2020-03-18 07:35:59 +00:00
|
|
|
const $element = angular.element('<vn-ticket-index></vn-ticket-index>');
|
|
|
|
controller = $componentController('vnTicketIndex', {$element});
|
2018-10-30 12:58:02 +00:00
|
|
|
}));
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
describe('compareDate()', () => {
|
|
|
|
it('should return warning when the date is the present', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let today = Date.vnNew();
|
2020-11-13 12:04:22 +00:00
|
|
|
let result = controller.compareDate(today);
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
expect(result).toEqual('warning');
|
|
|
|
});
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
it('should return sucess when the date is in the future', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let futureDate = Date.vnNew();
|
2018-10-30 12:58:02 +00:00
|
|
|
futureDate = futureDate.setDate(futureDate.getDate() + 10);
|
2018-11-06 13:27:16 +00:00
|
|
|
let result = controller.compareDate(futureDate);
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
expect(result).toEqual('success');
|
|
|
|
});
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
it('should return undefined when the date is in the past', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let pastDate = Date.vnNew();
|
2018-10-30 12:58:02 +00:00
|
|
|
pastDate = pastDate.setDate(pastDate.getDate() - 10);
|
2018-11-06 13:27:16 +00:00
|
|
|
let result = controller.compareDate(pastDate);
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
expect(result).toEqual(undefined);
|
2018-08-13 07:32:33 +00:00
|
|
|
});
|
2018-10-30 12:58:02 +00:00
|
|
|
});
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
describe('preview()', () => {
|
|
|
|
it('should show the dialog summary', () => {
|
2019-04-29 08:21:36 +00:00
|
|
|
controller.$.summary = {show: () => {}};
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.summary, 'show');
|
2018-04-19 12:56:05 +00:00
|
|
|
|
2018-10-30 12:58:02 +00:00
|
|
|
let event = new MouseEvent('click', {
|
|
|
|
view: $window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|
2018-11-06 13:27:16 +00:00
|
|
|
controller.preview(event, tickets[0]);
|
2018-10-30 12:58:02 +00:00
|
|
|
|
2018-11-06 13:27:16 +00:00
|
|
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|
|
|
|
});
|
2019-04-25 05:57:26 +00:00
|
|
|
|
2020-03-09 10:50:23 +00:00
|
|
|
describe('openBalanceDialog()', () => {
|
2019-04-25 05:57:26 +00:00
|
|
|
it('should fill the object for the component balanceCreateDialog', () => {
|
2020-03-09 10:50:23 +00:00
|
|
|
controller.$.balanceCreateDialog = {show: () => {}};
|
|
|
|
jest.spyOn(controller.$.balanceCreateDialog, 'show').mockReturnThis();
|
|
|
|
|
2020-03-25 14:17:43 +00:00
|
|
|
controller.$.model = {data: tickets};
|
2020-03-09 10:50:23 +00:00
|
|
|
controller.openBalanceDialog();
|
2019-04-25 05:57:26 +00:00
|
|
|
|
2019-04-29 08:21:36 +00:00
|
|
|
let description = controller.$.balanceCreateDialog.description;
|
|
|
|
let amountPaid = controller.$.balanceCreateDialog.amountPaid;
|
2019-04-25 05:57:26 +00:00
|
|
|
|
2019-04-29 08:21:36 +00:00
|
|
|
expect(description).toEqual('Albaran: 2, 3');
|
|
|
|
expect(amountPaid).toEqual(50.5);
|
2019-04-25 05:57:26 +00:00
|
|
|
});
|
|
|
|
});
|
2020-03-09 10:50:23 +00:00
|
|
|
|
2023-06-13 09:37:35 +00:00
|
|
|
describe('sendDocuware()', () => {
|
|
|
|
it('should perform a post to sendDocuware and change tickets state', () => {
|
2020-06-17 13:38:37 +00:00
|
|
|
controller.$.model = {data: tickets, refresh: () => {}};
|
2023-06-13 09:37:35 +00:00
|
|
|
const newState = {id: 2};
|
2020-06-17 13:38:37 +00:00
|
|
|
|
2023-06-13 09:37:35 +00:00
|
|
|
$httpBackend.expect('POST', 'Docuwares/upload').respond({id: newState.id});
|
|
|
|
controller.sendDocuware();
|
2020-06-17 13:38:37 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2023-06-13 09:37:35 +00:00
|
|
|
expect(controller.$.model.data[1].stateFk).toEqual(newState.id);
|
2020-06-17 13:38:37 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-09 10:50:23 +00:00
|
|
|
describe('checked()', () => {
|
|
|
|
it('should return an array of checked tickets', () => {
|
2020-03-25 14:17:43 +00:00
|
|
|
controller.$.model = {data: tickets};
|
2020-03-09 10:50:23 +00:00
|
|
|
const result = controller.checked;
|
|
|
|
const firstRow = result[0];
|
|
|
|
const secondRow = result[1];
|
|
|
|
|
|
|
|
expect(result.length).toEqual(2);
|
|
|
|
expect(firstRow.id).toEqual(2);
|
|
|
|
expect(secondRow.id).toEqual(3);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('totalChecked()', () => {
|
|
|
|
it('should return the total number of checked tickets', () => {
|
2020-03-25 14:17:43 +00:00
|
|
|
controller.$.model = {data: tickets};
|
2020-03-09 10:50:23 +00:00
|
|
|
const result = controller.checked;
|
|
|
|
|
|
|
|
expect(result.length).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|