-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from jaegertracing/fixit-week/test-coverage
Increase test coverage
- Loading branch information
Showing
28 changed files
with
1,941 additions
and
355 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) 2017 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('./TopNav', () => () => <div />); | ||
jest.mock('../../utils/metrics'); | ||
|
||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { mapStateToProps, PageImpl as Page } from './Page'; | ||
import { trackPageView } from '../../utils/metrics'; | ||
|
||
describe('mapStateToProps()', () => { | ||
it('maps state to props', () => { | ||
const state = { | ||
config: {}, | ||
router: { location: {} }, | ||
}; | ||
const ownProps = { a: {} }; | ||
expect(mapStateToProps(state, ownProps)).toEqual({ | ||
config: state.config, | ||
location: state.router.location, | ||
a: ownProps.a, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('<Page>', () => { | ||
let props; | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
trackPageView.mockReset(); | ||
props = { | ||
location: { | ||
pathname: String(Math.random()), | ||
search: String(Math.random()), | ||
}, | ||
config: { menu: [] }, | ||
}; | ||
wrapper = mount(<Page {...props} />); | ||
}); | ||
|
||
it('does not explode', () => { | ||
expect(wrapper).toBeDefined(); | ||
}); | ||
|
||
it('tracks an initial page-view', () => { | ||
const { pathname, search } = props.location; | ||
expect(trackPageView.mock.calls).toEqual([[pathname, search]]); | ||
}); | ||
|
||
it('tracks a pageView when the location changes', () => { | ||
trackPageView.mockReset(); | ||
const location = { pathname: 'le-path', search: 'searching' }; | ||
wrapper.setProps({ location }); | ||
expect(trackPageView.mock.calls).toEqual([[location.pathname, location.search]]); | ||
}); | ||
}); |
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
116 changes: 116 additions & 0 deletions
116
src/components/DependencyGraph/DependencyForceGraph.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,116 @@ | ||
// Copyright (c) 2017 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 React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { InteractiveForceGraph, ForceGraphNode, ForceGraphLink } from 'react-vis-force'; | ||
|
||
import DependencyForceGraph, { chargeStrength } from './DependencyForceGraph'; | ||
|
||
describe('chargeStrength', () => { | ||
it('returns a number', () => { | ||
expect(chargeStrength({ radius: 1, orphan: false })).toBeLessThan(0); | ||
}); | ||
|
||
it('handles orphan as a special case', () => { | ||
const asOrphan = chargeStrength({ radius: 1, orphan: true }); | ||
const notOrphan = chargeStrength({ radius: 1, orphan: false }); | ||
expect(chargeStrength(asOrphan)).toBeLessThan(0); | ||
expect(chargeStrength(notOrphan)).toBeLessThan(0); | ||
expect(asOrphan).not.toBe(notOrphan); | ||
}); | ||
}); | ||
|
||
describe('<DependencyForceGraph>', () => { | ||
const nodes = [{ id: 'node-a', radius: 1 }, { id: 'node-b', radius: 1 }]; | ||
const links = [{ source: 'node-a', target: 'node-b', value: 1 }]; | ||
let oldSize; | ||
let wrapper; | ||
|
||
beforeAll(() => { | ||
oldSize = { | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
}; | ||
}); | ||
|
||
afterAll(() => { | ||
const { height, width } = oldSize; | ||
window.innerHeight = height; | ||
window.innerWidth = width; | ||
}); | ||
|
||
beforeEach(() => { | ||
window.innerWidth = 1234; | ||
window.innerHeight = 5678; | ||
wrapper = shallow(<DependencyForceGraph nodes={nodes} links={links} />); | ||
}); | ||
|
||
it('does not explode', () => { | ||
expect(wrapper).toBeDefined(); | ||
expect(wrapper.length).toBe(1); | ||
}); | ||
|
||
it('saves the window dimensions to state', () => { | ||
const { height, width } = wrapper.state(); | ||
expect(height).toBe(window.innerHeight); | ||
expect(width).toBe(window.innerWidth); | ||
}); | ||
|
||
describe('window resize event', () => { | ||
it('adds and removes an event listener on mount and unmount', () => { | ||
const oldFns = { | ||
addFn: window.addEventListener, | ||
removeFn: window.removeEventListener, | ||
}; | ||
window.addEventListener = jest.fn(); | ||
window.removeEventListener = jest.fn(); | ||
wrapper = shallow(<DependencyForceGraph nodes={nodes} links={links} />); | ||
expect(window.addEventListener.mock.calls.length).toBe(1); | ||
expect(window.removeEventListener.mock.calls.length).toBe(0); | ||
wrapper.unmount(); | ||
expect(window.removeEventListener.mock.calls.length).toBe(1); | ||
window.addEventListener = oldFns.addFn; | ||
window.removeEventListener = oldFns.removeFn; | ||
}); | ||
|
||
it('updates the saved window dimensions on resize', () => { | ||
const { height: preHeight, width: preWidth } = wrapper.state(); | ||
window.innerHeight *= 2; | ||
window.innerWidth *= 2; | ||
// difficult to get JSDom to dispatch the window resize event, so hit | ||
// the listener directly | ||
wrapper.instance().onResize(); | ||
const { height, width } = wrapper.state(); | ||
expect(height).toBe(window.innerHeight); | ||
expect(width).toBe(window.innerWidth); | ||
expect(height).not.toBe(preHeight); | ||
expect(width).not.toBe(preWidth); | ||
}); | ||
}); | ||
|
||
describe('render', () => { | ||
it('renders a InteractiveForceGraph', () => { | ||
expect(wrapper.find(InteractiveForceGraph).length).toBe(1); | ||
}); | ||
|
||
it('renders a <ForceGraphNode> for each node', () => { | ||
expect(wrapper.find(ForceGraphNode).length).toBe(nodes.length); | ||
}); | ||
|
||
it('renders a <ForceGraphLink> for each link', () => { | ||
expect(wrapper.find(ForceGraphLink).length).toBe(links.length); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.