mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 01:44:19 +01:00
add segment remove test
This commit is contained in:
parent
a8de4bac42
commit
584b295463
4 changed files with 30 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import * as test from '../test'
|
||||
import * as sketcher_utils from '../utils/sketcher-utils'
|
||||
import * as keyboard from '../utils/keyboard'
|
||||
import {TestMouseEvent} from '../utils/mouse-event'
|
||||
import Vector from '../../app/math/vector';
|
||||
|
||||
|
|
@ -47,7 +48,7 @@ export default {
|
|||
test.emptySketch(env.test((win, app) => {
|
||||
addSegment(app, 10, 10, 100, 100);
|
||||
env.assertEquals(0, app.viewer.selected.length);
|
||||
sketcher_utils.click(app.viewer.toolManager.tool, 50, 50);
|
||||
sketcher_utils.click(app, 50, 50);
|
||||
env.assertEquals(1, app.viewer.selected.length);
|
||||
env.done();
|
||||
}));
|
||||
|
|
@ -58,8 +59,21 @@ export default {
|
|||
addSegment(app, 10, 10, 100, 100);
|
||||
env.assertEquals(0, app.viewer.selected.length);
|
||||
// this point technically isn't on the line but should trigger the selection
|
||||
sketcher_utils.click(app.viewer.toolManager.tool, 55, 50);
|
||||
sketcher_utils.click(app, 55, 50);
|
||||
env.assertEquals(1, app.viewer.selected.length);
|
||||
env.assertEquals('TCAD.TWO.Segment', app.viewer.selected[0]._class);
|
||||
env.done();
|
||||
}));
|
||||
},
|
||||
|
||||
testRemove: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
const segment = addSegment(app, 10, 10, 100, 100);
|
||||
env.assertEquals(1, app.viewer.activeLayer.objects.length);
|
||||
sketcher_utils.click(app, 50, 50);
|
||||
const keyboardEvent = keyboard.keyCode('keydown', 8);
|
||||
win.dispatchEvent(keyboardEvent);
|
||||
env.assertEquals(0, app.viewer.activeLayer.objects.length);
|
||||
env.done();
|
||||
}));
|
||||
},
|
||||
|
|
@ -116,13 +130,14 @@ export default {
|
|||
sketcher_utils.move(app, from, from.plus(moveDelta));
|
||||
env.assertPoint2DEquals(sketcher_utils.toModelP(app, initA.plus(moveDelta)), segment.a);
|
||||
env.assertPoint2DEquals(sketcher_utils.toModelP(app, initB.plus(moveDelta)), segment.b);
|
||||
env.assertEquals('TCAD.TWO.Segment', app.viewer.selected[0]._class);
|
||||
env.done();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
function vec() {
|
||||
return new Vector(arguments);
|
||||
function vec(x, y, z) {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
function collectObjects(visitable) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ export class TestEnv {
|
|||
}
|
||||
|
||||
done() {
|
||||
if (this.finished) {
|
||||
return;
|
||||
}
|
||||
this.finished = true;
|
||||
this.took = performance.now() - this.took;
|
||||
this.callback(this);
|
||||
|
|
|
|||
5
web/test/utils/keyboard.js
Normal file
5
web/test/utils/keyboard.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export function keyCode(eventType, value) {
|
||||
const keyboardEvent = new KeyboardEvent(eventType, {bubbles:true});
|
||||
Object.defineProperty(keyboardEvent, "keyCode", {value});
|
||||
return keyboardEvent;
|
||||
}
|
||||
|
|
@ -12,9 +12,9 @@ export function getConstraints(app) {
|
|||
return app.viewer.parametricManager.subSystems[0].constraints;
|
||||
}
|
||||
|
||||
export function click(tool, x, y) {
|
||||
tool.mousedown(new TestMouseEvent(x, y));
|
||||
tool.mouseup(new TestMouseEvent(x, y));
|
||||
export function click(app, x, y) {
|
||||
app.viewer.toolManager.tool.mousedown(new TestMouseEvent(x, y));
|
||||
app.viewer.toolManager.tool.mouseup(new TestMouseEvent(x, y));
|
||||
}
|
||||
|
||||
export function move(app, from, to) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue