Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add uiFind icons, scroll to first match #367

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bolster test coverage for files in PR
Signed-off-by: Everett Ross <reverett@uber.com>
  • Loading branch information
everett980 committed Apr 12, 2019
commit 79eb6df2f7a55c9879d68a4c82d803fa84330c0a
52 changes: 44 additions & 8 deletions packages/jaeger-ui/src/components/TracePage/ScrollManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import ScrollManager from './ScrollManager';
const SPAN_HEIGHT = 2;

function getTrace() {
let nextSpanID = 0;
const spans = [];
const trace = {
spans,
duration: 2000,
startTime: 1000,
};
for (let i = 0; i < 10; i++) {
spans.push({ duration: 1, startTime: 1000, spanID: nextSpanID++ });
spans.push({ duration: 1, startTime: 1000, spanID: i + 1 });
}
return trace;
}
Expand Down Expand Up @@ -106,6 +105,9 @@ describe('ScrollManager', () => {
});

describe('_scrollToVisibleSpan()', () => {
function getRefs(spanID) {
return [{ refType: 'CHILD_OF', spanID }];
}
let scrollPastMock;

beforeEach(() => {
Expand Down Expand Up @@ -142,7 +144,7 @@ describe('ScrollManager', () => {

it('skips spans that are out of view', () => {
trace.spans[4].startTime = trace.startTime + trace.duration * 0.5;
accessors.getViewRange = jest.fn(() => [0.4, 0.6]);
accessors.getViewRange = () => [0.4, 0.6];
accessors.getTopRowIndexVisible.mockReturnValue(trace.spans.length - 1);
accessors.getBottomRowIndexVisible.mockReturnValue(0);
manager._scrollToVisibleSpan(1);
Expand All @@ -154,18 +156,41 @@ describe('ScrollManager', () => {
it('skips spans that do not match the text search', () => {
accessors.getTopRowIndexVisible.mockReturnValue(trace.spans.length - 1);
accessors.getBottomRowIndexVisible.mockReturnValue(0);
accessors.getSearchedSpanIDs = jest.fn(() => new Set([trace.spans[4].spanID]));
accessors.getSearchedSpanIDs = () => new Set([trace.spans[4].spanID]);
manager._scrollToVisibleSpan(1);
expect(scrollPastMock).lastCalledWith(4, 1);
manager._scrollToVisibleSpan(-1);
expect(scrollPastMock).lastCalledWith(4, -1);
});

describe('scrollToNextVisibleSpan() and scrollToPrevVisibleSpan()', () => {
function getRefs(spanID) {
return [{ refType: 'CHILD_OF', spanID }];
}
it('scrolls to boundary when scrolling away from closest spanID in findMatches', () => {
const closetFindMatchesSpanID = 4;
accessors.getTopRowIndexVisible.mockReturnValue(closetFindMatchesSpanID - 1);
accessors.getBottomRowIndexVisible.mockReturnValue(closetFindMatchesSpanID + 1);
accessors.getSearchedSpanIDs = () => new Set([trace.spans[closetFindMatchesSpanID].spanID]);

manager._scrollToVisibleSpan(1);
expect(scrollPastMock).lastCalledWith(trace.spans.length - 1, 1);

manager._scrollToVisibleSpan(-1);
expect(scrollPastMock).lastCalledWith(0, -1);
});

it('scrolls to last visible row when boundary is hidden', () => {
const parentOfLastRowWithHiddenChildrenIndex = trace.spans.length - 2;
accessors.getBottomRowIndexVisible.mockReturnValue(0);
accessors.getCollapsedChildren = () =>
new Set([trace.spans[parentOfLastRowWithHiddenChildrenIndex].spanID]);
accessors.getSearchedSpanIDs = () => new Set([trace.spans[0].spanID]);
trace.spans[trace.spans.length - 1].references = getRefs(
trace.spans[parentOfLastRowWithHiddenChildrenIndex].spanID
);

manager._scrollToVisibleSpan(1);
expect(scrollPastMock).lastCalledWith(parentOfLastRowWithHiddenChildrenIndex, 1);
});

describe('scrollToNextVisibleSpan() and scrollToPrevVisibleSpan()', () => {
beforeEach(() => {
// change spans so 0 and 4 are top-level and their children are collapsed
const spans = trace.spans;
Expand Down Expand Up @@ -213,6 +238,17 @@ describe('ScrollManager', () => {
expect(scrollPastMock).lastCalledWith(4, -1);
});
});

describe('scrollToFirstVisibleSpan', () => {
beforeEach(() => {
jest.spyOn(manager, '_scrollToVisibleSpan').mockImplementationOnce();
});

it('calls _scrollToVisibleSpan searching downwards from first span', () => {
manager.scrollToFirstVisibleSpan();
expect(manager._scrollToVisibleSpan).toHaveBeenCalledWith(1, 0);
});
});
});

describe('scrollPageDown() and scrollPageUp()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import React from 'react';
import { shallow, mount } from 'enzyme';
import { Link } from 'react-router-dom';

import AltViewOptions from './AltViewOptions';
import KeyboardShortcutsHelp from './KeyboardShortcutsHelp';
Expand Down Expand Up @@ -110,6 +111,14 @@ describe('<TracePageHeader>', () => {
expect(wrapper.find(AltViewOptions).length).toBe(0);
});

it('renders the link to search', () => {
expect(wrapper.find(Link).length).toBe(0);

const toSearch = 'some-link';
wrapper.setProps({ toSearch });
expect(wrapper.find({ to: toSearch }).length).toBe(1);
});

it('toggles the standalone link', () => {
const linkToStandalone = 'some-link';
const props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ import React from 'react';
import { shallow } from 'enzyme';

import * as markers from './TracePageSearchBar.markers';
import { TracePageSearchBarFn as TracePageSearchBar } from './TracePageSearchBar';
import DefaultTracePageSearchBar, { TracePageSearchBarFn as TracePageSearchBar } from './TracePageSearchBar';
import { trackFilter } from '../index.track';
import UiFindInput from '../../common/UiFindInput';

describe('<TracePageSearchBar>', () => {
const defaultProps = {
forwardedRef: React.createRef(),
navigable: true,
nextResult: () => {},
prevResult: () => {},
resultCount: 0,
textFilter: 'something',
};
const defaultProps = {
forwardedRef: React.createRef(),
navigable: true,
nextResult: () => {},
prevResult: () => {},
resultCount: 0,
textFilter: 'something',
};

describe('<TracePageSearchBar>', () => {
let wrapper;

beforeEach(() => {
Expand Down Expand Up @@ -94,3 +94,12 @@ describe('<TracePageSearchBar>', () => {
});
});
});

describe('<DefaultTracePageSearchBar>', () => {
const { forwardedRef: ref, ...propsWithoutRef } = defaultProps;

it('forwardsRef correctly', () => {
const wrapper = shallow(<DefaultTracePageSearchBar {...propsWithoutRef} ref={ref} />);
expect(wrapper.find(TracePageSearchBar).props()).toEqual(defaultProps);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,18 @@ describe('TraceTimelineViewer/duck', () => {
it('toggles a log item', () => {
const logItem = 'hello-log-item';
const id = trace.spans[0].spanID;
const secondID = trace.spans[1].spanID;
const baseDetail = new DetailState();
const toggledDetail = baseDetail.toggleLogItem(logItem);

store.dispatch(actions.detailToggle(id));
store.dispatch(actions.detailToggle(secondID));
const secondDetail = store.getState().detailStates.get(secondID);
expect(store.getState().detailStates.get(id)).toEqual(baseDetail);

store.dispatch(actions.detailLogItemToggle(id, logItem));
expect(store.getState().detailStates.get(id)).toEqual(toggledDetail);
expect(store.getState().detailStates.get(secondID)).toBe(secondDetail);
});

describe('hoverIndentGuideIds', () => {
Expand Down
79 changes: 77 additions & 2 deletions packages/jaeger-ui/src/components/TracePage/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ import * as track from './index.track';
import ArchiveNotifier from './ArchiveNotifier';
import { reset as resetShortcuts } from './keyboard-shortcuts';
import { cancel as cancelScroll } from './scroll-page';
import * as calculateTraceDagEV from './TraceGraph/calculateTraceDagEV';
import SpanGraph from './TracePageHeader/SpanGraph';
import TracePageHeader from './TracePageHeader';
import { trackSlimHeaderToggle } from './TracePageHeader/TracePageHeader.track';
import TraceTimelineViewer from './TraceTimelineViewer';
import ErrorMessage from '../common/ErrorMessage';
import LoadingIndicator from '../common/LoadingIndicator';
import * as getUiFindVertexKeys from '../TraceDiff/TraceDiffGraph/traceDiffGraphUtils';
import { fetchedState } from '../../constants';
import traceGenerator from '../../demo/trace-generators';
import transformTraceData from '../../model/transform-trace-data';
Expand Down Expand Up @@ -84,6 +86,7 @@ describe('<TracePage>', () => {
const defaultProps = {
acknowledgeArchive: () => {},
fetchTrace() {},
focusUiFindMatches: jest.fn(),
id: trace.traceID,
history: {
replace: () => {},
Expand Down Expand Up @@ -132,6 +135,32 @@ describe('<TracePage>', () => {
});
});

describe('focusUiFindMatches', () => {
let scrollToFirstVisibleSpanSpy;

beforeEach(() => {
scrollToFirstVisibleSpanSpy = jest.spyOn(wrapper.instance()._scrollManager, 'scrollToFirstVisibleSpan');
scrollToFirstVisibleSpanSpy.mockReset();
defaultProps.focusUiFindMatches.mockReset();
});

it('calls _scrollManager.scrollToFirstVisibleSpan and props.focusUiFindMatches with props.trace.data and uiFind when props.trace.data is present', () => {
everett980 marked this conversation as resolved.
Show resolved Hide resolved
const uiFind = 'test ui find';
wrapper.setProps({ uiFind });
wrapper.find(TracePageHeader).prop('focusUiFindMatches')();
expect(defaultProps.focusUiFindMatches).toHaveBeenCalledWith(defaultProps.trace.data, uiFind);
expect(scrollToFirstVisibleSpanSpy).toHaveBeenCalled();
});

it('handles when props.trace.data is absent', () => {
const propFn = wrapper.find(TracePageHeader).prop('focusUiFindMatches');
wrapper.setProps({ trace: {} });
propFn();
expect(defaultProps.focusUiFindMatches).not.toHaveBeenCalled();
expect(scrollToFirstVisibleSpanSpy).not.toHaveBeenCalled();
});
});

it('uses props.uiFind, props.trace.traceID, and props.trace.spans.length to create filterSpans memo cache key', () => {
expect(filterSpansSpy).toHaveBeenCalledTimes(0);

Expand Down Expand Up @@ -331,7 +360,17 @@ describe('<TracePage>', () => {
});

describe('resultCount', () => {
it('is the size of findMatchesIDs when available', () => {
let getUiFindVertexKeysSpy;

beforeAll(() => {
getUiFindVertexKeysSpy = jest.spyOn(getUiFindVertexKeys, 'getUiFindVertexKeys');
});

beforeEach(() => {
getUiFindVertexKeysSpy.mockReset();
});

it('is the size of spanFindMatches when available', () => {
expect(wrapper.find(TracePageHeader).prop('resultCount')).toBe(0);

const size = 20;
Expand All @@ -340,9 +379,26 @@ describe('<TracePage>', () => {
expect(wrapper.find(TracePageHeader).prop('resultCount')).toBe(size);
});

it('is the size of graphFindMatches when available', () => {
expect(wrapper.find(TracePageHeader).prop('resultCount')).toBe(0);

const size = 30;
getUiFindVertexKeysSpy.mockReturnValueOnce({ size });
wrapper.setState({ traceGraphView: true });
wrapper.setProps({ uiFind: 'new ui find to bust memo' });
expect(wrapper.find(TracePageHeader).prop('resultCount')).toBe(size);
});

it('defaults to 0', () => {
// falsy uiFind for base case
wrapper.setProps({ uiFind: '' });
expect(wrapper.find(TracePageHeader).prop('resultCount')).toBe(0);

filterSpansSpy.mockReturnValueOnce(null);
wrapper.setProps({ uiFind: 'new ui find to bust memo' });
wrapper.setProps({ uiFind: 'truthy uiFind' });
expect(wrapper.find(TracePageHeader).prop('resultCount')).toBe(0);

wrapper.setState({ traceGraphView: true });
expect(wrapper.find(TracePageHeader).prop('resultCount')).toBe(0);
});
});
Expand Down Expand Up @@ -458,13 +514,18 @@ describe('<TracePage>', () => {
let header;
let spanGraph;
let timeline;
let calculateTraceDagEVSpy;

function refreshWrappers() {
header = wrapper.find(TracePageHeader);
spanGraph = wrapper.find(SpanGraph);
timeline = wrapper.find(TraceTimelineViewer);
}

beforeAll(() => {
calculateTraceDagEVSpy = jest.spyOn(calculateTraceDagEV, 'default');
});

beforeEach(() => {
wrapper = mount(<TracePage {...defaultProps} />);
// use the method directly because it is a `ref` prop
Expand All @@ -490,6 +551,15 @@ describe('<TracePage>', () => {
expect(sections.length).toBe(0);
});

it('initializes slimView correctly', () => {
expect(wrapper.state('slimView')).toBe(false);
// Empty trace avoids this spec from evaluating TracePageHeader's consumption of slimView
wrapper = mount(
<TracePage {...defaultProps} trace={{}} embedded={{ timeline: { collapseTitle: true } }} />
);
expect(wrapper.state('slimView')).toBe(true);
});

it('propagates slimView changes', () => {
const { onSlimViewClicked } = header.props();
expect(header.prop('slimView')).toBe(false);
Expand All @@ -516,6 +586,11 @@ describe('<TracePage>', () => {
wrapper.update();
refreshWrappers();
expect(header.prop('traceGraphView')).toBe(true);
expect(calculateTraceDagEVSpy).toHaveBeenCalledWith(defaultProps.trace.data);

wrapper.setProps({ trace: {} });
onTraceGraphViewClicked();
expect(calculateTraceDagEVSpy).toHaveBeenCalledTimes(1);
});

it('propagates viewRange changes', () => {
Expand Down
18 changes: 7 additions & 11 deletions packages/jaeger-ui/src/components/TracePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ export class TracePageImpl extends React.PureComponent<TProps, TState> {
}

componentWillReceiveProps(nextProps: TProps) {
if (this._scrollManager) {
const { trace } = nextProps;
this._scrollManager.setTrace(trace && trace.data);
}
const { trace } = nextProps;
this._scrollManager.setTrace(trace && trace.data);
}

componentDidUpdate({ id: prevID }: TProps) {
Expand All @@ -204,13 +202,11 @@ export class TracePageImpl extends React.PureComponent<TProps, TState> {
componentWillUnmount() {
resetShortcuts();
cancelScroll();
if (this._scrollManager) {
this._scrollManager.destroy();
this._scrollManager = new ScrollManager(undefined, {
scrollBy,
scrollTo,
});
}
this._scrollManager.destroy();
this._scrollManager = new ScrollManager(undefined, {
scrollBy,
scrollTo,
});
}

_adjustViewRange(startChange: number, endChange: number, trackSrc: string) {
Expand Down