Builder page: added unit test for drag & drop of skill

This commit is contained in:
gianantoniopini
2021-02-09 09:36:36 +01:00
parent 23bf495a5a
commit 2fa4ff8d9d
3 changed files with 102 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import React from 'react';
import {
fireEvent,
render,
screen,
waitFor,
@ -46,6 +47,36 @@ const expectDatabaseUpdateToHaveCompleted = async (
);
};
const dragAndDropDirectionUp = 'DND_DIRECTION_UP';
const dragAndDropDirectionDown = 'DND_DIRECTION_DOWN';
const dragAndDropListItem = (listItemElement, direction) => {
const spaceKey = { keyCode: 32 };
const arrowUpKey = { keyCode: 38 };
const arrowDownKey = { keyCode: 40 };
const getKeyForDirection = () => {
switch (direction) {
case dragAndDropDirectionUp:
return arrowUpKey;
case dragAndDropDirectionDown:
return arrowDownKey;
default:
throw new Error('Unhandled `direction`!');
}
};
listItemElement.focus();
// enable keyboard dragging
fireEvent.keyDown(listItemElement, spaceKey);
// move element based on direction
fireEvent.keyDown(listItemElement, getKeyForDirection());
// disable keyboard dragging
fireEvent.keyDown(listItemElement, spaceKey);
};
// eslint-disable-next-line no-underscore-dangle
async function _setup(
resumeId,
@ -124,4 +155,7 @@ export {
setupAndWait,
waitForDatabaseUpdateToHaveCompletedFn as waitForDatabaseUpdateToHaveCompleted,
expectDatabaseUpdateToHaveCompleted,
dragAndDropDirectionUp,
dragAndDropDirectionDown,
dragAndDropListItem,
};