Skip to content

Commit

Permalink
fix(tests): solves testing issues + add some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
NLueg committed Jun 28, 2023
1 parent 494538c commit bc5b39e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/signature_pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export interface PointGroupOptions {
maxWidth: number;
penColor: string;
velocityFilterWeight: number;
/**
* This is the globalCompositeOperation for the line.
* *default: 'source-over'*
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
*/
compositeOperation: GlobalCompositeOperation;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const face: PointGroup[] = [
minWidth: 0.5,
maxWidth: 2.5,
velocityFilterWeight: 0.7,
compositeOperation: 'source-over',
points: [
{
time: 1523730547109,
Expand All @@ -22,6 +23,7 @@ export const face: PointGroup[] = [
minWidth: 0.5,
maxWidth: 2.5,
velocityFilterWeight: 0.7,
compositeOperation: 'source-over',
points: [
{
time: 1523730547775,
Expand All @@ -37,6 +39,7 @@ export const face: PointGroup[] = [
minWidth: 0.5,
maxWidth: 2.5,
velocityFilterWeight: 0.7,
compositeOperation: 'source-over',
points: [
{
time: 1523730548448,
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/square.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const square: PointGroup[] = [
minWidth: 0.5,
maxWidth: 2.5,
velocityFilterWeight: 0.7,
compositeOperation: 'source-over',
points: [
{
time: 1637131731972,
Expand Down
15 changes: 15 additions & 0 deletions tests/signature_pad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ describe('#clear', () => {
expect(pad.isEmpty()).toBe(true);
expect(pad.toData()).toEqual([]);
});

it('clear should apply erase options to canvas context', () => {
const pad = new SignaturePad(canvas);

pad.fromData(face);
expect(pad.isEmpty()).toBe(false);

pad.penColor = 'pink';
pad.compositeOperation = 'destination-out';

pad.clear();

const context = canvas.getContext('2d') as CanvasRenderingContext2D;
expect(context.globalCompositeOperation).toBe('destination-out');
})
});

describe('#isEmpty', () => {
Expand Down

0 comments on commit bc5b39e

Please sign in to comment.