-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
386 additions
and
29 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
__tests__/classes/CanvasRenderingContext2D.__getClippingPath.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
let ctx; | ||
beforeEach(() => { | ||
// get a new context each test | ||
ctx = document.createElement('canvas') | ||
.getContext('2d'); | ||
}); | ||
|
||
afterEach(() => { | ||
const drawCalls = ctx.__getClippingRegion(); | ||
expect(drawCalls).toMatchSnapshot(); | ||
}); | ||
|
||
describe('__getClippingRegion', () => { | ||
it("should be empty when there are no path elements", () => { | ||
ctx.clip(); | ||
}); | ||
|
||
it("should store the clipping region", () => { | ||
ctx.rect(1, 2, 3, 4); | ||
ctx.arc(1, 2, 3, 4, 5); | ||
ctx.clip(); | ||
}); | ||
|
||
it("shouldn't store the whole clipping region twice when clip is called twice", () => { | ||
ctx.rect(1, 2, 3, 4); | ||
ctx.arc(1, 2, 3, 4, 5); | ||
ctx.clip(); | ||
ctx.rect(1, 2, 3, 4); | ||
ctx.arc(1, 2, 3, 4, 5); | ||
ctx.clip(); | ||
}); | ||
|
||
it("should save the clipping region correctly when saved", () => { | ||
ctx.rect(1, 2, 3, 4); | ||
ctx.arc(1, 2, 3, 4, 5); | ||
ctx.clip(); | ||
const region = ctx.__getClippingRegion(); | ||
ctx.save(); | ||
expect(region).toStrictEqual(ctx.__getClippingRegion()); | ||
}); | ||
|
||
it("should save the clipping region correctly when saved", () => { | ||
ctx.rect(1, 2, 3, 4); | ||
ctx.arc(1, 2, 3, 4, 5); | ||
ctx.clip(); | ||
const region = ctx.__getClippingRegion(); | ||
ctx.save(); | ||
ctx.rect(1, 2, 3, 4); | ||
ctx.arc(1, 2, 3, 4, 5); | ||
ctx.clip(); | ||
expect(region).not.toStrictEqual(ctx.__getClippingRegion()); | ||
ctx.restore(); | ||
expect(region).toStrictEqual(ctx.__getClippingRegion()); | ||
}); | ||
}); |
267 changes: 267 additions & 0 deletions
267
__tests__/classes/__snapshots__/CanvasRenderingContext2D.__getClippingPath.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`__getClippingRegion should be empty when there are no path elements 1`] = `Array []`; | ||
|
||
exports[`__getClippingRegion should save the clipping region correctly when saved 1`] = ` | ||
Array [ | ||
Object { | ||
"props": Object { | ||
"height": 4, | ||
"width": 3, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "rect", | ||
}, | ||
Object { | ||
"props": Object { | ||
"anticlockwise": false, | ||
"endAngle": 5, | ||
"radius": 3, | ||
"startAngle": 4, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "arc", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`__getClippingRegion should save the clipping region correctly when saved 2`] = ` | ||
Array [ | ||
Object { | ||
"props": Object { | ||
"height": 4, | ||
"width": 3, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "rect", | ||
}, | ||
Object { | ||
"props": Object { | ||
"anticlockwise": false, | ||
"endAngle": 5, | ||
"radius": 3, | ||
"startAngle": 4, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "arc", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`__getClippingRegion should store the clipping region 1`] = ` | ||
Array [ | ||
Object { | ||
"props": Object { | ||
"height": 4, | ||
"width": 3, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "rect", | ||
}, | ||
Object { | ||
"props": Object { | ||
"anticlockwise": false, | ||
"endAngle": 5, | ||
"radius": 3, | ||
"startAngle": 4, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "arc", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`__getClippingRegion shouldn't store the whole clipping region twice when clip is called twice 1`] = ` | ||
Array [ | ||
Object { | ||
"props": Object { | ||
"height": 4, | ||
"width": 3, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "rect", | ||
}, | ||
Object { | ||
"props": Object { | ||
"anticlockwise": false, | ||
"endAngle": 5, | ||
"radius": 3, | ||
"startAngle": 4, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "arc", | ||
}, | ||
Object { | ||
"props": Object { | ||
"fillRule": "nonzero", | ||
"path": Array [ | ||
Object { | ||
"props": Object {}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "beginPath", | ||
}, | ||
Object { | ||
"props": Object { | ||
"height": 4, | ||
"width": 3, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "rect", | ||
}, | ||
Object { | ||
"props": Object { | ||
"anticlockwise": false, | ||
"endAngle": 5, | ||
"radius": 3, | ||
"startAngle": 4, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "arc", | ||
}, | ||
], | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "clip", | ||
}, | ||
Object { | ||
"props": Object { | ||
"height": 4, | ||
"width": 3, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "rect", | ||
}, | ||
Object { | ||
"props": Object { | ||
"anticlockwise": false, | ||
"endAngle": 5, | ||
"radius": 3, | ||
"startAngle": 4, | ||
"x": 1, | ||
"y": 2, | ||
}, | ||
"transform": Array [ | ||
1, | ||
0, | ||
0, | ||
1, | ||
0, | ||
0, | ||
], | ||
"type": "arc", | ||
}, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.