Skip to content

Commit

Permalink
history testing on tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Ducret committed Jan 10, 2018
1 parent 50fc37d commit 5e7c491
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/client/ts/tools/eyedropperTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export class EyedropperTool extends Tool {

endUse(pos: Vec2) {
this.continueUse(pos);
this.icon.removeAttribute("style");
if (this.icon != null) {
this.icon.removeAttribute("style");
}
}

drawPreview(layer: Layer) {
Expand Down
33 changes: 33 additions & 0 deletions test/test-tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Vec2} from "../src/client/ts/vec2";
import {Project} from "../src/client/ts/docState";
import {ActionInterface} from "../src/client/ts/tools/actionInterface";

describe('History', function () {
let w = 20;
let h = 20;
let randPos = function () {
return new Vec2(Math.floor(Math.random() * w), Math.floor(Math.random() * h));
};
let proj = new Project(null, 'test project', new Vec2(w, h));
for (let t of proj.toolRegistry.getTools()) {
let need_ui = false;
for (let req of t.getSettings().getRequests()) {
if (req.name == "user_interface") {
need_ui = true;
}
}
if (!need_ui) {
it('works with tool ' + t.getName(), async function () {
proj.currentLayer.reset();
let initState = proj.currentLayer.getHTMLElement().toDataURL();
t.startUse(proj.currentLayer.getContext().getImageData(0, 0, w, h), randPos());
t.continueUse(randPos());
t.endUse(randPos());
let undo: Promise<ActionInterface> = t.applyTool(proj.currentLayer, true);
proj.link.sendAction(await undo);
let endState = proj.currentLayer.getHTMLElement().toDataURL();
expect(initState).toEqual(endState);
});
}
}
});

0 comments on commit 5e7c491

Please sign in to comment.