2022-11-08 14:56:58 +00:00
|
|
|
import './index.js';
|
|
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
|
|
|
|
describe('Component vnTicketFuture', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
const today = Date.vnNew();
|
2022-11-08 14:56:58 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2022-12-20 08:54:28 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2022-11-08 14:56:58 +00:00
|
|
|
|
2022-12-20 08:54:28 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
2022-11-08 14:56:58 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
const $element = angular.element('<vn-ticket-future></vn-ticket-future>');
|
2022-12-14 11:17:12 +00:00
|
|
|
controller = $componentController('vnTicketFuture', {$element});
|
2022-11-08 14:56:58 +00:00
|
|
|
controller.$.model = crudModel;
|
|
|
|
controller.$.model.data = [{
|
|
|
|
id: 1,
|
|
|
|
checked: true,
|
2022-12-14 11:17:12 +00:00
|
|
|
state: 'OK'
|
2022-11-08 14:56:58 +00:00
|
|
|
}, {
|
|
|
|
id: 2,
|
|
|
|
checked: true,
|
2022-12-14 11:17:12 +00:00
|
|
|
state: 'Libre'
|
2022-11-08 14:56:58 +00:00
|
|
|
}];
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('compareDate()', () => {
|
|
|
|
it('should return warning when the date is the present', () => {
|
|
|
|
let result = controller.compareDate(today);
|
|
|
|
|
|
|
|
expect(result).toEqual('warning');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return sucess when the date is in the future', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let futureDate = Date.vnNew();
|
2022-11-08 14:56:58 +00:00
|
|
|
futureDate = futureDate.setDate(futureDate.getDate() + 10);
|
|
|
|
let result = controller.compareDate(futureDate);
|
|
|
|
|
|
|
|
expect(result).toEqual('success');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return undefined when the date is in the past', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
let pastDate = Date.vnNew();
|
2022-11-08 14:56:58 +00:00
|
|
|
pastDate = pastDate.setDate(pastDate.getDate() - 10);
|
|
|
|
let result = controller.compareDate(pastDate);
|
|
|
|
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checked()', () => {
|
|
|
|
it('should return an array of checked tickets', () => {
|
|
|
|
const result = controller.checked;
|
|
|
|
const firstRow = result[0];
|
|
|
|
const secondRow = result[1];
|
|
|
|
|
|
|
|
expect(result.length).toEqual(2);
|
|
|
|
expect(firstRow.id).toEqual(1);
|
|
|
|
expect(secondRow.id).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('dateRange()', () => {
|
|
|
|
it('should return two dates with the hours at the start and end of the given date', () => {
|
2022-12-20 08:54:28 +00:00
|
|
|
const dateRange = controller.dateRange(today);
|
2022-11-08 14:56:58 +00:00
|
|
|
const start = dateRange[0].toString();
|
|
|
|
const end = dateRange[1].toString();
|
|
|
|
|
2022-12-20 08:54:28 +00:00
|
|
|
expect(start).toContain(today.getDate());
|
2022-11-08 14:56:58 +00:00
|
|
|
expect(start).toContain('00:00:00');
|
|
|
|
|
2022-12-20 08:54:28 +00:00
|
|
|
expect(end).toContain(today.getDate());
|
2022-11-08 14:56:58 +00:00
|
|
|
expect(end).toContain('23:59:59');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('moveTicketsFuture()', () => {
|
|
|
|
it('should make an HTTP Post query', () => {
|
|
|
|
jest.spyOn(controller.$.model, 'refresh');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
$httpBackend.expectPOST(`Tickets/merge`).respond();
|
|
|
|
controller.moveTicketsFuture();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|