Skip to content

Commit

Permalink
Fix TracePageHeader and TracePageSearchBar tests
Browse files Browse the repository at this point in the history
Signed-off-by: Davit Yeghshatyan <davo@uber.com>
  • Loading branch information
Davit Yeghshatyan committed Aug 22, 2018
1 parent 7bdc815 commit 98ca290
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
10 changes: 6 additions & 4 deletions packages/jaeger-ui/src/components/TracePage/TracePageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.

import * as React from 'react';
import { Button, Dropdown, Icon, Menu } from 'antd';
import { Button, Dropdown, Icon, Input, Menu } from 'antd';
import IoChevronDown from 'react-icons/lib/io/chevron-down';
import IoChevronRight from 'react-icons/lib/io/chevron-right';
import IoIosFilingOutline from 'react-icons/lib/io/ios-filing-outline';
Expand All @@ -41,6 +41,7 @@ type TracePageHeaderProps = {
prevResult: () => void,
nextResult: () => void,
clearSearch: () => void,
forwardedRef: { current: Input | null },
resultCount: number,
archiveButtonVisible: boolean,
onArchiveClicked: () => void,
Expand Down Expand Up @@ -90,7 +91,7 @@ export const HEADER_ITEMS = [
},
];

function TracePageHeader(props: TracePageHeaderProps, ref: any) {
export function TracePageHeaderFn(props: TracePageHeaderProps) {
const {
archiveButtonVisible,
onArchiveClicked,
Expand All @@ -109,6 +110,7 @@ function TracePageHeader(props: TracePageHeaderProps, ref: any) {
nextResult,
clearSearch,
resultCount,
forwardedRef,
} = props;

if (!traceID) {
Expand Down Expand Up @@ -185,7 +187,7 @@ function TracePageHeader(props: TracePageHeaderProps, ref: any) {
nextResult={nextResult}
clearSearch={clearSearch}
resultCount={resultCount}
ref={ref}
ref={forwardedRef}
/>
<Dropdown overlay={viewMenu}>
<Button className="ub-mr2">
Expand All @@ -206,4 +208,4 @@ function TracePageHeader(props: TracePageHeaderProps, ref: any) {

// ghetto fabulous cast because the 16.3 API is not in flow yet
// https://github.com/facebook/flow/issues/6103
export default (React: any).forwardRef(TracePageHeader);
export default (React: any).forwardRef((props, ref) => <TracePageHeaderFn {...props} forwardedRef={ref} />);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import React from 'react';
import { shallow, mount } from 'enzyme';

import TracePageHeader, { HEADER_ITEMS } from './TracePageHeader';
import { TracePageHeaderFn as TracePageHeader, HEADER_ITEMS } from './TracePageHeader';

describe('<TracePageHeader>', () => {
const defaultProps = {
Expand Down
23 changes: 16 additions & 7 deletions packages/jaeger-ui/src/components/TracePage/TracePageSearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ type TracePageSearchBarProps = {
nextResult: () => void,
clearSearch: () => void,
resultCount: number,
forwardedRef: { current: Input | null },
};

function TracePageSearchBar(props: TracePageSearchBarProps, ref: any) {
const { prevResult, nextResult, clearSearch, resultCount, updateTextFilter, textFilter } = props;
export function TracePageSearchBarFn(props: TracePageSearchBarProps) {
const {
prevResult,
nextResult,
clearSearch,
resultCount,
updateTextFilter,
textFilter,
forwardedRef,
} = props;

const count = textFilter ? (
<span className="TracePageSearchBar--count">{resultCount.toString()}</span>
) : null;
const count = textFilter ? <span className="TracePageSearchBar--count">{resultCount}</span> : null;

const updateFilter = event => updateTextFilter(event.target.value);
const onKeyDown = e => {
Expand All @@ -56,7 +63,7 @@ function TracePageSearchBar(props: TracePageSearchBarProps, ref: any) {
value={textFilter}
data-test={markers.IN_TRACE_SEARCH}
suffix={count}
ref={ref}
ref={forwardedRef}
onKeyDown={onKeyDown}
onPressEnter={nextResult}
/>
Expand All @@ -70,4 +77,6 @@ function TracePageSearchBar(props: TracePageSearchBarProps, ref: any) {

// ghetto fabulous cast because the 16.3 API is not in flow yet
// https://github.com/facebook/flow/issues/6103
export default (React: any).forwardRef(TracePageSearchBar);
export default (React: any).forwardRef((props, ref) => (
<TracePageSearchBarFn {...props} forwardedRef={ref} />
));
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
// limitations under the License.

import React from 'react';
import sinon from 'sinon';
import { shallow } from 'enzyme';

import * as markers from './TracePageSearchBar.markers';
import TracePageSearchBar from './TracePageSearchBar';
import { TracePageSearchBarFn as TracePageSearchBar } from './TracePageSearchBar';

describe('<TracePageSearchBar>', () => {
const defaultProps = {
Expand All @@ -35,15 +34,15 @@ describe('<TracePageSearchBar>', () => {
});

it('calls updateTextFilter() function for onChange of the input', () => {
const updateTextFilter = sinon.spy();
const updateTextFilter = jest.fn();
const props = { ...defaultProps, updateTextFilter };
wrapper = shallow(<TracePageSearchBar {...props} />);
const event = { target: { value: 'my new value' } };
wrapper
.find(`[data-test="${markers.IN_TRACE_SEARCH}"]`)
.first()
.simulate('change', event);
expect(updateTextFilter.calledWith('my new value')).toBeTruthy();
expect(updateTextFilter.mock.calls.length).toBe(1);
});

it('renders the search bar', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type TraceTimelineViewerProps = {
collapseOne: (Span[]) => void,
expandAll: () => void,
expandOne: (Span[]) => void,
findMatchesIDs: Set<string>,
findMatchesIDs: ?Set<string>,
spanNameColumnWidth: number,
trace: Trace,
updateNextViewRangeTime: ViewRangeTimeUpdate => void,
Expand Down
7 changes: 4 additions & 3 deletions packages/jaeger-ui/src/components/TracePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import _values from 'lodash/values';
import { connect } from 'react-redux';
import type { RouterHistory, Match } from 'react-router-dom';
import { bindActionCreators } from 'redux';
import { Input } from 'antd';

import ArchiveNotifier from './ArchiveNotifier';
import { actions as archiveActions } from './ArchiveNotifier/duck';
Expand Down Expand Up @@ -101,7 +102,7 @@ export class TracePageImpl extends React.PureComponent<TracePageProps, TracePage
state: TracePageState;

_headerElm: ?Element;
_searchBar: any;
_searchBar: { current: Input | null };
_scrollManager: ScrollManager;

constructor(props: TracePageProps) {
Expand Down Expand Up @@ -230,11 +231,11 @@ export class TracePageImpl extends React.PureComponent<TracePageProps, TracePage

clearSearch = () => {
this.updateTextFilter('');
this._searchBar.current.blur();
if (this._searchBar.current) this._searchBar.current.blur();
};

focusOnSearchBar = () => {
this._searchBar.current.focus();
if (this._searchBar.current) this._searchBar.current.focus();
};

updateViewRangeTime = (start: number, end: number, trackSrc?: string) => {
Expand Down

0 comments on commit 98ca290

Please sign in to comment.