mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-22 20:51:29 +10:00
Builder page: added unit test for drag & drop of skill
This commit is contained in:
@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user