mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-24 09:26:43 +01:00
fix a segment test
This commit is contained in:
parent
e68aa71c95
commit
6d06343f53
10 changed files with 152 additions and 140 deletions
|
|
@ -2,7 +2,7 @@ import {camelCaseSplitToStr} from "gems/camelCaseSplit";
|
|||
import {TestEnv} from "./test";
|
||||
import {ModesConfig} from "./modes";
|
||||
|
||||
export function defineCypressTest(groupName, module) {
|
||||
export function defineCypressTests(groupName, module) {
|
||||
|
||||
if (!module.TEST_MODE) {
|
||||
throw 'modules should have a mode defined';
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ export const ModesConfig = {
|
|||
},
|
||||
sketcherUI: {
|
||||
testSubject: win => createSketcherSubject(win.__CAD_APP),
|
||||
startPage: 'http://localhost:3000/index.html#TestProject'
|
||||
startPage: 'http://localhost:3000/sketcher.html#TestProject'
|
||||
},
|
||||
};
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import * as sketcher_utils from '../utils/sketcherUtils'
|
||||
import {decapitalize} from '../../../modules/gems/capitalize';
|
||||
import genSerpinski, {genSerpinskiImpl} from '../../../web/app/utils/genSerpinski';
|
||||
import {distance, distanceAB} from '../../../web/app/math/math';
|
||||
import {genSerpinskiImpl} from '../../../web/app/utils/genSerpinski';
|
||||
import {distance} from '../../../web/app/math/math';
|
||||
|
||||
export function createSubjectFromInPlaceSketcher(ctx) {
|
||||
let actions = {};
|
||||
|
|
@ -92,10 +92,14 @@ export function createSketcherSubject(sketcherApp) {
|
|||
function runAction(id) {
|
||||
sketcherApp.actions[id].action();
|
||||
}
|
||||
|
||||
function toModel(x, y) {
|
||||
return sketcher_utils.toModel(sketcherApp, x, y);
|
||||
}
|
||||
|
||||
return {
|
||||
addSegment, addRectangle, addArc, addCircle, addEllipse, addEllipticalArc, addSerpinski, addBezier, addPolygon,
|
||||
move, changeLayer, changeToConstructionLayer, changeToDefaultLayer,
|
||||
move, changeLayer, changeToConstructionLayer, changeToDefaultLayer, toModel,
|
||||
click, select, runAction,
|
||||
viewer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,129 +1,126 @@
|
|||
import * as test from '../test'
|
||||
import * as sketcher_utils from '../utils/sketcherUtils'
|
||||
import * as keyboard from '../utils/keyboard'
|
||||
import {TestMouseEvent} from '../utils/mouseEvent'
|
||||
import Vector from 'math/vector';
|
||||
|
||||
export default {
|
||||
testSegmentWizard: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
env.assertEquals(0, app.viewer.activeLayer.objects.length);
|
||||
sketcher_utils.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(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(env.test((win, app) => {
|
||||
env.assertEquals(0, app.viewer.activeLayer.objects.length);
|
||||
sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
app.actions['save'].action();
|
||||
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(env.test((win, app) => {
|
||||
sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
env.assertEquals(0, app.viewer.selected.length);
|
||||
sketcher_utils.clickXY(app, 50, 50);
|
||||
env.assertEquals(1, app.viewer.selected.length);
|
||||
env.done();
|
||||
}));
|
||||
},
|
||||
|
||||
testSelectionNeighborhood: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
sketcher_utils.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.clickXY(app, 55, 50);
|
||||
env.assertEquals(1, app.viewer.selected.length);
|
||||
env.assertEquals('TCAD.TWO.Segment', app.viewer.selected[0]._class);
|
||||
env.done();
|
||||
}));
|
||||
},
|
||||
export const TEST_MODE = 'sketcherUI';
|
||||
|
||||
testRemove: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
const segment = sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
env.assertEquals(1, app.viewer.activeLayer.objects.length);
|
||||
sketcher_utils.clickXY(app, 50, 50);
|
||||
const keyboardEvent = keyboard.keyCode('keydown', 8);
|
||||
win.dispatchEvent(keyboardEvent);
|
||||
env.assertEquals(0, app.viewer.activeLayer.objects.length);
|
||||
env.done();
|
||||
}));
|
||||
},
|
||||
export function testSegmentWizard(env, test) {
|
||||
env.assertEquals(0, test.viewer.activeLayer.objects.length);
|
||||
test.addSegment(10, 10, 100, 100);
|
||||
|
||||
testSnapFirstPoint: function(env) {
|
||||
test.emptySketch(env.test((win, app) => {
|
||||
const s1 = sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
const s2 = sketcher_utils.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 = sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
const s2 = sketcher_utils.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 = sketcher_utils.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 = sketcher_utils.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.assertEquals('TCAD.TWO.Segment', app.viewer.selected[0]._class);
|
||||
env.done();
|
||||
}));
|
||||
}
|
||||
env.assertEquals(1, test.viewer.activeLayer.objects.length);
|
||||
const segment = test.viewer.activeLayer.objects[0];
|
||||
env.assertEquals('TCAD.TWO.Segment', segment._class);
|
||||
env.assertPoint2DEquals(test.toModel(10, 10), segment.a);
|
||||
env.assertPoint2DEquals(test.toModel(100, 100), segment.b);
|
||||
env.done();
|
||||
}
|
||||
|
||||
// testSaveLoad: function(env) {
|
||||
// test.emptySketch(env.test((win, app) => {
|
||||
// env.assertEquals(0, app.viewer.activeLayer.objects.length);
|
||||
// sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
// app.actions['save'].action();
|
||||
// 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(env.test((win, app) => {
|
||||
// sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
// env.assertEquals(0, app.viewer.selected.length);
|
||||
// sketcher_utils.clickXY(app, 50, 50);
|
||||
// env.assertEquals(1, app.viewer.selected.length);
|
||||
// env.done();
|
||||
// }));
|
||||
// },
|
||||
//
|
||||
// testSelectionNeighborhood: function(env) {
|
||||
// test.emptySketch(env.test((win, app) => {
|
||||
// sketcher_utils.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.clickXY(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 = sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
// env.assertEquals(1, app.viewer.activeLayer.objects.length);
|
||||
// sketcher_utils.clickXY(app, 50, 50);
|
||||
// const keyboardEvent = keyboard.keyCode('keydown', 8);
|
||||
// win.dispatchEvent(keyboardEvent);
|
||||
// env.assertEquals(0, app.viewer.activeLayer.objects.length);
|
||||
// env.done();
|
||||
// }));
|
||||
// },
|
||||
//
|
||||
// testSnapFirstPoint: function(env) {
|
||||
// test.emptySketch(env.test((win, app) => {
|
||||
// const s1 = sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
// const s2 = sketcher_utils.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 = sketcher_utils.addSegment(app, 10, 10, 100, 100);
|
||||
// const s2 = sketcher_utils.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 = sketcher_utils.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 = sketcher_utils.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.assertEquals('TCAD.TWO.Segment', app.viewer.selected[0]._class);
|
||||
// env.done();
|
||||
// }));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
function vec(x, y, z) {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ export function moveInModel(app, fromX, fromY, toX, toY) {
|
|||
|
||||
|
||||
export function addSegment(app, aX, aY, bX, bY) {
|
||||
app.actions['addSegment'].action();
|
||||
app.actions.SegmentTool.invoke(app.context);
|
||||
const tool = app.viewer.toolManager.tool;
|
||||
tool.mousemove(new TestMouseEvent(aX, aY));
|
||||
tool.mousedown(new TestMouseEvent(aX, aY));
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@ import * as LoftTests from '../../../coreTests/testCases/craftLoft';
|
|||
import * as DatumTests from '../../../coreTests/testCases/craftDatum';
|
||||
import * as BooleanTests from '../../../coreTests/testCases/craftBoolean';
|
||||
|
||||
import {defineCypressTest} from "../../../coreTests/defineCypress";
|
||||
import {defineCypressTests} from "../../../coreTests/defineCypress";
|
||||
|
||||
describe("Craft Operations", () => {
|
||||
defineCypressTest("Plane Operation", PlaneTests);
|
||||
defineCypressTest("Extrude - all sketcher objects", ExtrudeBasicShapesTests);
|
||||
defineCypressTest("Extrude Options", ExtrudeOptionsTests);
|
||||
defineCypressTest("Extrude Operation", ExtrudeTests);
|
||||
defineCypressTest("Cut Operation", CutTests);
|
||||
defineCypressTest("Revolve Operation", RevolveTests);
|
||||
defineCypressTest("Fillet Operation", FilletTests);
|
||||
defineCypressTest("Loft Operation", LoftTests);
|
||||
defineCypressTest("Datum Operation", DatumTests);
|
||||
defineCypressTest("General Boolean Operation", BooleanTests);
|
||||
defineCypressTests("Plane Operation", PlaneTests);
|
||||
defineCypressTests("Extrude - all sketcher objects", ExtrudeBasicShapesTests);
|
||||
defineCypressTests("Extrude Options", ExtrudeOptionsTests);
|
||||
defineCypressTests("Extrude Operation", ExtrudeTests);
|
||||
defineCypressTests("Cut Operation", CutTests);
|
||||
defineCypressTests("Revolve Operation", RevolveTests);
|
||||
defineCypressTests("Fillet Operation", FilletTests);
|
||||
defineCypressTests("Loft Operation", LoftTests);
|
||||
defineCypressTests("Datum Operation", DatumTests);
|
||||
defineCypressTests("General Boolean Operation", BooleanTests);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
5
test/cypress/integration/sketcher/tools/segment.spec.js
Normal file
5
test/cypress/integration/sketcher/tools/segment.spec.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import {defineCypressTests} from "../../../../coreTests/defineCypress";
|
||||
import * as SegmentToolTests from "../../../../coreTests/testCases/segment";
|
||||
|
||||
|
||||
defineCypressTests("Segment Tool", SegmentToolTests);
|
||||
|
|
@ -56,6 +56,10 @@ export function getAllSketcherActions() {
|
|||
return ALL_ACTIONS;
|
||||
}
|
||||
|
||||
export function getSketcherActionIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
//For backward compatibility
|
||||
export function runActionOrToastWhyNot(actionId, ctx, silent) {
|
||||
const selection = ctx.viewer.selected;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import React from "react";
|
|||
import {stream, state} from "lstream";
|
||||
import {Dock, dockBtn} from "./components/Dock";
|
||||
import {DIRECTIONS, ResizeHelper} from "../../../modules/ui/components/Window";
|
||||
import {getSketcherAction} from "./actions";
|
||||
import {getAllSketcherActions, getSketcherAction, getSketcherActionIndex} from "./actions";
|
||||
|
||||
class App2D {
|
||||
|
||||
|
|
@ -15,11 +15,13 @@ class App2D {
|
|||
this.context = createAppContext(this.viewer, this);
|
||||
this.inputManager = new InputManager(this);
|
||||
|
||||
this.actions = {};
|
||||
|
||||
this.initNonReactUIParts();
|
||||
}
|
||||
|
||||
get actions() {
|
||||
return getSketcherActionIndex();
|
||||
}
|
||||
|
||||
fit() {
|
||||
|
||||
const bbox = new BBox();
|
||||
|
|
|
|||
Loading…
Reference in a new issue