Skip to content

Commit

Permalink
fix: rough rect with drop shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Nov 22, 2024
1 parent 4bb17b9 commit d36d02c
Show file tree
Hide file tree
Showing 35 changed files with 338 additions and 124 deletions.
76 changes: 76 additions & 0 deletions __tests__/ssr/rough-rect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,80 @@ describe('RoughRect', () => {
'rough-rect',
);
});

it('should render a rough rect correctly.', async () => {
const rect = new RoughRect({
x: 50,
y: 50,
width: 100,
height: 100,
fill: 'black',
stroke: 'red',
strokeWidth: 2,
});
canvas.appendChild(rect);
canvas.render();

expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot(
dir,
'rough-rect-stroke',
);
expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot(
dir,
'rough-rect-stroke',
);
});

it('should render a rough rect correctly.', async () => {
const rect = new RoughRect({
x: 50,
y: 50,
width: 100,
height: 100,
fill: 'black',
stroke: 'red',
strokeWidth: 2,
dropShadowBlurRadius: 4,
dropShadowColor: 'blue',
dropShadowOffsetX: 5,
dropShadowOffsetY: 5,
});
canvas.appendChild(rect);
canvas.render();

expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot(
dir,
'rough-rect-dropshadow',
);
expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot(
dir,
'rough-rect-dropshadow',
);
});

it('should render a simple rough rect correctly.', async () => {
const rect = new RoughRect({
x: 50,
y: 50,
width: 100,
height: 100,
fill: 'black',
});
canvas.appendChild(rect);
canvas.render();

rect.height = 20;
rect.width = 20;
rect.fillStyle = 'dots';
canvas.render();

expect($canvas.getContext('webgl1')).toMatchWebGLSnapshot(
dir,
'rough-rect-rerender',
);
expect(exporter.toSVG({ grid: true })).toMatchSVGSnapshot(
dir,
'rough-rect-rerender',
);
});
});
Binary file added __tests__/ssr/snapshots/rough-rect-dropshadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions __tests__/ssr/snapshots/rough-rect-dropshadow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/ssr/snapshots/rough-rect-rerender.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions __tests__/ssr/snapshots/rough-rect-rerender.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/ssr/snapshots/rough-rect-stroke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d36d02c

Please sign in to comment.