Skip to content

Commit

Permalink
Adding tests for empty service names
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 committed Nov 4, 2020
1 parent 3b00d30 commit cec0ebe
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/jaeger-ui/src/components/DependencyGraph/DAG.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export default class DAG extends React.Component {
serviceCalls: [],
};

constructor(props) {
super(props);
this.cytoscapeRef = React.createRef();
}

componentDidMount() {
const { serviceCalls } = this.props;
const nodeMap = {};
Expand All @@ -55,8 +60,9 @@ export default class DAG extends React.Component {
});
}
});

cytoscape({
container: document.getElementById('cy'),
container: this.cytoscapeRef.current,
boxSelectionEnabled: false,
autounselectify: true,
layout: {
Expand Down Expand Up @@ -104,6 +110,7 @@ export default class DAG extends React.Component {
left: 0,
top: 0,
}}
ref={this.cytoscapeRef}
/>
);
}
Expand Down
54 changes: 52 additions & 2 deletions packages/jaeger-ui/src/components/DependencyGraph/DAG.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,53 @@
// limitations under the License.

/* eslint-disable import/first */
jest.mock('cytoscape');
// jest.mock('cytoscape');

import React from 'react';
import { mount } from 'enzyme';

import DAG from './DAG';

// mock canvas API (we don't care about canvas results)

window.HTMLCanvasElement.prototype.getContext = function() {
return {
fillRect() {},
clearRect() {},
getImageData(x, y, w, h) {
return {
data: new Array(w * h * 4),
};
},
putImageData() {},
createImageData() {
return [];
},
setTransform() {},
drawImage() {},
save() {},
fillText() {},
restore() {},
beginPath() {},
moveTo() {},
lineTo() {},
closePath() {},
stroke() {},
translate() {},
scale() {},
rotate() {},
arc() {},
fill() {},
measureText() {
return { width: 0 };
},
transform() {},
rect() {},
clip() {},
};
};
describe('<DAG>', () => {
it('does not explode', () => {
// HTMLCanvasElement.prototype.getContext = jest.fn()
const serviceCalls = [
{
callCount: 1,
Expand All @@ -31,4 +69,16 @@ describe('<DAG>', () => {
];
expect(mount(<DAG serviceCalls={serviceCalls} />)).toBeDefined();
});

it('does not explode with empty strings or string with only spaces', () => {
// HTMLCanvasElement.prototype.getContext = jest.fn()
const serviceCalls = [
{
callCount: 1,
child: '',
parent: ' ',
},
];
expect(mount(<DAG serviceCalls={serviceCalls} />)).toBeDefined();
});
});

0 comments on commit cec0ebe

Please sign in to comment.