mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 01:58:27 +00:00
test: init testing for @idraw/core src/lib/context
This commit is contained in:
parent
0963d1c4c0
commit
a9649b2bb5
2 changed files with 141 additions and 0 deletions
108
packages/board/__tests__/lib/__snapshots__/context.test.ts.snap
Normal file
108
packages/board/__tests__/lib/__snapshots__/context.test.ts.snap
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`@idraw/board: src/lib/context Context 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"props": Object {
|
||||
"height": 1600,
|
||||
"width": 2400,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"transform": Array [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"type": "clearRect",
|
||||
},
|
||||
Object {
|
||||
"props": Object {
|
||||
"height": 1600,
|
||||
"width": 2400,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
"transform": Array [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"type": "fillRect",
|
||||
},
|
||||
Object {
|
||||
"props": Object {
|
||||
"height": 480,
|
||||
"width": 800,
|
||||
"x": 40,
|
||||
"y": 40,
|
||||
},
|
||||
"transform": Array [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"type": "fillRect",
|
||||
},
|
||||
Object {
|
||||
"props": Object {
|
||||
"height": 480,
|
||||
"width": 800,
|
||||
"x": 320,
|
||||
"y": 320,
|
||||
},
|
||||
"transform": Array [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"type": "fillRect",
|
||||
},
|
||||
Object {
|
||||
"props": Object {
|
||||
"height": 480,
|
||||
"width": 800,
|
||||
"x": 640,
|
||||
"y": 640,
|
||||
},
|
||||
"transform": Array [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"type": "fillRect",
|
||||
},
|
||||
Object {
|
||||
"props": Object {
|
||||
"height": 400,
|
||||
"width": 800,
|
||||
"x": 1560,
|
||||
"y": 1160,
|
||||
},
|
||||
"transform": Array [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
],
|
||||
"type": "fillRect",
|
||||
},
|
||||
]
|
||||
`;
|
||||
33
packages/board/__tests__/lib/context.test.ts
Normal file
33
packages/board/__tests__/lib/context.test.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import Context from './../../src/lib/context';
|
||||
import { getData } from './../data';
|
||||
|
||||
describe('@idraw/board: src/lib/context', () => {
|
||||
test('Context', async () => {
|
||||
const opts = {
|
||||
width: 600,
|
||||
height: 400,
|
||||
contextWidth: 1000,
|
||||
contextHeight: 900,
|
||||
devicePixelRatio: 4
|
||||
}
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = opts.contextWidth;
|
||||
canvas.height = opts.contextHeight;
|
||||
const ctx2d: CanvasRenderingContext2D = canvas.getContext('2d') as CanvasRenderingContext2D;
|
||||
|
||||
const ctx = new Context(ctx2d, opts);
|
||||
const data = getData();
|
||||
|
||||
ctx.clearRect(0, 0, opts.width, opts.height);
|
||||
ctx.setFillStyle('#ffffff');
|
||||
ctx.fillRect(0, 0, opts.width, opts.height);
|
||||
data.elements.forEach(ele => {
|
||||
ctx.setFillStyle(ele.desc.color);
|
||||
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
||||
});
|
||||
// @ts-ignore;
|
||||
const calls = ctx2d.__getDrawCalls();
|
||||
expect(calls).toMatchSnapshot();
|
||||
});
|
||||
})
|
||||
|
||||
Loading…
Reference in a new issue