salix/modules/ticket/front/advance/index.spec.js

71 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-11-14 13:30:35 +00:00
import './index.js';
import crudModel from 'core/mocks/crud-model';
describe('Component vnTicketAdvance', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('ticket')
);
2022-12-20 10:36:58 +00:00
beforeEach(inject(($componentController, _$httpBackend_) => {
2022-11-14 13:30:35 +00:00
$httpBackend = _$httpBackend_;
const $element = angular.element('<vn-ticket-advance></vn-ticket-advance>');
2022-12-20 10:36:37 +00:00
controller = $componentController('vnTicketAdvance', {$element});
2022-11-14 13:30:35 +00:00
controller.$.model = crudModel;
controller.$.model.data = [{
id: 1,
checked: true,
2022-12-20 10:36:37 +00:00
state: 'OK'
2022-11-14 13:30:35 +00:00
}, {
id: 2,
checked: true,
2022-12-20 10:36:37 +00:00
state: 'Libre'
2022-11-14 13:30:35 +00:00
}];
}));
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', () => {
2023-01-16 14:18:24 +00:00
const now = Date.vnNew();
2022-11-14 13:30:35 +00:00
const today = now.getDate();
const dateRange = controller.dateRange(now);
const start = dateRange[0].toString();
const end = dateRange[1].toString();
expect(start).toContain(today);
expect(start).toContain('00:00:00');
expect(end).toContain(today);
expect(end).toContain('23:59:59');
});
});
describe('moveTicketsAdvance()', () => {
it('should make an HTTP Post query', () => {
jest.spyOn(controller.$.model, 'refresh');
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`Tickets/merge`).respond();
controller.moveTicketsAdvance();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
});