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

Time series - tests #1198

Merged
Changes from 6 commits
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
120 changes: 120 additions & 0 deletions src/components/experiment-tracking/time-series/time-series.test.js
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 = [
Copy link
Contributor

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

'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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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 hoveredElementIndex


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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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
expect(runLine.hasClass('time-series__run-line--blend')).toBe(false);

and if you pass multiple selectedRuns, this will be true

expect(runLine.hasClass('time-series__run-line--blend')).toBe(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);
});
});