forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Make analyzer full screen work with new eui using…
… existing hooks. (elastic#126117) (elastic#126218) * Fix analyzer full screen with new eui data grid * Add basic tests for full screen hook (cherry picked from commit 9920e7b) Co-authored-by: Kevin Qualters <56408403+kqualters-elastic@users.noreply.github.com>
- Loading branch information
1 parent
92533d9
commit a893f7b
Showing
4 changed files
with
172 additions
and
53 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
x-pack/plugins/security_solution/public/common/containers/use_full_screen/index.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,95 @@ | ||
/* | ||
* 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 React, { useEffect } from 'react'; | ||
import { TestProviders } from '../../mock'; | ||
import { | ||
renderHook, | ||
act, | ||
RenderResult, | ||
WaitForNextUpdate, | ||
cleanup, | ||
} from '@testing-library/react-hooks'; | ||
import { useGlobalFullScreen, GlobalFullScreen } from '.'; | ||
|
||
describe('useFullScreen', () => { | ||
describe('with no data-grid present in the dom', () => { | ||
let result: RenderResult<GlobalFullScreen>; | ||
let waitForNextUpdate: WaitForNextUpdate; | ||
test('Default values with no data grid in the dom', async () => { | ||
await act(async () => { | ||
const WrapperContainer: React.FC<{ children?: React.ReactNode }> = ({ children }) => ( | ||
<div className="euiDataGrid--fullScreen"> | ||
<TestProviders>{children}</TestProviders> | ||
</div> | ||
); | ||
({ result, waitForNextUpdate } = renderHook(() => useGlobalFullScreen(), { | ||
wrapper: WrapperContainer, | ||
})); | ||
await waitForNextUpdate(); | ||
expect(result.current.globalFullScreen).toEqual(false); | ||
}); | ||
act(() => { | ||
result.current.setGlobalFullScreen(true); | ||
}); | ||
expect(result.current.globalFullScreen).toEqual(true); | ||
cleanup(); | ||
}); | ||
}); | ||
|
||
describe('with a mock full screen data-grid in the dom', () => { | ||
let result: RenderResult<GlobalFullScreen>; | ||
let waitForNextUpdate: WaitForNextUpdate; | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
test('setting globalFullScreen to true should not remove the chrome removal class and data grid remains open and full screen', async () => { | ||
await act(async () => { | ||
const WrapperContainer: React.FC<{ children?: React.ReactNode }> = ({ children }) => { | ||
useEffect(() => { | ||
document.body.classList.add('euiDataGrid__restrictBody'); | ||
}, []); | ||
return ( | ||
<div className="euiDataGrid--fullScreen"> | ||
<TestProviders>{children}</TestProviders> | ||
</div> | ||
); | ||
}; | ||
({ result, waitForNextUpdate } = renderHook(() => useGlobalFullScreen(), { | ||
wrapper: WrapperContainer, | ||
})); | ||
await waitForNextUpdate(); | ||
}); | ||
act(() => { | ||
result.current.setGlobalFullScreen(true); | ||
}); | ||
expect(document.querySelector('.euiDataGrid__restrictBody')).toBeTruthy(); | ||
}); | ||
test('setting globalFullScreen to false should remove the chrome removal class and data grid remains open and full screen', async () => { | ||
await act(async () => { | ||
const WrapperContainer: React.FC<{ children?: React.ReactNode }> = ({ children }) => { | ||
useEffect(() => { | ||
document.body.classList.add('euiDataGrid__restrictBody'); | ||
}, []); | ||
return ( | ||
<div className="euiDataGrid--fullScreen"> | ||
<TestProviders>{children}</TestProviders> | ||
</div> | ||
); | ||
}; | ||
({ result, waitForNextUpdate } = renderHook(() => useGlobalFullScreen(), { | ||
wrapper: WrapperContainer, | ||
})); | ||
await waitForNextUpdate(); | ||
}); | ||
act(() => { | ||
result.current.setGlobalFullScreen(false); | ||
}); | ||
expect(document.querySelector('.euiDataGrid__restrictBody')).toBeNull(); | ||
}); | ||
}); | ||
}); |
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