Skip to content

Commit

Permalink
Cypress: hooked up drag command the same way as other commands
Browse files Browse the repository at this point in the history
  • Loading branch information
verheyenkoen committed Sep 9, 2024
1 parent 56d5179 commit ad5d94e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
31 changes: 24 additions & 7 deletions cypress/support/commands/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,30 @@ class DragSimulator {
}
}

Cypress.Commands.add(
"drag",
{ prevSubject: "element" },
(subject, targetSelector) => {
return new DragSimulator().drag(subject, targetSelector);
},
);
export default function drag(
subject: JQuery<HTMLElement>,
targetSelector: string,
) {
const dragSimulator = new DragSimulator();

return dragSimulator
.init(subject, targetSelector)
.then(() => dragSimulator.dragstart())
.then(() => dragSimulator.dragover())
.then((success) => {
if (success) {
return dragSimulator.drop().then(() => true);
} else {
return cy.wrap(false, NO_LOG);
}
})
.then((result) => {
dragSimulator.log.snapshot("after");

return result;
})
.finishLog(dragSimulator.log);
}

declare global {
namespace Cypress {
Expand Down
3 changes: 3 additions & 0 deletions cypress/support/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { deletePublication, deleteDataset } from "./delete-one";
import finishLog from "./finish-log";
import setField from "./set-field";
import triggerHtmx from "./trigger-htmx";
import drag from "./drag";

// Dual commands
import extractBiblioId from "./extract-biblio-id";
Expand Down Expand Up @@ -84,6 +85,8 @@ Cypress.Commands.addAll(
setField,

triggerHtmx,

drag,
},
);

Expand Down

0 comments on commit ad5d94e

Please sign in to comment.