Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Apr 3, 2024
1 parent 080f536 commit cb4755e
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tests/signature_pad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,15 @@ describe('user interactions', () => {
clientX: 50,
clientY: 30,
pressure: 1,
buttons: 1,
}),
);
externalCanvas.dispatchEvent(
new PointerEvent('pointermove', {
clientX: 240,
clientY: 30,
pressure: 1,
buttons: 1,
}),
);
// check that original document is not affected
Expand Down Expand Up @@ -455,6 +457,16 @@ describe('Signature events.', () => {
},
].forEach((param) => {
describe(`${param.eventName}.`, () => {
function createPointerEvent(dispatchedEventName: string) {
return new PointerEvent(dispatchedEventName, {
clientX: 50,
clientY: 30,
pressure: 1,
buttons: dispatchedEventName == 'pointerup' ? 0 : 1,
bubbles: true,
});
}

beforeEach(() => {
signpad.addEventListener(param.eventName, eventHandler);
});
Expand All @@ -468,15 +480,9 @@ describe('Signature events.', () => {
});

it('writes to the canvas.', () => {
const eventInitObj = <PointerEventInit>{
clientX: 50,
clientY: 30,
pressure: 1,
bubbles: true,
};
let pointerEvent;
for (const dispatchedEventName of param.dispatchedEventName) {
pointerEvent = new PointerEvent(dispatchedEventName, eventInitObj);
pointerEvent = createPointerEvent(dispatchedEventName);
canvas.dispatchEvent(pointerEvent);
}

Expand Down Expand Up @@ -532,13 +538,15 @@ describe('Signature events.', () => {
clientX: 50,
clientY: 30,
pressure: 1,
buttons: 1,
}),
);
canvas.dispatchEvent(
new PointerEvent('pointermove', {
clientX: 50,
clientY: 40,
pressure: 1,
buttons: 1,
}),
);
document.dispatchEvent(
Expand Down

0 comments on commit cb4755e

Please sign in to comment.