-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…44989) This PR fixes a regression which didn't stop the date picker refresh when switching from the anomaly detection jobs list to single metric viewer. Includes unit tests which would fail without the fix.
- Loading branch information
Showing
5 changed files
with
242 additions
and
14 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
.../plugins/ml/public/components/navigation_menu/top_nav/__snapshots__/top_nav.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
x-pack/legacy/plugins/ml/public/components/navigation_menu/top_nav/top_nav.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { mount, shallow } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import { uiTimefilterMock } from '../../../contexts/ui/__mocks__/mocks'; | ||
import { mlTimefilterRefresh$ } from '../../../services/timefilter_refresh_service'; | ||
|
||
import { MlSuperDatePickerWithUpdate, TopNav } from './top_nav'; | ||
|
||
uiTimefilterMock.enableAutoRefreshSelector(); | ||
uiTimefilterMock.enableTimeRangeSelector(); | ||
|
||
jest.mock('../../../contexts/ui/use_ui_context'); | ||
|
||
const noop = () => {}; | ||
|
||
describe('Navigation Menu: <TopNav />', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
test('Minimal initialization.', () => { | ||
const refreshListener = jest.fn(); | ||
const refreshSubscription = mlTimefilterRefresh$.subscribe(refreshListener); | ||
|
||
const wrapper = shallow(<TopNav />); | ||
expect(wrapper).toMatchSnapshot(); | ||
expect(refreshListener).toBeCalledTimes(0); | ||
|
||
refreshSubscription.unsubscribe(); | ||
}); | ||
|
||
// The following tests are written against MlSuperDatePickerWithUpdate | ||
// instead of TopNav. TopNav uses hooks and we cannot writing tests | ||
// with async hook updates yet until React 16.9 is available. | ||
|
||
// MlSuperDatePickerWithUpdate fixes an issue with EuiSuperDatePicker | ||
// which didn't make it into Kibana 7.4. We should be able to just | ||
// use EuiSuperDatePicker again once the following PR is in EUI: | ||
// https://github.com/elastic/eui/pull/2298 | ||
|
||
test('Listen for consecutive super date picker refreshs.', async () => { | ||
const onRefresh = jest.fn(); | ||
|
||
const componentRefresh = mount( | ||
<MlSuperDatePickerWithUpdate | ||
onTimeChange={noop} | ||
isPaused={false} | ||
onRefresh={onRefresh} | ||
refreshInterval={10} | ||
/> | ||
); | ||
|
||
const instanceRefresh = componentRefresh.instance(); | ||
|
||
jest.advanceTimersByTime(10); | ||
// @ts-ignore | ||
await instanceRefresh.asyncInterval.__pendingFn; | ||
jest.advanceTimersByTime(10); | ||
// @ts-ignore | ||
await instanceRefresh.asyncInterval.__pendingFn; | ||
|
||
expect(onRefresh).toBeCalledTimes(2); | ||
}); | ||
|
||
test('Switching refresh interval to pause should stop onRefresh being called.', async () => { | ||
const onRefresh = jest.fn(); | ||
|
||
const componentRefresh = mount( | ||
<MlSuperDatePickerWithUpdate | ||
onTimeChange={noop} | ||
isPaused={false} | ||
onRefresh={onRefresh} | ||
refreshInterval={10} | ||
/> | ||
); | ||
|
||
const instanceRefresh = componentRefresh.instance(); | ||
|
||
jest.advanceTimersByTime(10); | ||
// @ts-ignore | ||
await instanceRefresh.asyncInterval.__pendingFn; | ||
componentRefresh.setProps({ isPaused: true, refreshInterval: 0 }); | ||
jest.advanceTimersByTime(10); | ||
// @ts-ignore | ||
await instanceRefresh.asyncInterval.__pendingFn; | ||
|
||
expect(onRefresh).toBeCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters