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

[Uptime] Remove prototype overwrite in unit test #73709

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ef05965
Remove prototype overwrite in unit test.
justinkambic Jul 29, 2020
56fed24
Wrap calls to prototype functions with jest.spyOn.
justinkambic Jul 29, 2020
15cfb3b
Merge branch 'master' into uptime_ping-histogram-jest-mock-moment
justinkambic Jul 29, 2020
69628a5
add additional component test helpers
dominiqueclarke Jan 7, 2021
afea632
add test examples
dominiqueclarke Jan 7, 2021
0ec06b0
uptime testing utils remove custom prefix from props and parameter op…
dominiqueclarke Jan 7, 2021
97d57a6
skip executed step tests
dominiqueclarke Jan 7, 2021
3294340
adjust MlJobLink test
dominiqueclarke Jan 7, 2021
05b0b6b
add testing util interfaces
dominiqueclarke Jan 7, 2021
dd1da2c
Merge branch 'master' into uptime_ping-histogram-jest-mock-moment
justinkambic Jan 7, 2021
c9e4fd6
Move updated test files to correct locations.
justinkambic Jan 7, 2021
6501666
Move other test file to correct location.
justinkambic Jan 7, 2021
c3f5112
Revert unintended changes from merge.
justinkambic Jan 7, 2021
0b5f791
Revert unintended changes from merge.
justinkambic Jan 7, 2021
959c45e
update mock core
dominiqueclarke Jan 7, 2021
48f1536
combine wrappers into one custom render function
dominiqueclarke Jan 7, 2021
4f57662
Move mock helpers to helper file. Update snapshots.
justinkambic Jan 7, 2021
aa70db5
Refactor tests to use RTL over enzyme.
justinkambic Jan 7, 2021
5ade268
Merge branch 'master' into tests/uptime-testing-utils
kibanamachine Jan 11, 2021
6a2cc03
Merge branch 'tests/uptime-testing-utils' into prototype-overwrite-wi…
justinkambic Jan 11, 2021
fd10c59
Refactor \`PingHistogram\` component tests to prefer RTL to Enzyme.
justinkambic Jan 11, 2021
c8d188f
Drop obsolete snapshot file.
justinkambic Jan 11, 2021
f143036
Merge branch 'master' into prototype-overwrite-with-new-testing-utils
justinkambic Jan 12, 2021
50949ec
Remove obsolete file leftover from merge error.
justinkambic Jan 12, 2021
f7ba9eb
Fix outdated import path.
justinkambic Jan 12, 2021
98bdfe0
Prefer custom render to vanilla.
justinkambic Jan 12, 2021
2a22f29
Fix formatting issue uncovered by unit test, and update test assertion.
justinkambic Jan 12, 2021
a98b048
Add test for single location.
justinkambic Jan 12, 2021
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
*/

import React from 'react';
import DateMath from '@elastic/datemath';
import { PingHistogramComponent, PingHistogramComponentProps } from './ping_histogram';
import { renderWithRouter, shallowWithRouter, MountWithReduxProvider } from '../../../lib';
import moment from 'moment';
import { render } from '../../../lib/helper/rtl_helpers';
import { mockDataPlugin, mockMoment, mockMomentTimezone } from '../../../lib/helper/test_helpers';

describe('PingHistogram component', () => {
let dateMathSpy: any;
beforeAll(() => {
moment.prototype.fromNow = jest.fn(() => 'a year ago');
mockMoment();
mockMomentTimezone();
mockDataPlugin();
Comment on lines +16 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of running these in each test, do you think we should move these as part of jest setup?

in uptime jest.config.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this in a follow-up: elastic/uptime#283

dateMathSpy = jest.spyOn(DateMath, 'parse');
dateMathSpy.mockReturnValue(20);
});

afterAll(() => {
jest.clearAllMocks();
});

const props: PingHistogramComponentProps = {
Expand Down Expand Up @@ -48,18 +58,13 @@ describe('PingHistogram component', () => {
},
};

it('shallow renders the component without errors', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided this test wasn't worth keeping. It asserted that the PingHistogramComponent contained the props that were passed to it, and not much else.

Rendering these components doesn't yield SVG or any other method of ensuring the data is rendered by Elastic Charts, but we also should not be testing those capabilities in our repo.

const component = shallowWithRouter(<PingHistogramComponent {...props} />);
expect(component).toMatchSnapshot();
});

it('renders the component without errors', () => {
const component = renderWithRouter(
<MountWithReduxProvider>
<PingHistogramComponent {...props} />
</MountWithReduxProvider>
const { getByLabelText, getByText } = render(<PingHistogramComponent {...props} />);
expect(getByText('Pings over time'));
expect(
getByLabelText(
'Bar Chart showing uptime status over time from 15 minutes ago to 15 minutes ago.'
)
);

expect(component).toMatchSnapshot();
});
});
Loading