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;
|
2018-10-30 12:58:02 +00:00
|
|
|
let $window;
|
|
|
|
let tickets = [{
|
|
|
|
id: 1,
|
|
|
|
clientFk: 1,
|
2019-04-25 05:57:26 +00:00
|
|
|
total: 10.5,
|
2019-04-29 08:21:36 +00:00
|
|
|
checked: false
|
2019-04-25 05:57:26 +00:00
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
clientFk: 1,
|
|
|
|
total: 20.5,
|
2019-04-29 08:21:36 +00:00
|
|
|
checked: true
|
2019-04-25 05:57:26 +00:00
|
|
|
}, {
|
|
|
|
id: 3,
|
|
|
|
clientFk: 1,
|
|
|
|
total: 30,
|
2019-04-29 08:21:36 +00:00
|
|
|
checked: true
|
2018-10-30 12:58:02 +00:00
|
|
|
}];
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('ticket', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-08-13 07:32:33 +00:00
|
|
|
|
2019-04-29 08:21:36 +00:00
|
|
|
beforeEach(inject(($componentController, _$window_) => {
|
2018-10-30 12:58:02 +00:00
|
|
|
$window = _$window_;
|
2019-04-29 08:21:36 +00:00
|
|
|
controller = $componentController('vnTicketIndex');
|
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', () => {
|
|
|
|
let curDate = new Date();
|
2018-11-06 13:27:16 +00:00
|
|
|
let result = controller.compareDate(curDate);
|
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', () => {
|
|
|
|
let futureDate = new Date();
|
|
|
|
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', () => {
|
|
|
|
let pastDate = new Date();
|
|
|
|
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
|
|
|
|
2019-02-15 11:39:21 +00:00
|
|
|
describe('showClientDescriptor()', () => {
|
|
|
|
it('should show the client descriptor popover', () => {
|
2019-04-29 08:21:36 +00:00
|
|
|
controller.$.clientDescriptor = {show: () => {}};
|
|
|
|
controller.$.clientDescriptor.show = jasmine.createSpy('show');
|
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
|
|
|
});
|
2019-02-15 11:39:21 +00:00
|
|
|
controller.showClientDescriptor(event, tickets[0].clientFk);
|
2018-04-19 12:56:05 +00:00
|
|
|
|
2019-02-15 11:39:21 +00:00
|
|
|
expect(controller.$.clientDescriptor.show).toHaveBeenCalledWith();
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|
2018-10-30 12:58:02 +00:00
|
|
|
});
|
2018-04-19 12:56:05 +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: () => {}};
|
2018-11-06 13:27:16 +00:00
|
|
|
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
|
|
|
|
|
|
|
describe('setBalanceCreateDialog()', () => {
|
|
|
|
it('should fill the object for the component balanceCreateDialog', () => {
|
2019-04-29 08:21:36 +00:00
|
|
|
controller.$.tickets = tickets;
|
2019-04-25 05:57:26 +00:00
|
|
|
controller.$.balanceCreateDialog = {};
|
2019-04-29 08:21:36 +00:00
|
|
|
controller.$.balanceCreateDialog.amountPaid = 0;
|
|
|
|
controller.setBalanceCreateDialog();
|
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
|
|
|
});
|
|
|
|
});
|
2018-04-19 12:56:05 +00:00
|
|
|
});
|