Skip to content

Commit

Permalink
Update tests after merge
Browse files Browse the repository at this point in the history
Signed-off-by: Everett Ross <[email protected]>
  • Loading branch information
everett980 committed Mar 8, 2019
1 parent bf3386f commit b4afe2d
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Props = {

const { classNameIsSmall } = DirectedGraph.propsFactories;

class TraceDiffGraph extends React.PureComponent<Props> {
export class UnconnectedTraceDiffGraph extends React.PureComponent<Props> {
props: Props;
layoutManager: LayoutManager;

Expand Down Expand Up @@ -126,4 +126,4 @@ class TraceDiffGraph extends React.PureComponent<Props> {
}
}

export default connect(extractUiFindFromState)(TraceDiffGraph);
export default connect(extractUiFindFromState)(UnconnectedTraceDiffGraph);
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import * as React from 'react';
import { shallow } from 'enzyme';
import _mapValues from 'lodash/mapValues';
// import _mapValues from 'lodash/mapValues';

import TraceDiffGraph, { setOnNodesContainer, setOnEdgesContainer, setOnNode } from './TraceDiffGraph';
import { UnconnectedTraceDiffGraph as TraceDiffGraph } from './TraceDiffGraph';
import ErrorMessage from '../../common/ErrorMessage';
import LoadingIndicator from '../../common/LoadingIndicator';
import { fetchedState } from '../../../constants';
Expand Down Expand Up @@ -152,72 +152,4 @@ describe('TraceDiffGraph', () => {
wrapper.unmount();
expect(layoutManager).toHaveBeenCalledTimes(1);
});

describe('setOnEdgesContainer', () => {
it('returns null if zoomTransform kwarg is falsy', () => {
expect(setOnEdgesContainer({ zoomTransform: null })).toBe(null);
expect(setOnEdgesContainer({ zoomTransform: undefined })).toBe(null);
});

it('calculates style object with opacity off of zoomTransform.k', () => {
expect(setOnEdgesContainer({ zoomTransform: { k: 0.0 } }).style.opacity).toBe(0.1);
expect(setOnEdgesContainer({ zoomTransform: { k: 0.3 } }).style.opacity).toBe(0.37);
expect(setOnEdgesContainer({ zoomTransform: { k: 0.5 } }).style.opacity).toBe(0.55);
expect(setOnEdgesContainer({ zoomTransform: { k: 0.7 } }).style.opacity).toBe(0.73);
expect(setOnEdgesContainer({ zoomTransform: { k: 1.0 } }).style.opacity).toBe(1);
});
});

describe('setOnNodesContainer', () => {
function stringPxCountToNumber(stringPx) {
return Number.parseInt(stringPx.split('px')[0], 10);
}

function getComputedSizes(k) {
const { style } = setOnNodesContainer({ zoomTransform: k != undefined ? { k } : undefined }); // eslint-disable-line eqeqeq
const [, , boxShadowBlurRadius, boxShadowSpreadRadius] = style.boxShadow.split(' ');
return {
outlineWidth: stringPxCountToNumber(style.outlineWidth),
boxShadowBlurRadius: stringPxCountToNumber(boxShadowBlurRadius),
boxShadowSpreadRadius: stringPxCountToNumber(boxShadowSpreadRadius),
};
}
const sizeIdentity = {
outlineWidth: 2,
boxShadowBlurRadius: 4,
boxShadowSpreadRadius: 8,
};

it('defaults style object with box-shadow size and outlineWidth off of 2 if zoomTransform.k is not provided', () => {
expect(getComputedSizes(null)).toEqual(sizeIdentity);
expect(getComputedSizes(undefined)).toEqual(sizeIdentity);
});

it('calculates style object with box-shadow size and outlineWidth at default size if zoomTransform.k is 1', () => {
expect(getComputedSizes(1)).toEqual(sizeIdentity);
});

it('calculates style object with box-shadow size and outlineWidth 150% as large if zoomTransform.k is .5', () => {
expect(getComputedSizes(0.5)).toEqual(_mapValues(sizeIdentity, x => x * 1.5));
});

it('calculates style object with box-shadow size and outlineWidth twice as large if zoomTransform.k is .33', () => {
expect(getComputedSizes(0.33)).toEqual(_mapValues(sizeIdentity, x => x * 2));
});

it('calculates style object with box-shadow size and outlineWidth 250% as large if zoomTransform.k is .25', () => {
expect(getComputedSizes(0.25)).toEqual(_mapValues(sizeIdentity, x => x * 2.5));
});
});

describe('setOnNode', () => {
it("inherits container's boxShadow and outlineWidth", () => {
expect(setOnNode()).toEqual({
style: {
boxShadow: 'inherit',
outlineWidth: 'inherit',
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`drawNode diffNode renders as expected when props.a and props.b are the
className="DiffNode is-same"
>
<tbody
className="DiffNode--body is-same"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -52,7 +52,7 @@ exports[`drawNode diffNode renders as expected when props.a and props.b are the
className="DiffNode is-same"
>
<tbody
className="DiffNode--body is-same"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -93,7 +93,7 @@ exports[`drawNode diffNode renders as expected when props.a is 0 1`] = `
className="DiffNode is-changed is-added"
>
<tbody
className="DiffNode--body is-changed is-added"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -158,7 +158,7 @@ exports[`drawNode diffNode renders as expected when props.a is 0 1`] = `
className="DiffNode is-changed is-added"
>
<tbody
className="DiffNode--body is-changed is-added"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -219,7 +219,7 @@ exports[`drawNode diffNode renders as expected when props.a is less than props.b
className="DiffNode is-changed is-more"
>
<tbody
className="DiffNode--body is-changed is-more"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -284,7 +284,7 @@ exports[`drawNode diffNode renders as expected when props.a is less than props.b
className="DiffNode is-changed is-more"
>
<tbody
className="DiffNode--body is-changed is-more"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -345,7 +345,7 @@ exports[`drawNode diffNode renders as expected when props.a is more than props.b
className="DiffNode is-changed is-less"
>
<tbody
className="DiffNode--body is-changed is-less"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -410,7 +410,7 @@ exports[`drawNode diffNode renders as expected when props.a is more than props.b
className="DiffNode is-changed is-less"
>
<tbody
className="DiffNode--body is-changed is-less"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -471,7 +471,7 @@ exports[`drawNode diffNode renders as expected when props.b is 0 1`] = `
className="DiffNode is-changed is-removed"
>
<tbody
className="DiffNode--body is-changed is-removed"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -536,7 +536,7 @@ exports[`drawNode diffNode renders as expected when props.b is 0 1`] = `
className="DiffNode is-changed is-removed"
>
<tbody
className="DiffNode--body is-changed is-removed"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -590,14 +590,14 @@ exports[`drawNode diffNode renders as expected when props.b is 0 1`] = `
</Popover>
`;

exports[`drawNode diffNode renders as expected when props.members matches props.uiFind 1`] = `
exports[`drawNode diffNode renders as expected when props.isUiFindMatch is true 1`] = `
<Popover
content={
<table
className="DiffNode is-same is-ui-find-match"
>
<tbody
className="DiffNode--body is-same is-ui-find-match"
className="DiffNode--body"
>
<tr>
<td
Expand Down Expand Up @@ -642,7 +642,7 @@ exports[`drawNode diffNode renders as expected when props.members matches props.
className="DiffNode is-same is-ui-find-match"
>
<tbody
className="DiffNode--body is-same is-ui-find-match"
className="DiffNode--body"
>
<tr>
<td
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@

import React from 'react';
import { shallow } from 'enzyme';
import _map from 'lodash/map';

import drawNode, { DiffNode } from './drawNode';
import filterSpansMock from '../../../utils/filter-spans';

jest.mock('../../../utils/filter-spans');
import drawNodeGenerator, { DiffNode } from './drawNode';

describe('drawNode', () => {
const members = [
Expand Down Expand Up @@ -49,7 +45,6 @@ describe('drawNode', () => {
let wrapper;

beforeEach(() => {
filterSpansMock.mockClear();
wrapper = shallow(<DiffNode {...props} />);
});

Expand Down Expand Up @@ -77,33 +72,40 @@ describe('drawNode', () => {
expect(wrapper).toMatchSnapshot();
});

it('renders as expected when props.members matches props.uiFind', () => {
const uiFind = 'uiFindValue';
filterSpansMock.mockReturnValue({ size: 1 });
wrapper.setProps({ uiFind });
it('renders as expected when props.isUiFindMatch is true', () => {
wrapper.setProps({ isUiFindMatch: true });
expect(wrapper).toMatchSnapshot();
expect(filterSpansMock).toHaveBeenLastCalledWith(uiFind, _map(props.members, 'span'));
});
});

describe('drawNode function', () => {
it('extracts values from vertex.data', () => {
const dataKey = 'data-key';
const dataValue = 'data-value';
const drawNodeResult = drawNode({
const dataKey = 'data-key';
const dataValue = 'data-value';
const key = 'vertex key';
const vertex = {
data: {
data: {
data: {
[dataKey]: dataValue,
},
members,
operation,
service,
[dataKey]: dataValue,
},
});
members,
operation,
service,
},
key,
};

it('extracts values from vertex.data', () => {
const drawNodeResult = drawNodeGenerator(new Set())(vertex);
expect(drawNodeResult.props[dataKey]).toBe(dataValue);
expect(drawNodeResult.props.isUiFindMatch).toBe(false);
expect(drawNodeResult.props.members).toBe(members);
expect(drawNodeResult.props.operation).toBe(operation);
expect(drawNodeResult.props.service).toBe(service);
});

it('passes isUiFindMatch as true if key is in set', () => {
const drawNodeResult = drawNodeGenerator(new Set([key]))(vertex);
expect(drawNodeResult.props.isUiFindMatch).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ exports[`TraceDiff render renders as expected 1`] = `
}
}
>
<TraceDiffGraph
<Connect(UnconnectedTraceDiffGraph)
a={
Object {
"id": "trace-id-a",
Expand Down
1 change: 1 addition & 0 deletions packages/jaeger-ui/src/components/TracePage/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ describe('<TracePage>', () => {

describe('calculates hideMap correctly', () => {
it('is true if on traceGraphView', () => {
wrapper.instance().traceDagEV = { vertices: [], nodes: [] };
wrapper.setState({ traceGraphView: true });
expect(wrapper.find(TracePageHeader).prop('hideMap')).toBe(true);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/jaeger-ui/src/utils/plexus/set-on-graph.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

// Copyright (c) 2018 Uber Technologies, Inc.
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
import _get from 'lodash/get';

const BASE_MATCH_SIZE = 8;
const SCALABLE_MATCH_SIZE = 8;
const SCALABLE_MATCH_SIZE = 4;

export function setOnEdgesContainer(state: Object) {
const { zoomTransform } = state;
Expand Down
Loading

0 comments on commit b4afe2d

Please sign in to comment.