forked from jaegertracing/jaeger-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track trace alt views (jaegertracing#512)
* Track trace alt views, TODO:test AltViewOptions Signed-off-by: Everett Ross <[email protected]> * Fix year Signed-off-by: Everett Ross <[email protected]> * Test AltViewOptions.tsx, rename toggle ddg prop Signed-off-by: Everett Ross <[email protected]>
- Loading branch information
1 parent
537bbe2
commit 521c2d0
Showing
9 changed files
with
283 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
packages/jaeger-ui/src/components/TracePage/TracePageHeader/AltViewOptions.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// 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. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { Button, Dropdown } from 'antd'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import AltViewOptions from './AltViewOptions'; | ||
import * as track from './TracePageHeader.track'; | ||
|
||
describe('AltViewOptions', () => { | ||
let trackGanttView; | ||
let trackGraphView; | ||
let trackJsonView; | ||
let trackRawJsonView; | ||
|
||
let wrapper; | ||
const getLink = text => { | ||
const menu = shallow(wrapper.find(Dropdown).prop('overlay')); | ||
const links = menu.find(Link); | ||
for (let i = 0; i < links.length; i++) { | ||
const link = links.at(i); | ||
if (link.children().text() === text) return link; | ||
} | ||
const link = menu.find('a'); | ||
if (link.children().text() === text) return link; | ||
throw new Error(`Could not find "${text}"`); | ||
}; | ||
const props = { | ||
traceGraphView: true, | ||
traceID: 'test trace ID', | ||
onTraceGraphViewClicked: jest.fn(), | ||
}; | ||
|
||
beforeAll(() => { | ||
trackGanttView = jest.spyOn(track, 'trackGanttView'); | ||
trackGraphView = jest.spyOn(track, 'trackGraphView'); | ||
trackJsonView = jest.spyOn(track, 'trackJsonView'); | ||
trackRawJsonView = jest.spyOn(track, 'trackRawJsonView'); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
wrapper = shallow(<AltViewOptions {...props} />); | ||
}); | ||
|
||
it('renders correctly', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('tracks viewing JSONs', () => { | ||
expect(trackJsonView).not.toHaveBeenCalled(); | ||
getLink('Trace JSON').simulate('click'); | ||
expect(trackJsonView).toHaveBeenCalledTimes(1); | ||
|
||
expect(trackRawJsonView).not.toHaveBeenCalled(); | ||
getLink('Trace JSON (unadjusted)').simulate('click'); | ||
expect(trackRawJsonView).toHaveBeenCalledTimes(1); | ||
|
||
expect(trackJsonView).toHaveBeenCalledTimes(1); | ||
expect(trackGanttView).not.toHaveBeenCalled(); | ||
expect(trackGraphView).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('toggles and tracks toggle', () => { | ||
expect(trackGanttView).not.toHaveBeenCalled(); | ||
expect(props.onTraceGraphViewClicked).not.toHaveBeenCalled(); | ||
getLink('Trace Timeline').simulate('click'); | ||
expect(trackGanttView).toHaveBeenCalledTimes(1); | ||
expect(props.onTraceGraphViewClicked).toHaveBeenCalledTimes(1); | ||
|
||
wrapper.setProps({ traceGraphView: false }); | ||
expect(trackGraphView).not.toHaveBeenCalled(); | ||
getLink('Trace Graph').simulate('click'); | ||
expect(trackGraphView).toHaveBeenCalledTimes(1); | ||
expect(props.onTraceGraphViewClicked).toHaveBeenCalledTimes(2); | ||
|
||
wrapper.setProps({ traceGraphView: true }); | ||
expect(trackGanttView).toHaveBeenCalledTimes(1); | ||
wrapper.find(Button).simulate('click'); | ||
expect(trackGanttView).toHaveBeenCalledTimes(2); | ||
expect(props.onTraceGraphViewClicked).toHaveBeenCalledTimes(3); | ||
|
||
wrapper.setProps({ traceGraphView: false }); | ||
expect(trackGraphView).toHaveBeenCalledTimes(1); | ||
wrapper.find(Button).simulate('click'); | ||
expect(trackGraphView).toHaveBeenCalledTimes(2); | ||
expect(props.onTraceGraphViewClicked).toHaveBeenCalledTimes(4); | ||
|
||
expect(trackGanttView).toHaveBeenCalledTimes(2); | ||
expect(trackJsonView).not.toHaveBeenCalled(); | ||
expect(trackRawJsonView).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/jaeger-ui/src/components/TracePage/TracePageHeader/TracePageHeader.track.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// 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. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/* eslint-disable import/first */ | ||
|
||
jest.mock('../../../utils/tracking'); | ||
|
||
import * as track from './TracePageHeader.track'; /* { | ||
CATEGORY_ALT_VIEW, | ||
CATEGORY_SLIM_HEADER, | ||
ACTION_GANTT, | ||
ACTION_GRAPH, | ||
ACTION_JSON, | ||
ACTION_RAW_JSON, | ||
} from './index.track'; */ | ||
import { trackEvent } from '../../../utils/tracking'; | ||
import { OPEN, CLOSE } from '../../../utils/tracking/common'; | ||
|
||
describe('TracePageHeader.track', () => { | ||
beforeEach(trackEvent.mockClear); | ||
|
||
const cases = [ | ||
{ | ||
action: track.ACTION_GANTT, | ||
category: track.CATEGORY_ALT_VIEW, | ||
msg: 'tracks a GA event for viewing gantt chart', | ||
fn: 'trackGanttView', | ||
}, | ||
{ | ||
action: track.ACTION_GRAPH, | ||
category: track.CATEGORY_ALT_VIEW, | ||
msg: 'tracks a GA event for viewing trace graph', | ||
fn: 'trackGraphView', | ||
}, | ||
{ | ||
action: track.ACTION_JSON, | ||
category: track.CATEGORY_ALT_VIEW, | ||
msg: 'tracks a GA event for viewing trace JSON', | ||
fn: 'trackJsonView', | ||
}, | ||
{ | ||
action: track.ACTION_RAW_JSON, | ||
category: track.CATEGORY_ALT_VIEW, | ||
msg: 'tracks a GA event for viewing trace JSON (raw)', | ||
fn: 'trackRawJsonView', | ||
}, | ||
{ | ||
action: OPEN, | ||
arg: false, | ||
category: track.CATEGORY_SLIM_HEADER, | ||
msg: 'tracks a GA event for opening slim header', | ||
fn: 'trackSlimHeaderToggle', | ||
}, | ||
{ | ||
action: CLOSE, | ||
arg: true, | ||
category: track.CATEGORY_SLIM_HEADER, | ||
msg: 'tracks a GA event for closing slim header', | ||
fn: 'trackSlimHeaderToggle', | ||
}, | ||
]; | ||
|
||
cases.forEach(({ action, arg, msg, fn, category }) => { | ||
it(msg, () => { | ||
track[fn](arg); | ||
expect(trackEvent.mock.calls.length).toBe(1); | ||
expect(trackEvent.mock.calls[0]).toEqual([category, action]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ger-ui/src/components/TracePage/TracePageHeader/__snapshots__/AltViewOptions.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AltViewOptions renders correctly 1`] = ` | ||
<Dropdown | ||
mouseEnterDelay={0.15} | ||
mouseLeaveDelay={0.1} | ||
overlay={ | ||
<Menu | ||
className="" | ||
focusable={false} | ||
prefixCls="ant-menu" | ||
theme="light" | ||
> | ||
<MenuItem> | ||
<a | ||
onClick={[Function]} | ||
role="button" | ||
> | ||
Trace Timeline | ||
</a> | ||
</MenuItem> | ||
<MenuItem> | ||
<Link | ||
onClick={[MockFunction]} | ||
rel="noopener noreferrer" | ||
replace={false} | ||
target="_blank" | ||
to="/api/traces/test trace ID?prettyPrint=true" | ||
> | ||
Trace JSON | ||
</Link> | ||
</MenuItem> | ||
<MenuItem> | ||
<Link | ||
onClick={[MockFunction]} | ||
rel="noopener noreferrer" | ||
replace={false} | ||
target="_blank" | ||
to="/api/traces/test trace ID?raw=true&prettyPrint=true" | ||
> | ||
Trace JSON (unadjusted) | ||
</Link> | ||
</MenuItem> | ||
</Menu> | ||
} | ||
placement="bottomLeft" | ||
prefixCls="ant-dropdown" | ||
> | ||
<Button | ||
block={false} | ||
className="ub-mr2" | ||
ghost={false} | ||
htmlType="button" | ||
loading={false} | ||
onClick={[Function]} | ||
prefixCls="ant-btn" | ||
> | ||
Alternate Views | ||
<Icon | ||
type="down" | ||
/> | ||
</Button> | ||
</Dropdown> | ||
`; |