2020-11-20 14:05:57 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Travel Component vnTravelExtraCommunity', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
beforeEach(ngModule('travel'));
|
|
|
|
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
2020-11-23 07:12:33 +00:00
|
|
|
const $element = angular.element('<vn-travel-extra-community><div class="travel-list"></div></vn-travel-extra-community>');
|
2020-11-20 14:05:57 +00:00
|
|
|
controller = $componentController('vnTravelExtraCommunity', {$element});
|
2020-11-23 07:12:33 +00:00
|
|
|
controller.$.model = {};
|
|
|
|
controller.$.model.refresh = jest.fn();
|
2020-11-20 14:05:57 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('changeReference()', () => {
|
|
|
|
it('should make an HTTP query', () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
const travel = {id: 1, ref: 'New reference'};
|
|
|
|
const expectedData = {ref: 'New reference'};
|
|
|
|
$httpBackend.expect('PATCH', `Travels/${travel.id}`, expectedData).respond(200);
|
|
|
|
controller.changeReference(travel);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-23 07:12:33 +00:00
|
|
|
describe('findDraggable()', () => {
|
|
|
|
it('should find the draggable element', () => {
|
|
|
|
const draggable = document.createElement('a');
|
|
|
|
draggable.setAttribute('draggable', true);
|
|
|
|
|
|
|
|
const $event = new Event('dragstart');
|
|
|
|
const target = document.createElement('div');
|
|
|
|
draggable.appendChild(target);
|
|
|
|
target.dispatchEvent($event);
|
|
|
|
|
|
|
|
const result = controller.findDraggable($event);
|
|
|
|
|
|
|
|
expect(result).toEqual(draggable);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('findDroppable()', () => {
|
|
|
|
it('should find the droppable element', () => {
|
|
|
|
const droppable = document.createElement('vn-table');
|
|
|
|
droppable.setAttribute('vn-droppable', true);
|
|
|
|
|
|
|
|
const $event = new Event('drop');
|
|
|
|
const target = document.createElement('div');
|
|
|
|
droppable.appendChild(target);
|
|
|
|
target.dispatchEvent($event);
|
|
|
|
|
|
|
|
const result = controller.findDroppable($event);
|
|
|
|
|
|
|
|
expect(result).toEqual(droppable);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('dragStart()', () => {
|
|
|
|
it(`should add the class "dragging" to the draggable element
|
|
|
|
and then set the entryId controller property`, () => {
|
|
|
|
const draggable = document.createElement('a');
|
|
|
|
draggable.setAttribute('draggable', true);
|
|
|
|
draggable.setAttribute('id', 3);
|
|
|
|
|
|
|
|
jest.spyOn(controller, 'findDraggable').mockReturnValue(draggable);
|
|
|
|
|
|
|
|
const $event = new Event('dragStart');
|
|
|
|
controller.dragStart($event);
|
|
|
|
|
|
|
|
const firstClass = draggable.classList[0];
|
2020-11-20 14:05:57 +00:00
|
|
|
|
2020-11-23 07:12:33 +00:00
|
|
|
expect(firstClass).toEqual('dragging');
|
|
|
|
expect(controller.entryId).toEqual(3);
|
|
|
|
expect(controller.entry).toEqual(draggable);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
fdescribe('dragEnd()', () => {
|
|
|
|
it(`should remove the class "dragging" from the draggable element
|
|
|
|
and then set the entryId controller property to null`, () => {
|
|
|
|
const draggable = document.createElement('a');
|
|
|
|
draggable.setAttribute('draggable', true);
|
|
|
|
draggable.setAttribute('id', 3);
|
|
|
|
draggable.classList.add('dragging');
|
|
|
|
|
|
|
|
jest.spyOn(controller, 'findDraggable').mockReturnValue(draggable);
|
|
|
|
|
|
|
|
const $event = new Event('dragStart');
|
|
|
|
controller.dragEnd($event);
|
|
|
|
|
|
|
|
const classList = draggable.classList;
|
|
|
|
|
|
|
|
expect(classList.length).toEqual(0);
|
|
|
|
expect(controller.entryId).toBeNull();
|
|
|
|
expect(controller.entry).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onDrop()', () => {
|
|
|
|
it('should make an HTTP patch query', () => {
|
|
|
|
const droppable = document.createElement('vn-table');
|
|
|
|
droppable.setAttribute('vn-droppable', true);
|
|
|
|
droppable.setAttribute('id', 1);
|
|
|
|
|
|
|
|
jest.spyOn(controller, 'findDroppable').mockReturnValue(droppable);
|
|
|
|
|
|
|
|
const oldDroppable = document.createElement('vn-table');
|
|
|
|
oldDroppable.setAttribute('vn-droppable', true);
|
|
|
|
const entry = document.createElement('div');
|
|
|
|
oldDroppable.appendChild(entry);
|
|
|
|
|
|
|
|
controller.entryId = 3;
|
|
|
|
controller.entry = entry;
|
|
|
|
|
|
|
|
const $event = new Event('drop');
|
|
|
|
const expectedData = {travelFk: 1};
|
|
|
|
$httpBackend.expect('PATCH', `Entries/3`, expectedData).respond(200);
|
|
|
|
controller.onDrop($event);
|
|
|
|
$httpBackend.flush();
|
2020-11-20 14:05:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|