Skip to content

Commit

Permalink
Allow draw after clear
Browse files Browse the repository at this point in the history
  • Loading branch information
flbulgarelli committed Feb 15, 2023
1 parent d015591 commit d782f67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class Canvas {
/** @type {(image: import('./image-metadata').ImageMetadata) => import('./image-metadata').ImageMetadata} */
this._imageAdjuster = itself;
this._outline = outline || Classic;
this._drawn = false;
}

_initialize() {
Expand All @@ -154,6 +153,7 @@ class Canvas {
this.templates = {};
/** @type {import('./vector').Vector} */
this._figurePadding = null;
this._drawn = false;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions test/canvas-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ describe("Canvas", () => {
assert.deepEqual(canvas.puzzle.head.centralAnchor, {x: 50, y: 50});
})

it("can not draw a canvas twice", () => {
const canvas = new Canvas('canvas', {
width: 800, height: 800,
painter: painter
})

canvas.sketchPiece({
structure: {right: Tab, down: Tab, left: Slot},
metadata: {}
});

canvas.draw();
assert.throws(() => canvas.draw());
})

it("can create a single-piece puzzle with size overriden ", () => {
const canvas = new Canvas('canvas', {
width: 800, height: 800,
Expand Down Expand Up @@ -265,10 +280,12 @@ describe("Canvas", () => {
canvas.draw();
canvas.clear();

assert.equal(canvas._drawn, false);
assert.equal(canvas._painter, painter);
assert.equal(canvas._puzzle, null);
assert.equal(canvas.puzzle.pieces.length, 0);
assert.deepEqual(canvas.figures, {});
assert.doesNotThrow(() => canvas.draw());
})

it("can sketch a whole puzzle", () => {
Expand Down

0 comments on commit d782f67

Please sign in to comment.