Skip to content

Commit

Permalink
Fix metrics_time hook test due to provider changes
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Jun 4, 2020
1 parent c2fadb9 commit cdcff8a
Showing 1 changed file with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { createMemoryHistory } from 'history';
import React from 'react';
import { Router } from 'react-router-dom';
import { mountHook } from 'test_utils/enzyme_helpers';

import { ScopedHistory } from '../../../../../../../../src/core/public';
import { useMetricsTime } from './use_metrics_time';

describe('useMetricsTime hook', () => {
describe('timeRange state', () => {
it('has a default value', () => {
const { getLastHookValue } = mountHook(() => useMetricsTime().timeRange);
const { getLastHookValue } = mountHook(
() => useMetricsTime().timeRange,
createProviderWrapper()
);
const hookValue = getLastHookValue();
expect(hookValue).toHaveProperty('from');
expect(hookValue).toHaveProperty('to');
expect(hookValue.interval).toBe('>=1m');
});

it('can be updated', () => {
const { act, getLastHookValue } = mountHook(() => useMetricsTime());
const { act, getLastHookValue } = mountHook(() => useMetricsTime(), createProviderWrapper());

const timeRange = {
from: 'now-15m',
Expand All @@ -37,12 +43,15 @@ describe('useMetricsTime hook', () => {

describe('AutoReloading state', () => {
it('has a default value', () => {
const { getLastHookValue } = mountHook(() => useMetricsTime().isAutoReloading);
const { getLastHookValue } = mountHook(
() => useMetricsTime().isAutoReloading,
createProviderWrapper()
);
expect(getLastHookValue()).toBe(false);
});

it('can be updated', () => {
const { act, getLastHookValue } = mountHook(() => useMetricsTime());
const { act, getLastHookValue } = mountHook(() => useMetricsTime(), createProviderWrapper());

act(({ setAutoReload }) => {
setAutoReload(true);
Expand All @@ -52,3 +61,17 @@ describe('useMetricsTime hook', () => {
});
});
});

const createProviderWrapper = () => {
const INITIAL_URL = '/test-basepath/s/test-space/app/metrics';
const history = createMemoryHistory();

history.push(INITIAL_URL);
const scopedHistory = new ScopedHistory(history, INITIAL_URL);

const ProviderWrapper: React.FC = ({ children }) => {
return <Router history={scopedHistory}>{children}</Router>;
};

return ProviderWrapper;
};

0 comments on commit cdcff8a

Please sign in to comment.