mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-25 07:47:55 +01:00
Increase coverage migrating tests.
This commit is contained in:
parent
695dd71921
commit
25b86f3cff
@ -8,7 +8,7 @@ module.exports = {
|
||||
publicPath: '',
|
||||
library: {
|
||||
type: 'umd',
|
||||
},
|
||||
}
|
||||
},
|
||||
target: 'web',
|
||||
module: {
|
||||
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"commonjs": true
|
||||
"commonjs": true,
|
||||
"jest": true
|
||||
},
|
||||
"extends": [
|
||||
"airbnb-base",
|
||||
@ -15,6 +16,7 @@
|
||||
},
|
||||
"plugins": ["only-warn"],
|
||||
"rules": {
|
||||
"no-underscore-dangle": "off",
|
||||
"no-plusplus": "off",
|
||||
"class-methods-use-this": "off",
|
||||
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["!cypress/**/*.js"]}]
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 304 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 MiB |
23
packages/mindplot/jest.config.js
Normal file
23
packages/mindplot/jest.config.js
Normal file
@ -0,0 +1,23 @@
|
||||
// Sync object
|
||||
/** @type {import('@jest/types').Config.InitialOptions} */
|
||||
const config = {
|
||||
testEnvironment: 'jsdom',
|
||||
verbose: true,
|
||||
moduleFileExtensions: ['js'],
|
||||
transform: {
|
||||
'^.+\\.js?$': 'babel-jest',
|
||||
},
|
||||
moduleNameMapper: {
|
||||
'^@libraries(.*)$': '<rootDir>../../libraries$1',
|
||||
'^@commands(.*)$': '<rootDir>/src/components/commands$1',
|
||||
'^@layout(.*)$': '<rootDir>/src/components/layout$1',
|
||||
'^@libs(.*)$': '<rootDir>/src/components/libraries$1',
|
||||
'^@model(.*)$': '<rootDir>/src/components/model$1',
|
||||
'^@persistence(.*)$': '<rootDir>/src/components/persistence$1',
|
||||
'^@util(.*)$': '<rootDir>/src/components/util$1',
|
||||
'^@widget(.*)$': '<rootDir>/src/components/widget$1',
|
||||
'^@components(.*)$': '<rootDir>/src/components$1',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = config;
|
@ -26,19 +26,21 @@
|
||||
"playground": "webpack serve --config webpack.playground.js",
|
||||
"cy:run": "cypress run",
|
||||
"cy:run:update": "cypress run --env updateSnapshots=true",
|
||||
"test:jest": "jest ./test/unit/*.js",
|
||||
"test:snapshots": "start-server-and-test playground http-get://localhost:8081 cy:run",
|
||||
"test:snapshots:update": "start-server-and-test playground http-get://localhost:8081 cy:run:update"
|
||||
},
|
||||
"dependencies": {
|
||||
"@wisemapping/core-js": "^0.0.1",
|
||||
"@wisemapping/web2d": "^0.0.1",
|
||||
"jest": "^27.4.3",
|
||||
"jquery": "^3.6.0",
|
||||
"mootools": "1.4.5",
|
||||
"mootools": "1.4.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.14.6",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.14.5",
|
||||
"@babel/preset-env": "^7.14.7",
|
||||
"@babel/register": "^7.16.0",
|
||||
"babel-loader": "^8.2.2",
|
||||
"clean-webpack-plugin": "^4.0.0-alpha.0",
|
||||
"copy-webpack-plugin": "^10.0.0",
|
||||
@ -53,6 +55,8 @@
|
||||
"eslint-plugin-import": "^2.24.2",
|
||||
"eslint-plugin-only-warn": "^1.0.3",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"jest-webpack": "^0.5.1",
|
||||
"mocha": "^9.1.3",
|
||||
"less": "^4.1.2",
|
||||
"less-loader": "^10.2.0",
|
||||
"nodemon": "^2.0.12",
|
||||
|
@ -15,9 +15,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import * as web2d from '@wisemapping/web2d';
|
||||
|
||||
import INodeModel, { TopicShape } from './model/INodeModel';
|
||||
import TopicConfig from './TopicConfig';
|
||||
|
||||
|
@ -43,6 +43,7 @@ import { create } from './NodeGraphUtils';
|
||||
|
||||
import EventBus from './layout/EventBus';
|
||||
import EventBusDispatcher from './layout/EventBusDispatcher';
|
||||
|
||||
import LayoutManager from './layout/LayoutManager';
|
||||
|
||||
import INodeModel, { TopicShape } from './model/INodeModel';
|
||||
|
@ -105,6 +105,7 @@ class Relationship extends ConnectionLine {
|
||||
ctrlPoints[1].x = defaultPoints[1].x;
|
||||
ctrlPoints[1].y = defaultPoints[1].y;
|
||||
}
|
||||
|
||||
const spoint = new web2d.Point();
|
||||
spoint.x = parseInt(ctrlPoints[0].x, 10) + parseInt(sourcePosition.x, 10);
|
||||
spoint.y = parseInt(ctrlPoints[0].y, 10) + parseInt(sourcePosition.y, 10);
|
||||
|
@ -88,7 +88,7 @@ class RelationshipPivot {
|
||||
|
||||
topics.forEach(((topic) => {
|
||||
topic.removeEvent('ontfocus', this._onTopicClick);
|
||||
}).bind(this));
|
||||
}));
|
||||
|
||||
workspace.removeChild(this._pivot);
|
||||
workspace.removeChild(this._startArrow);
|
||||
|
@ -31,6 +31,7 @@ import ShirinkConnector from './ShrinkConnector';
|
||||
import NoteEditor from './widget/NoteEditor';
|
||||
import ActionDispatcher from './ActionDispatcher';
|
||||
import LinkEditor from './widget/LinkEditor';
|
||||
|
||||
import TopicEventDispatcher, { TopicEvent } from './TopicEventDispatcher';
|
||||
import INodeModel, { TopicShape } from './model/INodeModel';
|
||||
|
||||
@ -769,7 +770,7 @@ class Topic extends NodeGraph {
|
||||
text: value,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
const editor = new NoteEditor(editorModel);
|
||||
this.closeEditors();
|
||||
@ -805,7 +806,7 @@ class Topic extends NodeGraph {
|
||||
url: value,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
this.closeEditors();
|
||||
|
@ -1,6 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
@ -18,5 +17,4 @@
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
29
packages/mindplot/test/playground/lib/raphael-plugins.js
Normal file
29
packages/mindplot/test/playground/lib/raphael-plugins.js
Normal file
@ -0,0 +1,29 @@
|
||||
Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) {
|
||||
color = color || '#999';
|
||||
let path = ['M', x, y, 'L', x + w, y, x + w, y + h, x, y + h, x, y];
|
||||
const rowHeight = h / hv;
|
||||
const columnWidth = w / wv;
|
||||
for (var i = 0; i < hv + 1; i++) {
|
||||
var offset = y + i * rowHeight;
|
||||
path = this.path(['M', x, offset, 'L', x + w, y + i * rowHeight]);
|
||||
if (offset == 0 || offset == h) {
|
||||
path.attr({ stroke: '#000' });
|
||||
} else if (offset == h / 2) {
|
||||
path.attr({ stroke: '#c00' });
|
||||
} else {
|
||||
path.attr({ stroke: '#999' });
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < wv + 1; i++) {
|
||||
var offset = x + i * columnWidth;
|
||||
path = this.path(['M', offset, y, 'L', x + i * columnWidth, y + h]);
|
||||
if (offset == 0 || offset == w) {
|
||||
path.attr({ stroke: '#000' });
|
||||
} else if (offset == w / 2) {
|
||||
path.attr({ stroke: '#c00' });
|
||||
} else {
|
||||
path.attr({ stroke: '#999' });
|
||||
}
|
||||
}
|
||||
return this.path;
|
||||
};
|
@ -1,282 +0,0 @@
|
||||
import LayoutManager from '../../../src/components/layout/LayoutManager';
|
||||
|
||||
describe('Balanced Test Suite', () => {
|
||||
it('balancedTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 1, 0);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 2, 1);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(3, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 3, 2);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(4, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 4, 3);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(5, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 5, 4);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(6, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 6, 5);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(7, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(8, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(9, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(3, 7, 0);
|
||||
manager.connectNode(7, 8, 0);
|
||||
manager.connectNode(7, 9, 1);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(10, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(11, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(12, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(6, 10, 0);
|
||||
manager.connectNode(10, 11, 0);
|
||||
manager.connectNode(10, 12, 1);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(13, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 13, 4);
|
||||
manager.layout();
|
||||
|
||||
// Check orders have shifted accordingly
|
||||
expect(manager.find(5).getOrder()).toEqual(6);
|
||||
|
||||
manager.addNode(14, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 14, 5);
|
||||
manager.layout();
|
||||
|
||||
// Check orders have shifted accordingly
|
||||
expect(manager.find(6).getOrder()).toEqual(7);
|
||||
|
||||
manager.addNode(15, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 15, 4);
|
||||
manager.layout();
|
||||
|
||||
// Check orders have shifted accordingly
|
||||
expect(manager.find(13).getOrder()).toEqual(6);
|
||||
expect(manager.find(5).getOrder()).toEqual(8);
|
||||
|
||||
manager.addNode(16, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 16, 25);
|
||||
manager.layout();
|
||||
|
||||
// Check orders have shifted accordingly
|
||||
expect(manager.find(16).getOrder()).toEqual(9);
|
||||
|
||||
manager.addNode(17, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(18, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(19, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 17, 11);
|
||||
manager.connectNode(0, 18, 13);
|
||||
manager.connectNode(0, 19, 10);
|
||||
manager.layout();
|
||||
|
||||
// Check that everything is ok
|
||||
expect(manager.find(1).getPosition().x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(3).getPosition().x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(5).getPosition().x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(2).getPosition().x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(4).getPosition().x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(6).getPosition().x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(7).getPosition().x).toBeGreaterThan(manager.find(3).getPosition().x);
|
||||
expect(manager.find(8).getPosition().x).toBeGreaterThan(manager.find(7).getPosition().x);
|
||||
expect(manager.find(9).getPosition().x).toBeGreaterThan(manager.find(7).getPosition().x);
|
||||
expect(manager.find(10).getPosition().x).toBeLessThan(manager.find(6).getPosition().x);
|
||||
expect(manager.find(11).getPosition().x).toBeLessThan(manager.find(10).getPosition().x);
|
||||
expect(manager.find(12).getPosition().x).toBeLessThan(manager.find(10).getPosition().x);
|
||||
});
|
||||
|
||||
it('balancedPredictTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(3, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(4, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(5, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(7, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(8, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(9, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(10, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(11, TestSuite.NODE_SIZE, position);
|
||||
|
||||
manager.connectNode(0, 1, 0);
|
||||
manager.connectNode(0, 2, 1);
|
||||
manager.connectNode(0, 3, 2);
|
||||
manager.connectNode(0, 4, 3);
|
||||
manager.connectNode(0, 5, 4);
|
||||
manager.connectNode(4, 7, 0);
|
||||
manager.connectNode(4, 8, 1);
|
||||
manager.connectNode(8, 9, 0);
|
||||
manager.connectNode(3, 10, 0);
|
||||
manager.connectNode(3, 11, 1);
|
||||
|
||||
manager.layout();
|
||||
|
||||
// Added as child of node 0 and dropped at (165, -70)
|
||||
const prediction1a = manager.predict(0, null, { x: 165, y: -70 });
|
||||
expect(prediction1a.position.y).toBeLessThan(manager.find(1).getPosition().y);
|
||||
expect(prediction1a.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1a.order).toEqual(0);
|
||||
|
||||
// Added as child of node 0 and dropped at (165, -10)
|
||||
const prediction1b = manager.predict(0, null, { x: 165, y: -10 });
|
||||
expect(prediction1b.position.y).toBeGreaterThan(manager.find(1).getPosition().y);
|
||||
expect(prediction1b.position.y).toBeLessThan(manager.find(3).getPosition().y);
|
||||
expect(prediction1b.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1b.order).toEqual(2);
|
||||
|
||||
// Added as child of node 0 and dropped at (145, 15)
|
||||
const prediction1c = manager.predict(0, null, { x: 145, y: 15 });
|
||||
expect(prediction1c.position.y).toBeGreaterThan(manager.find(3).getPosition().y);
|
||||
expect(prediction1c.position.y).toBeLessThan(manager.find(5).getPosition().y);
|
||||
expect(prediction1c.position.x).toEqual(manager.find(3).getPosition().x);
|
||||
expect(prediction1c.order).toEqual(4);
|
||||
|
||||
// Added as child of node 0 and dropped at (145, 70)
|
||||
const prediction1d = manager.predict(0, null, { x: 145, y: 70 });
|
||||
expect(prediction1d.position.y).toBeGreaterThan(manager.find(5).getPosition().y);
|
||||
expect(prediction1d.position.x).toEqual(manager.find(5).getPosition().x);
|
||||
expect(prediction1d.order).toEqual(6);
|
||||
|
||||
// Added as child of node 0 and dropped at (-145, -50)
|
||||
const prediction2a = manager.predict(0, null, { x: -145, y: -50 });
|
||||
expect(prediction2a.position.y).toBeLessThan(manager.find(2).getPosition().y);
|
||||
expect(prediction2a.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction2a.order).toEqual(1);
|
||||
|
||||
// Added as child of node 0 and dropped at (-145, -10)
|
||||
const prediction2b = manager.predict(0, null, { x: -145, y: -10 });
|
||||
expect(prediction2b.position.y).toBeGreaterThan(manager.find(2).getPosition().y);
|
||||
expect(prediction2b.position.y).toBeLessThan(manager.find(4).getPosition().y);
|
||||
expect(prediction2b.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction2b.order).toEqual(3);
|
||||
|
||||
// Added as child of node 0 and dropped at (-145, 40)
|
||||
const prediction2c = manager.predict(0, null, { x: -145, y: 400 });
|
||||
expect(prediction2c.position.y).toBeGreaterThan(manager.find(4).getPosition().y);
|
||||
expect(prediction2c.position.x).toEqual(manager.find(4).getPosition().x);
|
||||
expect(prediction2c.order).toEqual(5);
|
||||
|
||||
// Predict nodes added with no position
|
||||
const prediction3 = manager.predict(0, null, null);
|
||||
expect(prediction3.position.y).toBeGreaterThan(manager.find(4).getPosition().y);
|
||||
expect(prediction3.position.x).toEqual(manager.find(4).getPosition().x);
|
||||
expect(prediction3.order).toEqual(5);
|
||||
|
||||
manager.addNode(6, TestSuite.NODE_SIZE, prediction3.position);
|
||||
manager.connectNode(0, 6, prediction3.order);
|
||||
manager.layout();
|
||||
|
||||
const prediction4 = manager.predict(0, null, null);
|
||||
expect(prediction4.position.y).toBeGreaterThan(manager.find(5).getPosition().y);
|
||||
expect(prediction4.position.x).toEqual(manager.find(5).getPosition().x);
|
||||
expect(prediction4.order).toEqual(6);
|
||||
|
||||
// Predict nodes added only a root node
|
||||
manager.removeNode(1).removeNode(2).removeNode(3).removeNode(4)
|
||||
.removeNode(5);
|
||||
manager.layout();
|
||||
const prediction5a = manager.predict(0, null, null);
|
||||
const prediction5b = manager.predict(0, null, { x: 40, y: 100 });
|
||||
expect(prediction5a.position.x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(prediction5a.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction5a.order).toEqual(0);
|
||||
expect(prediction5a.position.x).toEqual(prediction5b.position.x);
|
||||
expect(prediction5a.position.y).toEqual(prediction5b.position.y);
|
||||
expect(prediction5a.order).toEqual(prediction5b.order);
|
||||
});
|
||||
|
||||
it('balancedNodeDragPredictTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
|
||||
manager.layout();
|
||||
|
||||
const prediction1a = manager.predict(0, 1, { x: 50, y: 50 });
|
||||
expect(prediction1a.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1a.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction1a.order).toEqual(manager.find(1).getOrder());
|
||||
|
||||
const prediction1b = manager.predict(0, 1, { x: 50, y: -50 });
|
||||
expect(prediction1b.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1b.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction1b.order).toEqual(manager.find(1).getOrder());
|
||||
|
||||
const prediction1c = manager.predict(0, 1, { x: -50, y: 50 });
|
||||
expect(prediction1c.position.x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(prediction1c.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction1c.order).toEqual(1);
|
||||
|
||||
const prediction1d = manager.predict(0, 1, { x: -50, y: -50 });
|
||||
expect(prediction1d.position.x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(prediction1d.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction1d.order).toEqual(1);
|
||||
|
||||
manager.disconnectNode(1);
|
||||
manager.connectNode(0, 1, 1);
|
||||
manager.layout();
|
||||
|
||||
const prediction2a = manager.predict(0, 1, { x: 50, y: 50 });
|
||||
expect(prediction2a.position.x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(prediction2a.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction2a.order).toEqual(0);
|
||||
|
||||
const prediction2b = manager.predict(0, 1, { x: 50, y: -50 });
|
||||
expect(prediction2b.position.x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(prediction2b.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction2b.order).toEqual(0);
|
||||
|
||||
const prediction2c = manager.predict(0, 1, { x: -50, y: 50 });
|
||||
expect(prediction2c.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction2c.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction2c.order).toEqual(manager.find(1).getOrder());
|
||||
|
||||
const prediction2d = manager.predict(0, 1, { x: -50, y: -50 });
|
||||
expect(prediction2d.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction2d.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction2d.order).toEqual(manager.find(1).getOrder());
|
||||
|
||||
manager.disconnectNode(1);
|
||||
manager.connectNode(0, 1, 0);
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2);
|
||||
manager.layout();
|
||||
|
||||
const prediction3a = manager.predict(0, 1, { x: 50, y: 50 });
|
||||
expect(prediction3a.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction3a.position.y).toBeGreaterThan(manager.find(2).getPosition().y);
|
||||
expect(prediction3a.order).toEqual(4);
|
||||
|
||||
const prediction3b = manager.predict(0, 1, { x: 50, y: -50 });
|
||||
expect(prediction3b.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction3b.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction3b.order).toEqual(manager.find(1).getOrder());
|
||||
|
||||
const prediction3c = manager.predict(0, 1, { x: -50, y: 50 });
|
||||
expect(prediction3c.position.x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(prediction3c.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction3c.order).toEqual(1);
|
||||
|
||||
const prediction3d = manager.predict(0, 1, { x: -50, y: -50 });
|
||||
expect(prediction3d.position.x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(prediction3d.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction3d.order).toEqual(1);
|
||||
|
||||
const prediction3e = manager.predict(0, 1, { x: 50, y: 0 });
|
||||
expect(prediction3e.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction3e.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction3e.order).toEqual(manager.find(1).getOrder());
|
||||
});
|
||||
});
|
329
packages/mindplot/test/unit/BalancedTestSuite.test.js
Normal file
329
packages/mindplot/test/unit/BalancedTestSuite.test.js
Normal file
@ -0,0 +1,329 @@
|
||||
import '../../../../libraries/mootools-core-1.4.5';
|
||||
import TestSuite from './TestSuite';
|
||||
import LayoutManager from '../../src/components/layout/LayoutManager';
|
||||
|
||||
describe('Balanced Test Suite', () => {
|
||||
describe('balancedTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 1, 0); manager.layout();
|
||||
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 2, 1);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(3, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 3, 2);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(4, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 4, 3);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(5, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 5, 4);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(6, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 6, 5);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(7, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(8, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(9, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(3, 7, 0);
|
||||
manager.connectNode(7, 8, 0);
|
||||
manager.connectNode(7, 9, 1);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(10, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(11, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(12, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(6, 10, 0);
|
||||
manager.connectNode(10, 11, 0);
|
||||
manager.connectNode(10, 12, 1);
|
||||
manager.layout();
|
||||
|
||||
manager.addNode(13, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 13, 4);
|
||||
manager.layout();
|
||||
|
||||
test('Check orders have shifted accordingly', () => {
|
||||
expect(manager.find(5).getOrder()).toEqual(6);
|
||||
});
|
||||
|
||||
test('Check orders have shifted accordingly', () => {
|
||||
manager.addNode(14, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 14, 5);
|
||||
manager.layout();
|
||||
expect(manager.find(6).getOrder()).toEqual(7);
|
||||
});
|
||||
|
||||
test('Check orders have shifted accordingly', () => {
|
||||
manager.addNode(15, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 15, 4);
|
||||
manager.layout();
|
||||
expect(manager.find(13).getOrder()).toEqual(6);
|
||||
expect(manager.find(5).getOrder()).toEqual(8);
|
||||
});
|
||||
|
||||
test('Check orders have shifted accordingly', () => {
|
||||
manager.addNode(16, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 16, 25);
|
||||
manager.layout();
|
||||
expect(manager.find(16).getOrder()).toEqual(9);
|
||||
});
|
||||
|
||||
test('Check that everything is ok', () => {
|
||||
manager.addNode(17, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(18, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(19, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 17, 11);
|
||||
manager.connectNode(0, 18, 13);
|
||||
manager.connectNode(0, 19, 10);
|
||||
manager.layout();
|
||||
expect(manager.find(1).getPosition().x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(3).getPosition().x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(5).getPosition().x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(2).getPosition().x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(4).getPosition().x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(6).getPosition().x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(manager.find(7).getPosition().x).toBeGreaterThan(manager.find(3).getPosition().x);
|
||||
expect(manager.find(8).getPosition().x).toBeGreaterThan(manager.find(7).getPosition().x);
|
||||
expect(manager.find(9).getPosition().x).toBeGreaterThan(manager.find(7).getPosition().x);
|
||||
expect(manager.find(10).getPosition().x).toBeLessThan(manager.find(6).getPosition().x);
|
||||
expect(manager.find(11).getPosition().x).toBeLessThan(manager.find(10).getPosition().x);
|
||||
expect(manager.find(12).getPosition().x).toBeLessThan(manager.find(10).getPosition().x);
|
||||
});
|
||||
});
|
||||
|
||||
describe('balancedPredictTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(3, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(4, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(5, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(7, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(8, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(9, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(10, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(11, TestSuite.NODE_SIZE, position);
|
||||
|
||||
manager.connectNode(0, 1, 0);
|
||||
manager.connectNode(0, 2, 1);
|
||||
manager.connectNode(0, 3, 2);
|
||||
manager.connectNode(0, 4, 3);
|
||||
manager.connectNode(0, 5, 4);
|
||||
manager.connectNode(4, 7, 0);
|
||||
manager.connectNode(4, 8, 1);
|
||||
manager.connectNode(8, 9, 0);
|
||||
manager.connectNode(3, 10, 0);
|
||||
manager.connectNode(3, 11, 1);
|
||||
|
||||
manager.layout();
|
||||
|
||||
test('Added as child of node 0 and dropped at (165, -70)', () => {
|
||||
const prediction1a = manager.predict(0, null, { x: 165, y: -70 });
|
||||
expect(prediction1a.position.y).toBeLessThan(manager.find(1).getPosition().y);
|
||||
expect(prediction1a.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1a.order).toEqual(0);
|
||||
});
|
||||
|
||||
test('Added as child of node 0 and dropped at (165, -10)', () => {
|
||||
const prediction1b = manager.predict(0, null, { x: 165, y: -10 });
|
||||
expect(prediction1b.position.y).toBeGreaterThan(manager.find(1).getPosition().y);
|
||||
expect(prediction1b.position.y).toBeLessThan(manager.find(3).getPosition().y);
|
||||
expect(prediction1b.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1b.order).toEqual(2);
|
||||
});
|
||||
|
||||
test('Added as child of node 0 and dropped at (145, 15)', () => {
|
||||
const prediction1c = manager.predict(0, null, { x: 145, y: 15 });
|
||||
expect(prediction1c.position.y).toBeGreaterThan(manager.find(3).getPosition().y);
|
||||
expect(prediction1c.position.y).toBeLessThan(manager.find(5).getPosition().y);
|
||||
expect(prediction1c.position.x).toEqual(manager.find(3).getPosition().x);
|
||||
expect(prediction1c.order).toEqual(4);
|
||||
});
|
||||
|
||||
test('Added as child of node 0 and dropped at (145, 70)', () => {
|
||||
const prediction1d = manager.predict(0, null, { x: 145, y: 70 });
|
||||
expect(prediction1d.position.y).toBeGreaterThan(manager.find(5).getPosition().y);
|
||||
expect(prediction1d.position.x).toEqual(manager.find(5).getPosition().x);
|
||||
expect(prediction1d.order).toEqual(6);
|
||||
});
|
||||
|
||||
test('Added as child of node 0 and dropped at (-145, -50)', () => {
|
||||
const prediction2a = manager.predict(0, null, { x: -145, y: -50 });
|
||||
expect(prediction2a.position.y).toBeLessThan(manager.find(2).getPosition().y);
|
||||
expect(prediction2a.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction2a.order).toEqual(1);
|
||||
});
|
||||
|
||||
test('Added as child of node 0 and dropped at (-145, -10)', () => {
|
||||
const prediction2b = manager.predict(0, null, { x: -145, y: -10 });
|
||||
expect(prediction2b.position.y).toBeGreaterThan(manager.find(2).getPosition().y);
|
||||
expect(prediction2b.position.y).toBeLessThan(manager.find(4).getPosition().y);
|
||||
expect(prediction2b.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction2b.order).toEqual(3);
|
||||
});
|
||||
|
||||
test('Added as child of node 0 and dropped at (-145, 40)', () => {
|
||||
const prediction2c = manager.predict(0, null, { x: -145, y: 400 });
|
||||
expect(prediction2c.position.y).toBeGreaterThan(manager.find(4).getPosition().y);
|
||||
expect(prediction2c.position.x).toEqual(manager.find(4).getPosition().x);
|
||||
expect(prediction2c.order).toEqual(5);
|
||||
});
|
||||
|
||||
test('Predict nodes added with no position', () => {
|
||||
const prediction3 = manager.predict(0, null, null);
|
||||
expect(prediction3.position.y).toBeGreaterThan(manager.find(4).getPosition().y);
|
||||
expect(prediction3.position.x).toEqual(manager.find(4).getPosition().x);
|
||||
expect(prediction3.order).toEqual(5);
|
||||
|
||||
manager.addNode(6, TestSuite.NODE_SIZE, prediction3.position);
|
||||
manager.connectNode(0, 6, prediction3.order);
|
||||
manager.layout();
|
||||
|
||||
const prediction4 = manager.predict(0, null, null);
|
||||
expect(prediction4.position.y).toBeGreaterThan(manager.find(5).getPosition().y);
|
||||
expect(prediction4.position.x).toEqual(manager.find(5).getPosition().x);
|
||||
expect(prediction4.order).toEqual(6);
|
||||
});
|
||||
|
||||
test('Predict nodes added only a root node', () => {
|
||||
manager.removeNode(1).removeNode(2).removeNode(3).removeNode(4)
|
||||
.removeNode(5);
|
||||
manager.layout();
|
||||
const prediction5a = manager.predict(0, null, null);
|
||||
const prediction5b = manager.predict(0, null, { x: 40, y: 100 });
|
||||
expect(prediction5a.position.x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(prediction5a.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction5a.order).toEqual(0);
|
||||
expect(prediction5a.position.x).toEqual(prediction5b.position.x);
|
||||
expect(prediction5a.position.y).toEqual(prediction5b.position.y);
|
||||
expect(prediction5a.order).toEqual(prediction5b.order);
|
||||
});
|
||||
});
|
||||
|
||||
describe('balancedNodeDragPredictTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0);
|
||||
manager.layout();
|
||||
|
||||
describe('Predict 1', () => {
|
||||
test('Node drag predict A', () => {
|
||||
const prediction1a = manager.predict(0, 1, { x: 50, y: 50 });
|
||||
expect(prediction1a.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1a.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction1a.order).toEqual(manager.find(1).getOrder());
|
||||
});
|
||||
|
||||
test('Node drag predict B', () => {
|
||||
const prediction1b = manager.predict(0, 1, { x: 50, y: -50 });
|
||||
expect(prediction1b.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1b.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction1b.order).toEqual(manager.find(1).getOrder());
|
||||
});
|
||||
|
||||
test('Node drag predict C', () => {
|
||||
const prediction1c = manager.predict(0, 1, { x: -50, y: 50 });
|
||||
expect(prediction1c.position.x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(prediction1c.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction1c.order).toEqual(1);
|
||||
});
|
||||
|
||||
test('Node drag predict D', () => {
|
||||
const prediction1d = manager.predict(0, 1, { x: -50, y: -50 });
|
||||
expect(prediction1d.position.x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(prediction1d.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction1d.order).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Predict 2', () => {
|
||||
beforeEach(() => {
|
||||
manager.disconnectNode(1);
|
||||
manager.connectNode(0, 1, 1);
|
||||
manager.layout();
|
||||
});
|
||||
|
||||
test('Node drag predict A', () => {
|
||||
const prediction2a = manager.predict(0, 1, { x: 50, y: 50 });
|
||||
expect(prediction2a.position.x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(prediction2a.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction2a.order).toEqual(0);
|
||||
});
|
||||
|
||||
test('Node drag predict B', () => {
|
||||
const prediction2b = manager.predict(0, 1, { x: 50, y: -50 });
|
||||
expect(prediction2b.position.x).toBeGreaterThan(manager.find(0).getPosition().x);
|
||||
expect(prediction2b.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction2b.order).toEqual(0);
|
||||
});
|
||||
|
||||
test('Node drag predict C', () => {
|
||||
const prediction2c = manager.predict(0, 1, { x: -50, y: 50 });
|
||||
expect(prediction2c.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction2c.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction2c.order).toEqual(manager.find(1).getOrder());
|
||||
});
|
||||
|
||||
test('Node drag predict D', () => {
|
||||
const prediction2d = manager.predict(0, 1, { x: -50, y: -50 });
|
||||
expect(prediction2d.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction2d.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction2d.order).toEqual(manager.find(1).getOrder());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Predict 3', () => {
|
||||
beforeAll(() => {
|
||||
manager.disconnectNode(1);
|
||||
manager.connectNode(0, 1, 0);
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2);
|
||||
manager.layout();
|
||||
});
|
||||
|
||||
test('Node drag predict A', () => {
|
||||
const prediction3a = manager.predict(0, 1, { x: 50, y: 50 });
|
||||
expect(prediction3a.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction3a.position.y).toBeGreaterThan(manager.find(2).getPosition().y);
|
||||
expect(prediction3a.order).toEqual(4);
|
||||
});
|
||||
|
||||
test('Node drag predict B', () => {
|
||||
const prediction3b = manager.predict(0, 1, { x: 50, y: -50 });
|
||||
expect(prediction3b.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction3b.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction3b.order).toEqual(manager.find(1).getOrder());
|
||||
});
|
||||
|
||||
test('Node drag predict C', () => {
|
||||
const prediction3c = manager.predict(0, 1, { x: -50, y: 50 });
|
||||
expect(prediction3c.position.x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(prediction3c.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction3c.order).toEqual(1);
|
||||
});
|
||||
|
||||
test('Node drag predict D', () => {
|
||||
const prediction3d = manager.predict(0, 1, { x: -50, y: -50 });
|
||||
expect(prediction3d.position.x).toBeLessThan(manager.find(0).getPosition().x);
|
||||
expect(prediction3d.position.y).toEqual(manager.find(0).getPosition().y);
|
||||
expect(prediction3d.order).toEqual(1);
|
||||
});
|
||||
|
||||
test('Node drag predict E', () => {
|
||||
const prediction3e = manager.predict(0, 1, { x: 50, y: 0 });
|
||||
expect(prediction3e.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction3e.position.y).toEqual(manager.find(1).getPosition().y);
|
||||
expect(prediction3e.order).toEqual(manager.find(1).getOrder());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,63 +0,0 @@
|
||||
let designer = null;
|
||||
/*: DOC += <div id="mindplot"></div> */
|
||||
const mapId = '1';
|
||||
const mapXml = '<map name="1" version="pela"><topic central="true" text="test" id="1"><topic position="103,-52" order="" id="2"/><topic position="-134,-75" order="" id="3"/><topic position="-126,5" order="" id="4"/><topic position="-115,53" order="" id="5"/><topic position="-136,-35" order="" id="6"/></topic></map>';
|
||||
const editorProperties = { zoom: 0.7, size: { width: '1366px', height: '768px' } };
|
||||
const buildMindmapDesigner = function () {
|
||||
// Initialize message logger ...
|
||||
const container = $('<div id="mindplot"></div>');
|
||||
$('body').append(container);
|
||||
|
||||
// Initialize Editor ...
|
||||
var window = $(window);
|
||||
const screenWidth = window.width();
|
||||
let screenHeight = window.height();
|
||||
|
||||
// Positionate node ...
|
||||
// header - footer
|
||||
screenHeight = screenHeight - 90 - 61;
|
||||
|
||||
// body margin ...
|
||||
editorProperties.width = screenWidth;
|
||||
editorProperties.height = screenHeight;
|
||||
|
||||
designer = new mindplot.Designer(editorProperties, container);
|
||||
// Load map from XML file persisted on disk...
|
||||
const persistence = new mindplot.LocalStorageManager('src/test/resources/welcome.xml');
|
||||
const mindmap = persistence.load(mapId);
|
||||
designer.loadMap(mindmap);
|
||||
|
||||
/* // Save map on load ....
|
||||
if (editorProperties.saveOnLoad)
|
||||
{
|
||||
var saveOnLoad = function() {
|
||||
designer.save(function() {
|
||||
}, false);
|
||||
}.delay(1000)
|
||||
} */
|
||||
};
|
||||
buildMindmapDesigner();
|
||||
|
||||
describe('Designer test suite', () => {
|
||||
it('testWorkspaceBuild', () => {
|
||||
const mindplot = $(document).find('#mindplot');
|
||||
expect(mindplot).not.toBeNull();
|
||||
expect(mindplot).not.toBeUndefined();
|
||||
});
|
||||
it('testCentralTopicPresent', () => {
|
||||
const centralTopic = designer.getMindmap().getCentralTopic();
|
||||
expect($defined(centralTopic)).toBe(true);
|
||||
const position = centralTopic.getPosition();
|
||||
expect(position.x).toEqual(0);
|
||||
expect(position.y).toEqual(0);
|
||||
});
|
||||
/* it("testCentralTopicPresent", function(){
|
||||
var centralTopic = designer.getMindmap().getCentralTopic();
|
||||
expect($defined(centralTopic)).toBe(true);
|
||||
var target = designer.getWorkSpace().getScreenManager().getContainer();
|
||||
var size = designer.getModel().getTopics().length;
|
||||
fireNativeEvent('dblclick',target,new web2d.Point(50,50));
|
||||
assertEquals(size+1, designer.getModel().getTopics().length);
|
||||
});
|
||||
*/
|
||||
});
|
70
packages/mindplot/test/unit/DesignerTestSuite.test.js
Normal file
70
packages/mindplot/test/unit/DesignerTestSuite.test.js
Normal file
@ -0,0 +1,70 @@
|
||||
import $ from 'jquery';
|
||||
import '../../../../libraries/mootools-core-1.4.5';
|
||||
import { Designer, LocalStorageManager } from '../../src';
|
||||
|
||||
// FIXME: The tests Map could not be loaded.
|
||||
describe.skip('Designer test suite', () => {
|
||||
let designer;
|
||||
|
||||
beforeAll(() => {
|
||||
/*: DOC += <div id="mindplot"></div> */
|
||||
const mapId = 'welcome';
|
||||
const editorProperties = { zoom: 0.7, size: { width: '1366px', height: '768px' }, locale: 'en' };
|
||||
|
||||
// Initialize message logger ...
|
||||
const container = $("<div id='mindplot'></div>");
|
||||
$('body').append(container);
|
||||
|
||||
// Initialize Editor ...
|
||||
const screenWidth = window.width;
|
||||
let screenHeight = window.height;
|
||||
|
||||
// Positionate node ...
|
||||
// header - footer
|
||||
screenHeight = screenHeight - 90 - 61;
|
||||
|
||||
// body margin ...
|
||||
editorProperties.width = screenWidth;
|
||||
editorProperties.height = screenHeight;
|
||||
|
||||
designer = new Designer(editorProperties, container);
|
||||
|
||||
// Load map from XML file persisted on disk...
|
||||
const pathXML = 'test/resources/welcome.xml';
|
||||
const persistence = new LocalStorageManager(pathXML);
|
||||
const mindmap = persistence.load(mapId);
|
||||
designer.loadMap(mindmap);
|
||||
|
||||
/* // Save map on load ....
|
||||
if (editorProperties.saveOnLoad)
|
||||
{
|
||||
var saveOnLoad = function() {
|
||||
designer.save(function() {
|
||||
}, false);
|
||||
}.delay(1000)
|
||||
} */
|
||||
});
|
||||
|
||||
test('testWorkspaceBuild', () => {
|
||||
const mind = document.querySelector('#mindplot');
|
||||
expect(mind).not.toBeNull();
|
||||
expect(mind).not.toBeUndefined();
|
||||
});
|
||||
/*
|
||||
* it('testCentralTopicPresent', () => {
|
||||
const centralTopic = designer.getMindmap().getCentralTopic();
|
||||
expect($defined(centralTopic)).toBe(true);
|
||||
const position = centralTopic.getPosition();
|
||||
expect(position.x).toEqual(0);
|
||||
expect(position.y).toEqual(0);
|
||||
});
|
||||
* it("testCentralTopicPresent", function(){
|
||||
var centralTopic = designer.getMindmap().getCentralTopic();
|
||||
expect($defined(centralTopic)).toBe(true);
|
||||
var target = designer.getWorkSpace().getScreenManager().getContainer();
|
||||
var size = designer.getModel().getTopics().length;
|
||||
fireNativeEvent('dblclick',target,new web2d.Point(50,50));
|
||||
assertEquals(size+1, designer.getModel().getTopics().length);
|
||||
});
|
||||
*/
|
||||
});
|
@ -1,39 +0,0 @@
|
||||
class TestClass extends Events{
|
||||
getEvents() {
|
||||
return this.$events;
|
||||
}
|
||||
|
||||
removeEvents() {
|
||||
this.$events = {};
|
||||
}
|
||||
}
|
||||
|
||||
// Test class and variables
|
||||
const expectedChangeFn1 = function () { return 'change1'; };
|
||||
const expectedChangeFn2 = function () { return 'change2'; };
|
||||
const expectedLoadFn = function () { return 'loaded'; };
|
||||
const myTestClass = new TestClass();
|
||||
|
||||
describe('Events class suite', () => {
|
||||
afterEach(() => {
|
||||
myTestClass.removeEvents();
|
||||
});
|
||||
|
||||
it('addEventTest', () => {
|
||||
expect(myTestClass.getEvents()).toEqual({});
|
||||
myTestClass.addEvent('change', expectedChangeFn1);
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1] });
|
||||
myTestClass.addEvent('change', expectedChangeFn2);
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2] });
|
||||
myTestClass.addEvent('load', expectedLoadFn);
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2], load: [expectedLoadFn] });
|
||||
});
|
||||
it('removeEventTest', () => {
|
||||
expect(myTestClass.getEvents()).toEqual({});
|
||||
myTestClass.addEvent('change', expectedChangeFn1);
|
||||
myTestClass.addEvent('change', expectedChangeFn2);
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2] });
|
||||
myTestClass.removeEvent('change', expectedChangeFn1);
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn2] });
|
||||
});
|
||||
});
|
64
packages/mindplot/test/unit/EventsTestSuite.test.js
Normal file
64
packages/mindplot/test/unit/EventsTestSuite.test.js
Normal file
@ -0,0 +1,64 @@
|
||||
import '../../../../libraries/mootools-core-1.4.5';
|
||||
import Events from '../../src/components/Events';
|
||||
|
||||
describe('Events class suite', () => {
|
||||
const TestClass = new Class({
|
||||
Extends: Events,
|
||||
|
||||
getEvents() {
|
||||
return this.$events;
|
||||
},
|
||||
|
||||
removeEvents() {
|
||||
this.$events = {};
|
||||
},
|
||||
});
|
||||
|
||||
const expectedChangeFn1 = () => 'change1';
|
||||
const expectedChangeFn2 = () => 'change2';
|
||||
const expectedLoadFn = () => 'loaded';
|
||||
const myTestClass = new TestClass();
|
||||
|
||||
describe('addEventTest', () => {
|
||||
afterAll(() => {
|
||||
myTestClass.removeEvents();
|
||||
});
|
||||
|
||||
test('Added event Change', () => {
|
||||
expect(myTestClass.getEvents()).toEqual({});
|
||||
myTestClass.addEvent('change', expectedChangeFn1);
|
||||
});
|
||||
|
||||
test('Added event Change', () => {
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1] });
|
||||
myTestClass.addEvent('change', expectedChangeFn2);
|
||||
});
|
||||
|
||||
test('Added event Load', () => {
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2] });
|
||||
myTestClass.addEvent('load', expectedLoadFn);
|
||||
expect(myTestClass.getEvents()).toEqual({
|
||||
change: [expectedChangeFn1, expectedChangeFn2],
|
||||
load: [expectedLoadFn],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeEventTest', () => {
|
||||
afterAll(() => {
|
||||
myTestClass.removeEvents();
|
||||
});
|
||||
|
||||
test('Added 2 event change', () => {
|
||||
expect(myTestClass.getEvents()).toEqual({});
|
||||
myTestClass.addEvent('change', expectedChangeFn1);
|
||||
myTestClass.addEvent('change', expectedChangeFn2);
|
||||
});
|
||||
|
||||
test('Remove 1 event change', () => {
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn1, expectedChangeFn2] });
|
||||
myTestClass.removeEvent('change', expectedChangeFn1);
|
||||
expect(myTestClass.getEvents()).toEqual({ change: [expectedChangeFn2] });
|
||||
});
|
||||
});
|
||||
});
|
@ -1,46 +1,60 @@
|
||||
import '../../../../libraries/mootools-core-1.4.5';
|
||||
import TestSuite from './TestSuite';
|
||||
import LayoutManager from '../../src/components/layout/LayoutManager';
|
||||
|
||||
expect.extend({
|
||||
toNotBeBranchesOverlap(received, expected) {
|
||||
const a = received;
|
||||
const b = expected;
|
||||
if (a[0] <= b[1] || a[1] >= b[0]) {
|
||||
return {
|
||||
message: 'Success',
|
||||
pass: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
message: 'Error',
|
||||
pass: false,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
describe('Free Test Suite', () => {
|
||||
beforeEach(function beforeEach() {
|
||||
this.addMatchers({
|
||||
toNotBeBranchesOverlap(expected) {
|
||||
const a = this.actual;
|
||||
const b = expected;
|
||||
return a[0] <= b[1] || a[1] >= b[0];
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
function branchCollision(treeSet, node, heightById) {
|
||||
const children = treeSet.getChildren(node);
|
||||
const childOfRootNode = treeSet._rootNodes.contains(node);
|
||||
|
||||
children.foeEach(((child) => {
|
||||
let siblings = treeSet.getSiblings(child);
|
||||
if (childOfRootNode) {
|
||||
siblings = siblings.filter((sibling) => (child.getOrder() % 2) == (sibling.getOrder() % 2));
|
||||
}
|
||||
|
||||
siblings.foeEach(((sibling) => {
|
||||
branchesOverlap(child, sibling, heightById);
|
||||
}).bind(this));
|
||||
|
||||
}).bind(this));
|
||||
|
||||
children.foeEach((child) => {
|
||||
branchCollision(treeSet, child, heightById);
|
||||
}).bind((this));
|
||||
}
|
||||
|
||||
function branchesOverlap(branchA, branchB, heightById) {
|
||||
const topA = branchA.getPosition().y - heightById[branchA.getId()] / 2;
|
||||
const bottomA = branchA.getPosition().y + heightById[branchA.getId()] / 2;
|
||||
const topB = branchB.getPosition().y - heightById[branchB.getId()] / 2;
|
||||
const bottomB = branchB.getPosition().y + heightById[branchB.getId()] / 2;
|
||||
expect([bottomA, topA]).toNotBeBranchesOverlap([bottomB, topB]);
|
||||
|
||||
test('Not be Branches Overlap', () => {
|
||||
expect([bottomA, topA]).toNotBeBranchesOverlap([bottomB, topB]);
|
||||
});
|
||||
}
|
||||
|
||||
it('avoidCollisionTree1Test', function avoidCollisionTree1Test() {
|
||||
function branchCollision(treeSet, node, heightById) {
|
||||
const children = treeSet.getChildren(node);
|
||||
const childOfRootNode = treeSet._rootNodes.contains(node);
|
||||
|
||||
children.forEach(((child) => {
|
||||
let siblings = treeSet.getSiblings(child);
|
||||
if (childOfRootNode) {
|
||||
siblings = siblings
|
||||
.filter((sibling) => (child.getOrder() % 2) === (sibling.getOrder() % 2));
|
||||
}
|
||||
|
||||
siblings.forEach(((sibling) => {
|
||||
branchesOverlap(child, sibling, heightById);
|
||||
}));
|
||||
}));
|
||||
|
||||
children.forEach((child) => {
|
||||
branchCollision(treeSet, child, heightById);
|
||||
}, this);
|
||||
}
|
||||
|
||||
describe('avoidCollisionTree1Test', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
// Prepare a sample graph ...
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
@ -76,24 +90,25 @@ describe('Free Test Suite', () => {
|
||||
.connectNode(24, 26, 0);
|
||||
manager.connectNode(5, 6, 0).connectNode(6, 8, 0).connectNode(8, 9, 0);
|
||||
manager.connectNode(5, 7, 1).connectNode(7, 10, 0);
|
||||
manager.connectNode(3, 11, 0).connectNode(11, 14, 0).connectNode(14, 18, 0).connectNode(14, 19, 1)
|
||||
manager.connectNode(3, 11, 0).connectNode(11, 14, 0)
|
||||
.connectNode(14, 18, 0).connectNode(14, 19, 1)
|
||||
.connectNode(14, 20, 2);
|
||||
manager.connectNode(3, 12, 1).connectNode(12, 15, 0).connectNode(12, 16, 1).connectNode(12, 17, 2);
|
||||
manager.connectNode(3, 12, 1).connectNode(12, 15, 0)
|
||||
.connectNode(12, 16, 1).connectNode(12, 17, 2);
|
||||
manager.connectNode(3, 13, 2);
|
||||
|
||||
manager.layout(true);
|
||||
|
||||
const treeSet = manager._treeSet;
|
||||
treeSet._rootNodes.beforeEach(((rootNode) => {
|
||||
treeSet._rootNodes.forEach(((rootNode) => {
|
||||
const heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode);
|
||||
branchCollision(treeSet, rootNode, heightById);
|
||||
}).bind(this));
|
||||
}));
|
||||
});
|
||||
|
||||
// FIXME: This is broken in master. This configuration has two topics overlapping.
|
||||
it('avoidCollisionTree2Test - FAILING, commented test', function avoidCollisionTree2Test() {
|
||||
describe('avoidCollisionTree2Test - FAILING, commented test', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
// Prepare a sample graph ...
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
@ -124,23 +139,25 @@ describe('Free Test Suite', () => {
|
||||
manager.connectNode(1, 5, 0);
|
||||
manager.connectNode(5, 6, 0).connectNode(6, 8, 0).connectNode(8, 9, 0);
|
||||
manager.connectNode(5, 7, 1).connectNode(7, 10, 0);
|
||||
manager.connectNode(3, 11, 0).connectNode(11, 14, 0).connectNode(14, 18, 0).connectNode(14, 19, 1)
|
||||
manager.connectNode(3, 11, 0).connectNode(11, 14, 0)
|
||||
.connectNode(14, 18, 0).connectNode(14, 19, 1)
|
||||
.connectNode(14, 20, 2);
|
||||
manager.connectNode(3, 12, 1).connectNode(12, 15, 0).connectNode(12, 16, 1).connectNode(12, 17, 2);
|
||||
manager.connectNode(3, 12, 1).connectNode(12, 15, 0)
|
||||
.connectNode(12, 16, 1).connectNode(12, 17, 2);
|
||||
manager.connectNode(3, 13, 2);
|
||||
|
||||
manager.layout(true);
|
||||
|
||||
const treeSet = manager._treeSet;
|
||||
treeSet._rootNodes.foeEach(((rootNode) => {
|
||||
treeSet._rootNodes.forEach(((rootNode) => {
|
||||
const heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode);
|
||||
// FIXME: uncoment this line when bug is fixed, branchCollision(treeSet, rootNode, heightById);
|
||||
}).bind(this));
|
||||
}));
|
||||
});
|
||||
|
||||
it('predictTest', () => {
|
||||
describe('predict test', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
// Prepare a sample graph ...
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
@ -169,32 +186,40 @@ describe('Free Test Suite', () => {
|
||||
|
||||
manager.layout();
|
||||
|
||||
const pos1 = { x: 370, y: 80 };
|
||||
const predict1 = manager.predict(5, 11, pos1, true);
|
||||
expect(predict1.position.x).toEqual(pos1.x);
|
||||
expect(predict1.position.y).toEqual(pos1.y);
|
||||
test('Predict 1', () => {
|
||||
const pos1 = { x: 370, y: 80 };
|
||||
const predict1 = manager.predict(5, 11, pos1, true);
|
||||
expect(predict1.position.x).toEqual(pos1.x);
|
||||
expect(predict1.position.y).toEqual(pos1.y);
|
||||
});
|
||||
|
||||
const pos2 = { x: -200, y: 80 };
|
||||
const predict2 = manager.predict(0, 2, pos2, true);
|
||||
expect(predict2.position.x).toEqual(pos2.x);
|
||||
expect(predict2.position.y).toEqual(pos2.y);
|
||||
test('Predict 2', () => {
|
||||
const pos2 = { x: -200, y: 80 };
|
||||
const predict2 = manager.predict(0, 2, pos2, true);
|
||||
expect(predict2.position.x).toEqual(pos2.x);
|
||||
expect(predict2.position.y).toEqual(pos2.y);
|
||||
});
|
||||
|
||||
const pos3 = { x: 200, y: 30 };
|
||||
const node5 = manager.find(5);
|
||||
const predict3 = manager.predict(3, 5, pos3, true);
|
||||
expect(predict3.position.x).toEqual(node5.getPosition().x);
|
||||
expect(predict3.position.y).toEqual(pos3.y);
|
||||
test('Predict 3', () => {
|
||||
const pos3 = { x: 200, y: 30 };
|
||||
const node5 = manager.find(5);
|
||||
const predict3 = manager.predict(3, 5, pos3, true);
|
||||
expect(predict3.position.x).toEqual(node5.getPosition().x);
|
||||
expect(predict3.position.y).toEqual(pos3.y);
|
||||
});
|
||||
|
||||
const pos4 = { x: -100, y: 45 };
|
||||
const node10 = manager.find(10);
|
||||
const predict4 = manager.predict(2, 10, pos4, true);
|
||||
expect(predict4.position.x).toEqual(node10.getPosition().x);
|
||||
expect(predict4.position.y).toEqual(pos4.y);
|
||||
test('Predict 4', () => {
|
||||
const pos4 = { x: -100, y: 45 };
|
||||
const node10 = manager.find(10);
|
||||
const predict4 = manager.predict(2, 10, pos4, true);
|
||||
expect(predict4.position.x).toEqual(node10.getPosition().x);
|
||||
expect(predict4.position.y).toEqual(pos4.y);
|
||||
});
|
||||
});
|
||||
|
||||
it('reconnectNodeTest', () => {
|
||||
describe('reconnect node test', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
// Prepare a sample graph ...
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
@ -222,28 +247,30 @@ describe('Free Test Suite', () => {
|
||||
manager.connectNode(2, 10, 1);
|
||||
manager.layout();
|
||||
|
||||
manager.disconnectNode(5);
|
||||
manager.connectNode(2, 5, 2);
|
||||
manager.layout();
|
||||
test('Reconnect Node', () => {
|
||||
manager.disconnectNode(5);
|
||||
manager.connectNode(2, 5, 2);
|
||||
manager.layout();
|
||||
|
||||
expect(manager.find(5).getPosition().y).toBeGreaterThan(manager.find(10).getPosition().y);
|
||||
expect(manager.find(5).getPosition().x).toEqual(manager.find(10).getPosition().x);
|
||||
expect(manager.find(5).getOrder()).toEqual(2);
|
||||
expect(manager.find(5).getPosition().y).toBeGreaterThan(manager.find(10).getPosition().y);
|
||||
expect(manager.find(5).getPosition().x).toEqual(manager.find(10).getPosition().x);
|
||||
expect(manager.find(5).getOrder()).toEqual(2);
|
||||
|
||||
manager.disconnectNode(5);
|
||||
manager.connectNode(10, 5, 0);
|
||||
manager.layout();
|
||||
manager.disconnectNode(5);
|
||||
manager.connectNode(10, 5, 0);
|
||||
manager.layout();
|
||||
|
||||
expect(manager.find(5).getPosition().y).toEqual(manager.find(10).getPosition().y);
|
||||
expect(manager.find(5).getPosition().x).toBeLessThan(manager.find(10).getPosition().x);
|
||||
expect(manager.find(5).getOrder()).toEqual(0);
|
||||
expect(manager.find(5).getPosition().y).toEqual(manager.find(10).getPosition().y);
|
||||
expect(manager.find(5).getPosition().x).toBeLessThan(manager.find(10).getPosition().x);
|
||||
expect(manager.find(5).getOrder()).toEqual(0);
|
||||
|
||||
manager.disconnectNode(5);
|
||||
manager.connectNode(3, 5, 2);
|
||||
manager.layout();
|
||||
manager.disconnectNode(5);
|
||||
manager.connectNode(3, 5, 2);
|
||||
manager.layout();
|
||||
|
||||
expect(manager.find(5).getPosition().y).toBeGreaterThan(manager.find(6).getPosition().y);
|
||||
expect(manager.find(5).getPosition().x).toEqual(manager.find(6).getPosition().x);
|
||||
expect(manager.find(5).getOrder()).toEqual(2);
|
||||
expect(manager.find(5).getPosition().y).toBeGreaterThan(manager.find(6).getPosition().y);
|
||||
expect(manager.find(5).getPosition().x).toEqual(manager.find(6).getPosition().x);
|
||||
expect(manager.find(5).getOrder()).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,77 +0,0 @@
|
||||
describe('Symmetric Test Suite', () => {
|
||||
it('symmetricTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(3, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(4, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(5, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(6, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(7, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(8, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(9, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(10, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(11, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(12, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(13, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(14, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 14, 0);
|
||||
manager.connectNode(14, 13, 0);
|
||||
manager.connectNode(13, 1, 0);
|
||||
manager.connectNode(13, 2, 1);
|
||||
manager.connectNode(13, 3, 2);
|
||||
manager.connectNode(13, 4, 3);
|
||||
manager.connectNode(13, 5, 4);
|
||||
manager.connectNode(1, 6, 0);
|
||||
manager.connectNode(1, 7, 1);
|
||||
manager.connectNode(7, 8, 0);
|
||||
manager.connectNode(8, 9, 0);
|
||||
manager.connectNode(5, 10, 0);
|
||||
manager.connectNode(6, 11, 0);
|
||||
manager.connectNode(6, 12, 1);
|
||||
|
||||
manager.layout();
|
||||
|
||||
// All nodes should be positioned symmetrically with respect to their common ancestors
|
||||
expect(manager.find(14).getPosition().y).toEqual(manager.find(13).getPosition().y);
|
||||
expect(manager.find(5).getPosition().y).toEqual(manager.find(10).getPosition().y);
|
||||
expect(manager.find(11).getPosition().y - manager.find(6).getPosition().y).toEqual(-(manager.find(12).getPosition().y - manager.find(6).getPosition().y));
|
||||
expect(manager.find(8).getPosition().y - manager.find(1).getPosition().y).toEqual(-(manager.find(11).getPosition().y - manager.find(1).getPosition().y));
|
||||
expect(manager.find(9).getPosition().y - manager.find(1).getPosition().y).toEqual(-(manager.find(11).getPosition().y - manager.find(1).getPosition().y));
|
||||
});
|
||||
|
||||
it('symmetricDragPredictTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1);
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
|
||||
manager.layout();
|
||||
|
||||
const prediction1a = manager.predict(1, 2, { x: -250, y: -20 });
|
||||
expect(prediction1a.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction1a.position.y).toEqual(manager.find(2).getPosition().y);
|
||||
expect(prediction1a.order).toEqual(manager.find(2).getOrder());
|
||||
|
||||
const prediction1b = manager.predict(1, 2, { x: -250, y: 20 });
|
||||
expect(prediction1b.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction1b.position.y).toEqual(manager.find(2).getPosition().y);
|
||||
expect(prediction1b.order).toEqual(manager.find(2).getOrder());
|
||||
|
||||
const prediction1c = manager.predict(0, 2, { x: -100, y: -20 });
|
||||
expect(prediction1c.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1c.position.y).toBeLessThan(manager.find(1).getPosition().y);
|
||||
expect(prediction1c.order).toEqual(manager.find(1).getOrder());
|
||||
|
||||
const prediction1d = manager.predict(0, 2, { x: -100, y: 20 });
|
||||
expect(prediction1d.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1d.position.y).toBeGreaterThan(manager.find(1).getPosition().y);
|
||||
expect(prediction1d.order).toEqual(3);
|
||||
|
||||
const prediction1e = manager.predict(1, 2, { x: -250, y: 0 });
|
||||
expect(prediction1e.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction1e.position.y).toEqual(manager.find(2).getPosition().y);
|
||||
expect(prediction1e.order).toEqual(manager.find(2).getOrder());
|
||||
});
|
||||
});
|
95
packages/mindplot/test/unit/SymmetricTestSuite.test.js
Normal file
95
packages/mindplot/test/unit/SymmetricTestSuite.test.js
Normal file
@ -0,0 +1,95 @@
|
||||
import '../../../../libraries/mootools-core-1.4.5';
|
||||
import TestSuite from './TestSuite';
|
||||
import LayoutManager from '../../src/components/layout/LayoutManager';
|
||||
|
||||
describe('Symmetric Test Suite', () => {
|
||||
describe('symmetricTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(3, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(4, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(5, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(6, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(7, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(8, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(9, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(10, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(11, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(12, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(13, TestSuite.NODE_SIZE, position);
|
||||
manager.addNode(14, TestSuite.NODE_SIZE, position);
|
||||
manager.connectNode(0, 14, 0);
|
||||
manager.connectNode(14, 13, 0);
|
||||
manager.connectNode(13, 1, 0);
|
||||
manager.connectNode(13, 2, 1);
|
||||
manager.connectNode(13, 3, 2);
|
||||
manager.connectNode(13, 4, 3);
|
||||
manager.connectNode(13, 5, 4);
|
||||
manager.connectNode(1, 6, 0);
|
||||
manager.connectNode(1, 7, 1);
|
||||
manager.connectNode(7, 8, 0);
|
||||
manager.connectNode(8, 9, 0);
|
||||
manager.connectNode(5, 10, 0);
|
||||
manager.connectNode(6, 11, 0);
|
||||
manager.connectNode(6, 12, 1);
|
||||
|
||||
manager.layout();
|
||||
|
||||
test('All nodes should be positioned symmetrically with respect to their common ancestors', () => {
|
||||
expect(manager.find(14).getPosition().y).toEqual(manager.find(13).getPosition().y);
|
||||
expect(manager.find(5).getPosition().y).toEqual(manager.find(10).getPosition().y);
|
||||
expect(manager.find(11).getPosition().y - manager.find(6).getPosition().y)
|
||||
.toEqual(-(manager.find(12).getPosition().y - manager.find(6).getPosition().y));
|
||||
expect(manager.find(8).getPosition().y - manager.find(1).getPosition().y)
|
||||
.toEqual(-(manager.find(11).getPosition().y - manager.find(1).getPosition().y));
|
||||
expect(manager.find(9).getPosition().y - manager.find(1).getPosition().y)
|
||||
.toEqual(-(manager.find(11).getPosition().y - manager.find(1).getPosition().y));
|
||||
});
|
||||
});
|
||||
|
||||
describe('symmetricDragPredictTest', () => {
|
||||
const position = { x: 0, y: 0 };
|
||||
const manager = new LayoutManager(0, TestSuite.ROOT_NODE_SIZE);
|
||||
manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1);
|
||||
manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0);
|
||||
manager.layout();
|
||||
|
||||
test('Prediction A', () => {
|
||||
const prediction1a = manager.predict(1, 2, { x: -250, y: -20 });
|
||||
expect(prediction1a.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction1a.position.y).toEqual(manager.find(2).getPosition().y);
|
||||
expect(prediction1a.order).toEqual(manager.find(2).getOrder());
|
||||
});
|
||||
|
||||
test('Prediction B', () => {
|
||||
const prediction1b = manager.predict(1, 2, { x: -250, y: 20 });
|
||||
expect(prediction1b.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction1b.position.y).toEqual(manager.find(2).getPosition().y);
|
||||
expect(prediction1b.order).toEqual(manager.find(2).getOrder());
|
||||
});
|
||||
|
||||
test('Prediction C', () => {
|
||||
const prediction1c = manager.predict(0, 2, { x: -100, y: -20 });
|
||||
expect(prediction1c.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1c.position.y).toBeLessThan(manager.find(1).getPosition().y);
|
||||
expect(prediction1c.order).toEqual(manager.find(1).getOrder());
|
||||
});
|
||||
|
||||
test('Prediction D', () => {
|
||||
const prediction1d = manager.predict(0, 2, { x: -100, y: 20 });
|
||||
expect(prediction1d.position.x).toEqual(manager.find(1).getPosition().x);
|
||||
expect(prediction1d.position.y).toBeGreaterThan(manager.find(1).getPosition().y);
|
||||
expect(prediction1d.order).toEqual(3);
|
||||
});
|
||||
|
||||
test('Prediction E', () => {
|
||||
const prediction1e = manager.predict(1, 2, { x: -250, y: 0 });
|
||||
expect(prediction1e.position.x).toEqual(manager.find(2).getPosition().x);
|
||||
expect(prediction1e.position.y).toEqual(manager.find(2).getPosition().y);
|
||||
expect(prediction1e.order).toEqual(manager.find(2).getOrder());
|
||||
});
|
||||
});
|
||||
});
|
@ -4,3 +4,5 @@ class TestSuite {
|
||||
|
||||
TestSuite.NODE_SIZE = { width: 80, height: 30 };
|
||||
TestSuite.ROOT_NODE_SIZE = { width: 120, height: 40 };
|
||||
|
||||
export default TestSuite;
|
||||
|
@ -11,6 +11,7 @@
|
||||
"Class": "readonly"
|
||||
},
|
||||
"rules": {
|
||||
"no-underscore-dangle": "off",
|
||||
"no-restricted-syntax": "off",
|
||||
"no-plusplus": "off",
|
||||
"max-len": [1,250],
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 132 KiB |
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
@ -34,7 +34,6 @@
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.14.5",
|
||||
"@babel/preset-env": "^7.14.7",
|
||||
"babel-loader": "^8.2.2",
|
||||
"clean-webpack-plugin": "^4.0.0-alpha.0",
|
||||
"core-js": "^3.15.2",
|
||||
"cypress": "^8.4.1",
|
||||
"cypress-image-snapshot": "^4.0.1",
|
||||
@ -51,6 +50,8 @@
|
||||
"webpack": "^5.44.0",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"webpack-dev-server": "^3.11.2",
|
||||
"clean-webpack-plugin": "^4.0.0-alpha.0",
|
||||
"html-webpack-plugin": "^5.3.2",
|
||||
"webpack-merge": "^5.8.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
Loading…
Reference in New Issue
Block a user