mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Add useTopNPopOver unit test (#145237)
## Summary Ops, I forgot to add this test to my previous PR. https://github.com/elastic/kibana/pull/144819
This commit is contained in:
parent
3e22323e00
commit
063909ba93
1 changed files with 65 additions and 0 deletions
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { act, renderHook } from '@testing-library/react-hooks';
|
||||
import { useTopNPopOver } from './utils';
|
||||
|
||||
describe('useTopNPopOver', () => {
|
||||
it('calls setIsPopoverVisible when toggling top N', () => {
|
||||
const setIsPopoverVisible = jest.fn();
|
||||
const {
|
||||
result: {
|
||||
current: { toggleTopN },
|
||||
},
|
||||
} = renderHook(() => useTopNPopOver(setIsPopoverVisible));
|
||||
|
||||
act(() => {
|
||||
toggleTopN();
|
||||
});
|
||||
|
||||
expect(setIsPopoverVisible).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('sets isShowingTopN to true when toggleTopN is called', () => {
|
||||
const { result } = renderHook(() => useTopNPopOver());
|
||||
|
||||
expect(result.current.isShowingTopN).toBeFalsy();
|
||||
|
||||
act(() => {
|
||||
result.current.toggleTopN();
|
||||
});
|
||||
|
||||
expect(result.current.isShowingTopN).toBeTruthy();
|
||||
});
|
||||
|
||||
it('sets isShowingTopN to false when toggleTopN is called for the second time', () => {
|
||||
const { result } = renderHook(() => useTopNPopOver());
|
||||
|
||||
expect(result.current.isShowingTopN).toBeFalsy();
|
||||
|
||||
act(() => {
|
||||
result.current.toggleTopN();
|
||||
result.current.toggleTopN();
|
||||
});
|
||||
|
||||
expect(result.current.isShowingTopN).toBeFalsy();
|
||||
});
|
||||
|
||||
it('sets isShowingTopN to false when closeTopN is called', () => {
|
||||
const { result } = renderHook(() => useTopNPopOver());
|
||||
act(() => {
|
||||
// First, make isShowingTopN truthy.
|
||||
result.current.toggleTopN();
|
||||
});
|
||||
expect(result.current.isShowingTopN).toBeTruthy();
|
||||
|
||||
act(() => {
|
||||
result.current.closeTopN();
|
||||
});
|
||||
expect(result.current.isShowingTopN).toBeFalsy();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue