mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-24 01:15:25 +01:00
add more test cases for segments
This commit is contained in:
parent
6324218664
commit
a8de4bac42
4 changed files with 138 additions and 33 deletions
|
|
@ -1,76 +1,129 @@
|
|||
import * as test from '../test'
|
||||
import * as sketcher_utils from '../utils/sketcher-utils'
|
||||
import {TestMouseEvent} from '../utils/mouse-event'
|
||||
import Vector from '../../app/math/vector';
|
||||
|
||||
function addSegment(app, aX, aY, bX, bY) {
|
||||
app.actions['addSegment'].action();
|
||||
app.viewer.toolManager.tool.mouseup(new TestMouseEvent(aX, aY));
|
||||
app.viewer.toolManager.tool.mousemove(new TestMouseEvent(bX, bY));
|
||||
app.viewer.toolManager.tool.mouseup(new TestMouseEvent(bX, bY));
|
||||
const tool = app.viewer.toolManager.tool;
|
||||
tool.mousemove(new TestMouseEvent(aX, aY));
|
||||
tool.mouseup(new TestMouseEvent(aX, aY));
|
||||
tool.mousemove(new TestMouseEvent(bX, bY));
|
||||
const segment = tool.line;
|
||||
tool.mouseup(new TestMouseEvent(bX, bY));
|
||||
app.viewer.toolManager.releaseControl();
|
||||
}
|
||||
|
||||
function click(tool, x, y) {
|
||||
tool.mousedown(new TestMouseEvent(x, y));
|
||||
tool.mouseup(new TestMouseEvent(x, y));
|
||||
return segment;
|
||||
}
|
||||
|
||||
export default {
|
||||
testSegmentWizard: function(env) {
|
||||
const win = test.emptySketch((win, app) => {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
env.assertEquals(0, app.viewer.activeLayer.objects.length);
|
||||
addSegment(app, 10, 10, 100, 100);
|
||||
env.assertEquals(1, app.viewer.activeLayer.objects.length);
|
||||
const segment = app.viewer.activeLayer.objects[0];
|
||||
env.assertEquals('TCAD.TWO.Segment', segment._class);
|
||||
env.assertPoint2DEquals(10, 10, segment.a);
|
||||
env.assertPoint2DEquals(101, 100, segment.b);
|
||||
env.assertPoint2DEquals(sketcher_utils.toModel(app, 10, 10), segment.a);
|
||||
env.assertPoint2DEquals(sketcher_utils.toModel(app, 100, 100), segment.b);
|
||||
env.done();
|
||||
});
|
||||
}));
|
||||
},
|
||||
|
||||
testSaveLoad: function(env) {
|
||||
test.emptySketch((win, app) => {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
env.assertEquals(0, app.viewer.activeLayer.objects.length);
|
||||
addSegment(app, 10, 10, 100, 100);
|
||||
app.actions['save'].action();
|
||||
test.sketch((win, app) => {
|
||||
test.sketch(env.test((win, app) => {
|
||||
env.assertEquals(1, app.viewer.activeLayer.objects.length);
|
||||
const segment = app.viewer.activeLayer.objects[0];
|
||||
env.assertEquals('TCAD.TWO.Segment', segment._class);
|
||||
env.done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
},
|
||||
|
||||
testSelection: function(env) {
|
||||
test.emptySketch((win, app) => {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
addSegment(app, 10, 10, 100, 100);
|
||||
env.assertEquals(0, app.viewer.selected.length);
|
||||
click(app.viewer.toolManager.tool, 50, 50);
|
||||
sketcher_utils.click(app.viewer.toolManager.tool, 50, 50);
|
||||
env.assertEquals(1, app.viewer.selected.length);
|
||||
env.done();
|
||||
});
|
||||
}));
|
||||
},
|
||||
|
||||
testSelectionNeighborhood: function(env) {
|
||||
test.emptySketch((win, app) => {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
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
|
||||
click(app.viewer.toolManager.tool, 55, 50);
|
||||
sketcher_utils.click(app.viewer.toolManager.tool, 55, 50);
|
||||
env.assertEquals(1, app.viewer.selected.length);
|
||||
env.done();
|
||||
});
|
||||
}));
|
||||
},
|
||||
|
||||
testSnap: function(env) {
|
||||
test.emptySketch((win, app) => {
|
||||
env.fail('implement me');
|
||||
});
|
||||
}
|
||||
testSnapFirstPoint: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
const s1 = addSegment(app, 10, 10, 100, 100);
|
||||
const s2 = addSegment(app, 102, 102, 50, 10);
|
||||
const constraints = sketcher_utils.getConstraints(app);
|
||||
env.assertEquals(1, constraints.length);
|
||||
env.assertEquals('coi', constraints[0].NAME);
|
||||
env.assertEquals(1, s1.b.linked.length);
|
||||
env.assertEquals(1, s2.a.linked.length);
|
||||
env.assertEquals(s1.b.linked[0], s2.a);
|
||||
env.assertEquals(s2.a.linked[0], s1.b);
|
||||
env.done();
|
||||
}));
|
||||
},
|
||||
|
||||
testSnapSecondPoint: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
const s1 = addSegment(app, 10, 10, 100, 100);
|
||||
const s2 = addSegment(app, 50, 10, 102, 102);
|
||||
const constraints = sketcher_utils.getConstraints(app);
|
||||
env.assertEquals(1, constraints.length);
|
||||
env.assertEquals('coi', constraints[0].NAME);
|
||||
env.assertEquals(1, s1.b.linked.length);
|
||||
env.assertEquals(1, s2.b.linked.length);
|
||||
env.assertEquals(s1.b.linked[0], s2.b);
|
||||
env.assertEquals(s2.b.linked[0], s1.b);
|
||||
env.done();
|
||||
}));
|
||||
},
|
||||
|
||||
testEndPointMove: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
const segment = addSegment(app, 10, 10, 100, 100);
|
||||
sketcher_utils.move(app, vec(100, 100), vec(200, 150));
|
||||
//should be still
|
||||
env.assertPoint2DEquals(sketcher_utils.toModel(app, 10, 10), segment.a);
|
||||
//should be moved
|
||||
env.assertPoint2DEquals(sketcher_utils.toModel(app, 200, 150), segment.b);
|
||||
env.done();
|
||||
}));
|
||||
},
|
||||
|
||||
testLineMove: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
const initA = vec(10, 10);
|
||||
const initB = vec(100, 100);
|
||||
const segment = addSegment(app, initA.x, initA.y, initB.x, initB.y);
|
||||
const from = vec(50, 50);
|
||||
const moveDelta = vec(100, 50);
|
||||
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.done();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
function vec() {
|
||||
return new Vector(arguments);
|
||||
}
|
||||
|
||||
function collectObjects(visitable) {
|
||||
const objects = [];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
export function FailError(msg) {
|
||||
this.msg = msg;
|
||||
this.stack = (new Error()).stack;
|
||||
}
|
||||
|
||||
export class TestEnv {
|
||||
|
|
@ -26,6 +27,28 @@ export class TestEnv {
|
|||
throw new FailError(this.error);
|
||||
}
|
||||
|
||||
terminateOnError(error) {
|
||||
this.failed = true;
|
||||
this.error = error + "";
|
||||
this.done();
|
||||
throw error;
|
||||
}
|
||||
|
||||
test(testBlock) {
|
||||
const env = this;
|
||||
return function() {
|
||||
try {
|
||||
testBlock.apply(this, arguments);
|
||||
} catch (e) {
|
||||
if (!env.finished) {
|
||||
env.terminateOnError(e);
|
||||
}
|
||||
console.error(e.stack);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(stmt, msg) {
|
||||
if (!stmt) {
|
||||
this.fail('assertTrue fails.', msg);
|
||||
|
|
@ -37,11 +60,15 @@ export class TestEnv {
|
|||
}
|
||||
}
|
||||
|
||||
assertPoint2DEquals(expectedX, expectedY, actial, msg) {
|
||||
if (actial.x !== expectedX || actial.y !== expectedY) {
|
||||
this.fail('assertPoint2DEquals: Expected: (' + expectedX + ', ' + expectedY + ') but was (' + actial.x + ', ' + actial.y + ')' , msg);
|
||||
assertPointXY2DEquals(expectedX, expectedY, actual, msg) {
|
||||
if (actual.x !== expectedX || actual.y !== expectedY) {
|
||||
this.fail('assertPoint2DEquals: Expected: (' + expectedX + ', ' + expectedY + ') but was (' + actual.x + ', ' + actual.y + ')' , msg);
|
||||
}
|
||||
}
|
||||
|
||||
assertPoint2DEquals(expected, actial, msg) {
|
||||
this.assertPointXY2DEquals(expected.x, expected.y, actial, msg);
|
||||
}
|
||||
}
|
||||
|
||||
export function load(url, callback) {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
{{#eachInMap suites}}
|
||||
<div class="suite-node" id="suite-{{key}}">
|
||||
<span class="status"><i class="fa fa-circle"></i></span>
|
||||
<span class="right-click-menu" data-menu="RunSuite" data-suite-name="{{key}}">
|
||||
<span class="right-click-menu action-item" data-action="RunSuite" data-menu="RunSuite" data-suite-name="{{key}}">
|
||||
<b>{{key}}</b>
|
||||
</span>
|
||||
{{#value}}
|
||||
<div class="test-case-node" id="case-{{../key}}-{{name}}" style="margin-left: 15px;">
|
||||
<span class="status"><i class="fa fa-circle"></i></span>
|
||||
<span class="right-click-menu" data-menu="RunTestCase" data-test-case-id="{{../key}}:{{name}}">
|
||||
<span class="right-click-menu action-item" data-action="RunTestCase" data-menu="RunTestCase" data-test-case-id="{{../key}}:{{name}}">
|
||||
{{name}}
|
||||
</span>
|
||||
{{#tests}}
|
||||
<div class="test-node" id="test-{{../../key}}-{{../name}}-{{name}}" style="margin-left: 30px;">
|
||||
<span class="status"><i class="fa fa-circle"></i></span>
|
||||
<span class="progress" style="display: none"><i class="fa fa-cog fa-spin"></i></span>
|
||||
<span class="right-click-menu" data-menu="RunTest" data-test-id="{{../../key}}:{{../name}}:{{name}}">
|
||||
<span class="right-click-menu action-item" data-action="RunTest" data-menu="RunTest" data-test-id="{{../../key}}:{{../name}}:{{name}}">
|
||||
{{name}}
|
||||
<span class="result"></span>
|
||||
</span>
|
||||
|
|
|
|||
25
web/test/utils/sketcher-utils.js
Normal file
25
web/test/utils/sketcher-utils.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import {TestMouseEvent} from './mouse-event'
|
||||
|
||||
export function toModel(app, x, y) {
|
||||
return app.viewer._screenToModel(x, y);
|
||||
}
|
||||
|
||||
export function toModelP(app, point) {
|
||||
return app.viewer._screenToModel(point.x, point.y);
|
||||
}
|
||||
|
||||
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 move(app, from, to) {
|
||||
const toolManager = app.viewer.toolManager;
|
||||
toolManager.tool.mousedown(new TestMouseEvent(from.x, from.y));
|
||||
toolManager.tool.mousemove(new TestMouseEvent(to.x, to.y));
|
||||
toolManager.tool.mouseup(new TestMouseEvent(to.x, to.y));
|
||||
}
|
||||
Loading…
Reference in a new issue