-
Notifications
You must be signed in to change notification settings - Fork 114
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
Time series - tests #1198
Time series - tests #1198
Changes from 6 commits
5c21486
f11d7df
1afa2c2
7066ab3
bce3781
d07514b
8057130
7385884
d7a912f
ac558f9
ec93726
6ebbb59
d728441
df7b5c0
1e2f6c7
98f1d8a
94588a4
e5278b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { TimeSeries } from './time-series'; | ||
import { HoverStateContext } from '../utils/hover-state-context'; | ||
import { data } from '../mock-data'; | ||
|
||
const selectedRuns = [ | ||
'2022-09-05T12.22.35.825Z', | ||
'2022-08-24T21.05.59.296Z', | ||
'2022-07-22T13.49.08.764Z', | ||
]; | ||
|
||
describe('TimeSeries', () => { | ||
const width = jest | ||
.spyOn(document, 'querySelector') | ||
.mockImplementation(() => 100); | ||
|
||
const metricsKeys = Object.keys(data.metrics); | ||
|
||
const runKeys = Object.keys(data.runs); | ||
const runData = Object.entries(data.runs); | ||
|
||
const mockValue = { | ||
hoveredElementId: runKeys[0], | ||
setHoveredElementId: jest.fn(), | ||
}; | ||
|
||
const wrapper = mount( | ||
<HoverStateContext.Provider value={mockValue}> | ||
<TimeSeries metricsData={data} selectedRuns={selectedRuns}></TimeSeries> | ||
</HoverStateContext.Provider> | ||
); | ||
|
||
it('renders without crashing', () => { | ||
expect(wrapper.find('.time-series').length).toBe(1); | ||
}); | ||
it('constructs an svg for each metric', () => { | ||
const svg = wrapper.find('.time-series').find('svg'); | ||
expect(svg.length).toBe(metricsKeys.length); | ||
}); | ||
it('draw X, Y and dual axes for each metric chart', () => { | ||
const xAxis = wrapper | ||
.find('.time-series') | ||
.find('svg') | ||
.find('g') | ||
.find('.time-series__runs-axis'); | ||
expect(xAxis.length).toBe(metricsKeys.length); | ||
|
||
const yAxis = wrapper | ||
.find('.time-series') | ||
.find('svg') | ||
.find('g') | ||
.find('.time-series__metric-axis'); | ||
expect(yAxis.length).toBe(metricsKeys.length); | ||
|
||
const dualAxis = wrapper | ||
.find('.time-series') | ||
.find('svg') | ||
.find('g') | ||
.find('.time-series__metric-axis-dual'); | ||
expect(dualAxis.length).toBe(metricsKeys.length); | ||
}); | ||
it('draw metricLine for each metric', () => { | ||
const metricLine = wrapper | ||
.find('.time-series') | ||
.find('svg') | ||
.find('g') | ||
.find('.time-series__metric-line'); | ||
expect(metricLine.length).toBe(metricsKeys.length); | ||
}); | ||
it('draw runLines for each metric', () => { | ||
const runLines = wrapper | ||
.find('.time-series') | ||
.find('svg') | ||
.find('g') | ||
.find('.time-series__run-lines') | ||
.find('.time-series__run-line'); | ||
expect(runLines.length).toBe(runData.length * metricsKeys.length); | ||
}); | ||
it('applies hovered class to the correct runLine', () => { | ||
const runLine = wrapper | ||
.find('.time-series') | ||
.find('svg') | ||
.find('g') | ||
.find('.time-series__run-lines') | ||
.find('line') | ||
.at(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this index === 0 is using in different tests, can make a variable for it please? Something like |
||
|
||
expect(runLine.hasClass('time-series__run-line--hovered')).toBe(true); | ||
}); | ||
|
||
it('applies blend class to the correct runLine', () => { | ||
const runLine = wrapper | ||
.find('.time-series') | ||
.find('svg') | ||
.find('g') | ||
.find('.time-series__run-lines') | ||
.find('line') | ||
.at(0); | ||
|
||
expect(selectedRuns.length > 1).toBe(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey this will always return true because you set the selectedRuns value with more than 1 item. I think its better to test if you pass one single selectedRun, this will be false and if you pass multiple selectedRuns, this will be true
|
||
expect(runLine.hasClass('time-series__run-line--blend')).toBe(true); | ||
}); | ||
|
||
it('show tooltip onHover - runLine', () => { | ||
wrapper | ||
.find('.time-series') | ||
.find('svg') | ||
.find('g') | ||
.find('.time-series__run-lines') | ||
.find('line') | ||
.at(0) | ||
.simulate('mouseover'); | ||
|
||
const tooltip = wrapper.find('.time-series').find('.tooltip'); | ||
|
||
expect(tooltip.hasClass('tooltip--show')).toBe(true); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you merge the other main branch in, I already have this mock in the mock-data, you can just re-use from it