Skip to content

Commit

Permalink
fixing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Aug 24, 2020
1 parent f8a4527 commit a31359c
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { wait } from '@testing-library/react';
import { MockApmPluginContextWrapper } from '../../../../context/ApmPluginContext/MockApmPluginContext';

const mockHistoryPush = jest.spyOn(history, 'push');
const mockHistoryReplace = jest.spyOn(history, 'replace');
const mockRefreshTimeRange = jest.fn();
function MockUrlParamsProvider({
params = {},
Expand Down Expand Up @@ -69,8 +70,8 @@ describe('DatePicker', () => {

it('sets default query params in the URL', () => {
mountDatePicker();
expect(mockHistoryPush).toHaveBeenCalledTimes(1);
expect(mockHistoryPush).toHaveBeenCalledWith(
expect(mockHistoryReplace).toHaveBeenCalledTimes(1);
expect(mockHistoryReplace).toHaveBeenCalledWith(
expect.objectContaining({
search: 'rangeFrom=now-15m&rangeTo=now',
})
Expand All @@ -82,8 +83,8 @@ describe('DatePicker', () => {
rangeTo: 'now',
refreshInterval: 5000,
});
expect(mockHistoryPush).toHaveBeenCalledTimes(1);
expect(mockHistoryPush).toHaveBeenCalledWith(
expect(mockHistoryReplace).toHaveBeenCalledTimes(1);
expect(mockHistoryReplace).toHaveBeenCalledWith(
expect.objectContaining({
search: 'rangeFrom=now-15m&rangeTo=now&refreshInterval=5000',
})
Expand All @@ -97,18 +98,19 @@ describe('DatePicker', () => {
refreshPaused: false,
refreshInterval: 5000,
});
expect(mockHistoryPush).toHaveBeenCalledTimes(0);
expect(mockHistoryReplace).toHaveBeenCalledTimes(0);
});

it('updates the URL when the date range changes', () => {
const datePicker = mountDatePicker();
expect(mockHistoryReplace).toHaveBeenCalledTimes(1);
datePicker.find(EuiSuperDatePicker).props().onTimeChange({
start: 'updated-start',
end: 'updated-end',
isInvalid: false,
isQuickSelection: true,
});
expect(mockHistoryPush).toHaveBeenCalledTimes(2);
expect(mockHistoryPush).toHaveBeenCalledTimes(1);
expect(mockHistoryPush).toHaveBeenLastCalledWith(
expect.objectContaining({
search: 'rangeFrom=updated-start&rangeTo=updated-end',
Expand Down

0 comments on commit a31359c

Please sign in to comment.