Updated front unit tests
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-11-23 08:12:33 +01:00
parent d40ea52560
commit 03158f04ae
3 changed files with 99 additions and 19 deletions

View File

@ -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() => {

View File

@ -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);

View File

@ -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('<vn-travel-extra-community></vn-travel-extra-community>');
const $element = angular.element('<vn-travel-extra-community><div class="travel-list"></div></vn-travel-extra-community>');
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();
});
});
});