salix/modules/route/front/index/index.spec.js

157 lines
5.2 KiB
JavaScript
Raw Normal View History

2020-08-25 08:22:57 +00:00
import './index.js';
import crudModel from 'core/mocks/crud-model';
describe('Component vnRouteIndex', () => {
let controller;
let $httpBackend;
2020-08-25 08:22:57 +00:00
beforeEach(ngModule('route'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
2020-08-25 08:22:57 +00:00
const $element = angular.element('<vn-route-index></vn-route-index>');
controller = $componentController('vnRouteIndex', {$element});
controller.$.model = crudModel;
2022-09-13 11:47:54 +00:00
controller.$.model.data = [{id: 1, checked: true}, {id: 2}, {id: 3}];
2020-08-25 08:22:57 +00:00
}));
describe('checked() getter', () => {
2020-08-25 12:10:38 +00:00
it('should return the checked lines', () => {
2020-08-25 08:22:57 +00:00
const data = controller.$.model.data;
data[0].checked = true;
data[2].checked = true;
const checkedRows = controller.checked;
const firstCheckedRow = checkedRows[0];
const secondCheckedRow = checkedRows[1];
expect(firstCheckedRow.id).toEqual(1);
expect(secondCheckedRow.id).toEqual(3);
});
});
describe('totalCheked() getter', () => {
2020-08-25 12:10:38 +00:00
it('should return the total checked lines', () => {
2020-08-25 08:22:57 +00:00
const data = controller.$.model.data;
data[0].checked = true;
const checkedRows = controller.totalChecked;
expect(checkedRows).toEqual(1);
});
});
describe('showRouteReport()', () => {
it('should call to the vnReport show method', () => {
2023-01-17 13:24:04 +00:00
jest.spyOn(window, 'open').mockReturnThis();
2020-08-25 08:22:57 +00:00
const data = controller.$.model.data;
data[0].checked = true;
data[2].checked = true;
2020-08-25 08:22:57 +00:00
controller.showRouteReport();
2023-01-17 13:24:04 +00:00
expect(window.open).toHaveBeenCalled();
2020-08-25 08:22:57 +00:00
});
});
2020-12-24 10:31:20 +00:00
describe('cloneSelectedRoutes()', () => {
it('should perform an http request to Routes/clone', () => {
2023-01-16 14:18:24 +00:00
controller.createdDate = Date.vnNew();
2020-12-24 10:31:20 +00:00
$httpBackend.expect('POST', 'Routes/clone').respond();
controller.cloneSelectedRoutes();
$httpBackend.flush();
});
});
describe('onDrop()', () => {
it('should call the insert method when dragging a ticket number', () => {
jest.spyOn(controller, 'insert');
const routeId = '1';
const expectedTicketId = '16';
const draggedElement = '16';
const droppable = document.createElement('a');
droppable.setAttribute('id', 1);
droppable.classList.add('vn-tr');
const $event = {
dataTransfer: {
getData: () => draggedElement
},
target: droppable
};
controller.onDrop($event);
expect(controller.insert).toHaveBeenCalledWith(routeId, expectedTicketId);
});
it('should call the insert method when dragging a ticket link', () => {
jest.spyOn(controller, 'insert');
const routeId = '1';
const expectedTicketId = '11';
const draggedElement = 'http://arkamcity.com/#!/ticket/11/summary';
const droppable = document.createElement('a');
droppable.setAttribute('id', 1);
droppable.classList.add('vn-tr');
const $event = {
dataTransfer: {
getData: () => draggedElement
},
target: droppable
};
controller.onDrop($event);
expect(controller.insert).toHaveBeenCalledWith(routeId, expectedTicketId);
});
it('should throw an error when dragging an invalid ticket link', () => {
jest.spyOn(controller.vnApp, 'showError');
const draggedElement = 'http://arkamcity.com/#!/item/11/summary';
const droppable = document.createElement('a');
droppable.setAttribute('id', 1);
droppable.classList.add('vn-tr');
const $event = {
dataTransfer: {
getData: () => draggedElement
},
target: droppable
};
controller.onDrop($event);
expect(controller.vnApp.showError).toHaveBeenCalledWith('Ticket not found');
});
});
describe('insert()', () => {
it('should perform a HTTP patch query and then call both refresh and showSuccess methods', () => {
jest.spyOn(controller.$.model, 'refresh').mockReturnThis();
jest.spyOn(controller.vnApp, 'showSuccess');
const routeId = 1;
const ticketId = 11;
const data = {ticketId};
$httpBackend.expect('PATCH', `Routes/1/insertTicket`, data).respond();
controller.insert(routeId, ticketId);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
2022-09-13 11:47:54 +00:00
describe('markAsServed()', () => {
it('should perform a HTTP patch query', () => {
const data = {isOk: true};
$httpBackend.expect('PATCH', `Routes/1`, data).respond();
controller.markAsServed();
$httpBackend.flush();
});
});
2020-08-25 08:22:57 +00:00
});