diff --git a/webapp/channels/src/components/advanced_text_editor/send_button/send_post_options/core_menu_options.test.tsx b/webapp/channels/src/components/advanced_text_editor/send_button/send_post_options/core_menu_options.test.tsx index 3e9f565b0cf..2352686a460 100644 --- a/webapp/channels/src/components/advanced_text_editor/send_button/send_post_options/core_menu_options.test.tsx +++ b/webapp/channels/src/components/advanced_text_editor/send_button/send_post_options/core_menu_options.test.tsx @@ -5,23 +5,12 @@ import {DateTime} from 'luxon'; import React from 'react'; import useTimePostBoxIndicator from 'components/advanced_text_editor/use_post_box_indicator'; +import {WithTestMenuContext} from 'components/menu/menu_context_test'; import {renderWithContext, fireEvent, screen} from 'tests/react_testing_utils'; import CoreMenuOptions from './core_menu_options'; -jest.mock('components/menu', () => ({ - __esModule: true, - Item: jest.fn(({labels, trailingElements, children, ...props}) => ( -
- {labels} - {children} - {trailingElements} -
- )), - Separator: jest.fn(() =>
), -})); - jest.mock('components/advanced_text_editor/use_post_box_indicator'); const mockedUseTimePostBoxIndicator = jest.mocked(useTimePostBoxIndicator); @@ -75,10 +64,12 @@ describe('CoreMenuOptions Component', () => { function renderComponent(state = initialState, handleOnSelectOverride = handleOnSelect) { renderWithContext( - , + + + , state, ); } diff --git a/webapp/channels/src/components/menu/menu_context_test.tsx b/webapp/channels/src/components/menu/menu_context_test.tsx new file mode 100644 index 00000000000..f0e9021d65f --- /dev/null +++ b/webapp/channels/src/components/menu/menu_context_test.tsx @@ -0,0 +1,32 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import React, {useEffect, useState} from 'react'; + +import {MenuContext, useMenuContextValue} from './menu_context'; + +type Props = { + children: React.ReactNode; +} + +export function WithTestMenuContext({ + children, +}: Props) { + const [show, setShow] = useState(true); + const menuContextValue = useMenuContextValue(() => setShow(false), show); + + useEffect(() => { + if (!show) { + menuContextValue.handleClosed(); + } + + // We only want to call this when the menu is closed + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [show]); + + return ( + + {children} + + ); +}