mirror of
https://gitee.com/antv/g6.git
synced 2024-12-01 03:08:33 +08:00
fix: enhance coverage
This commit is contained in:
parent
08a12516e2
commit
683a3ac746
@ -426,8 +426,6 @@ export default class MiniMap extends Base {
|
||||
case DELEGATE_MODE:
|
||||
this.updateDelegateShapes();
|
||||
break;
|
||||
default:
|
||||
this.updateGraphShapes();
|
||||
}
|
||||
|
||||
const group = canvas.get('children')[0];
|
||||
|
@ -5,6 +5,7 @@ const div = document.createElement('div');
|
||||
div.id = 'minimap';
|
||||
document.body.appendChild(div);
|
||||
const container = document.createElement('div');
|
||||
container.id = 'minimap-container';
|
||||
div.appendChild(container);
|
||||
|
||||
describe('minimap', () => {
|
||||
@ -170,7 +171,58 @@ describe('minimap', () => {
|
||||
expect(matrix2[4]).toEqual(2);
|
||||
expect(matrix2[6]).toEqual(0);
|
||||
expect(matrix2[7]).toEqual(0);
|
||||
// graph.destroy();
|
||||
|
||||
Simulate.simulate(container, 'mouseleave', {
|
||||
clientX: -100,
|
||||
clientY: -100
|
||||
});
|
||||
graph.destroy();
|
||||
});
|
||||
it('invalid dom event', () => {
|
||||
const minimap = new G6.Minimap({ size: [200, 200] });
|
||||
const graph = new G6.Graph({
|
||||
container: div,
|
||||
width: 500,
|
||||
height: 500,
|
||||
plugins: [minimap],
|
||||
modes: {
|
||||
default: ['zoom-canvas']
|
||||
}
|
||||
});
|
||||
const data = {
|
||||
nodes: [{
|
||||
id: '1',
|
||||
x: 50,
|
||||
y: 80
|
||||
}, {
|
||||
id: '2',
|
||||
x: 140,
|
||||
y: 100
|
||||
}],
|
||||
edges: [{
|
||||
source: '1',
|
||||
target: '2'
|
||||
}]
|
||||
}
|
||||
graph.data(data);
|
||||
graph.render();
|
||||
|
||||
const viewport = minimap.getContainer();
|
||||
const canvas = minimap.getCanvas();
|
||||
|
||||
const container = canvas.get('container');
|
||||
|
||||
Simulate.simulate(container, 'mousemove', {
|
||||
clientX: 100,
|
||||
clientY: 100,
|
||||
});
|
||||
|
||||
viewport.style.width = '300px';
|
||||
Simulate.simulate(viewport, 'mousedown', {
|
||||
clientX: 100,
|
||||
clientY: 100,
|
||||
target: null,
|
||||
});
|
||||
});
|
||||
it('delegate type of minimap', () => {
|
||||
const minimap = new G6.Minimap({
|
||||
@ -290,4 +342,33 @@ describe('minimap', () => {
|
||||
expect(shapeGroup[2].get('children').length).toEqual(1);
|
||||
graph.destroy();
|
||||
});
|
||||
it('get minimap container', () => {
|
||||
const minimap = new G6.Minimap({ size: [200, 200], type: 'keyShape' });
|
||||
const graph = new G6.Graph({
|
||||
container: div,
|
||||
width: 500,
|
||||
height: 500,
|
||||
plugins: [minimap],
|
||||
});
|
||||
|
||||
const container = minimap.getContainer();
|
||||
expect(container).not.toBe(undefined);
|
||||
expect(container.className).toBe('g6-minimap');
|
||||
graph.destroy();
|
||||
});
|
||||
it('minimap beforeanimate afteranimate', () => {
|
||||
const minimap = new G6.Minimap({ size: [200, 200] });
|
||||
const graph = new G6.Graph({
|
||||
container: div,
|
||||
width: 500,
|
||||
height: 500,
|
||||
plugins: [minimap],
|
||||
});
|
||||
|
||||
graph.emit('beforeanimate');
|
||||
expect(minimap.get('refresh')).toBe(false);
|
||||
graph.emit('afteranimate');
|
||||
expect(minimap.get('refresh')).toBe(true);
|
||||
graph.destroy();
|
||||
});
|
||||
});
|
||||
|
@ -9,7 +9,12 @@ import {
|
||||
getRectIntersectByPoint,
|
||||
invertMatrix,
|
||||
scaleMatrix,
|
||||
scale,
|
||||
rotate,
|
||||
} from '../../../src/util/math';
|
||||
import { Graph } from '../../../src';
|
||||
import Canvas from '@antv/g-canvas/lib/canvas';
|
||||
|
||||
|
||||
const equal = (a: number, b: number): boolean => Math.abs(a - b) < 0.0001;
|
||||
|
||||
@ -145,6 +150,16 @@ describe('math util test', () => {
|
||||
expect(dis).toEqual(7.0710678118654755);
|
||||
});
|
||||
|
||||
it('applyMatrix with null matrix', () => {
|
||||
const point = {
|
||||
x: 10,
|
||||
y: 15,
|
||||
};
|
||||
|
||||
const p = applyMatrix(point, null, 0);
|
||||
expect(p).toEqual({ x: 10, y: 15 });
|
||||
});
|
||||
|
||||
it('applyMatrix tag = 0', () => {
|
||||
const point = {
|
||||
x: 10,
|
||||
@ -167,6 +182,16 @@ describe('math util test', () => {
|
||||
expect(p).toEqual({ x: 32, y: 14 });
|
||||
});
|
||||
|
||||
it('invertMatrix with null matrix', () => {
|
||||
const point = {
|
||||
x: 30,
|
||||
y: 10,
|
||||
};
|
||||
|
||||
const p = invertMatrix(point, null, 0);
|
||||
expect(p).toEqual({ x: 30, y: 10 });
|
||||
});
|
||||
|
||||
it('invertMatrix tag = 0', () => {
|
||||
const point = {
|
||||
x: 30,
|
||||
@ -284,4 +309,26 @@ describe('math util test', () => {
|
||||
expect(result[1]).toEqual([1, 0, 1]);
|
||||
expect(result[2]).toEqual([1, 2, 0]);
|
||||
});
|
||||
it('scale and rotate', () => {
|
||||
const div = document.createElement('div');
|
||||
div.id = 'edge-shape';
|
||||
document.body.appendChild(div);
|
||||
const canvas = new Canvas({
|
||||
container: 'edge-shape',
|
||||
width: 600,
|
||||
height: 600,
|
||||
});
|
||||
const group = canvas.addGroup();
|
||||
scale(group, 0.5);
|
||||
const matrix = group.getMatrix();
|
||||
expect(matrix[0]).toBe(0.5);
|
||||
scale(group, 0.5);
|
||||
const matrix2 = group.getMatrix();
|
||||
expect(matrix2[0]).toBe(0.25);
|
||||
rotate(group, 1.3);
|
||||
const matrix3 = group.getMatrix();
|
||||
expect(matrix3[0]).toBe(0.06687470715614684);
|
||||
expect(matrix3[1]).toBe(0.24088954635429824);
|
||||
expect(matrix3[3]).toBe(-0.24088954635429824);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user