diff --git a/modules/travel/back/methods/travel/specs/filter.spec.js b/modules/travel/back/methods/travel/specs/filter.spec.js
index d04b0f093..ababe961e 100644
--- a/modules/travel/back/methods/travel/specs/filter.spec.js
+++ b/modules/travel/back/methods/travel/specs/filter.spec.js
@@ -38,7 +38,7 @@ describe('Travel filter()', () => {
const result = await app.models.Travel.filter(ctx);
- expect(result.length).toEqual(8);
+ expect(result.length).toEqual(3);
});
it('should return the travel matching "total entries"', async() => {
diff --git a/modules/travel/front/extra-community/index.js b/modules/travel/front/extra-community/index.js
index bd362f34f..221d6cb0d 100644
--- a/modules/travel/front/extra-community/index.js
+++ b/modules/travel/front/extra-community/index.js
@@ -48,7 +48,7 @@ class Controller extends Section {
const draggable = this.findDraggable($event);
draggable.classList.add('dragging');
- const id = draggable.getAttribute('id');
+ const id = parseInt(draggable.id);
this.entryId = id;
this.entry = draggable;
}
@@ -63,7 +63,7 @@ class Controller extends Section {
onDrop($event) {
const model = this.$.model;
const droppable = this.findDroppable($event);
- const travelId = droppable.getAttribute('id');
+ const travelId = parseInt(droppable.id);
const currentDroppable = this.entry.closest(this.droppableElement);
diff --git a/modules/travel/front/extra-community/index.spec.js b/modules/travel/front/extra-community/index.spec.js
index 54f5e505f..581002f18 100644
--- a/modules/travel/front/extra-community/index.spec.js
+++ b/modules/travel/front/extra-community/index.spec.js
@@ -3,20 +3,15 @@ import './index.js';
describe('Travel Component vnTravelExtraCommunity', () => {
let controller;
let $httpBackend;
- let travel = {
- id: 1,
- warehouseInFk: 1,
- totalEntries: 3,
- isDelivered: false
- };
beforeEach(ngModule('travel'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
- const $element = angular.element('');
+ const $element = angular.element('');
controller = $componentController('vnTravelExtraCommunity', {$element});
- controller.$.summary = {show: jasmine.createSpy('show')};
+ controller.$.model = {};
+ controller.$.model.refresh = jest.fn();
}));
describe('changeReference()', () => {
@@ -33,15 +28,100 @@ describe('Travel Component vnTravelExtraCommunity', () => {
});
});
- xdescribe('changeReference()', () => {
- it('should make an HTTP query', () => {
- let event = new MouseEvent('click', {
- bubbles: true,
- cancelable: true
- });
- controller.preview(event, travel);
+ describe('findDraggable()', () => {
+ it('should find the draggable element', () => {
+ const draggable = document.createElement('a');
+ draggable.setAttribute('draggable', true);
- expect(controller.$.summary.show).toHaveBeenCalledWith();
+ 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];
+
+ 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();
});
});
});