/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import { MOCK_DATA } from '../../../../test/mocks/mockData'; import { act, render, waitFor } from '@testing-library/react'; import React from 'react'; import { coreServicesMock, notificationServiceMock, } from '../../../../test/mocks/serviceMock'; import { CoreServicesContext } from '../../../components/coreServices'; import { MuteChannelModal } from '../components/modals/MuteChannelModal'; describe(' spec', () => { it('returns if no channels', () => { const { container } = render( {}} onClose={() => {}} services={notificationServiceMock} /> ); expect(container.firstChild).toBeNull(); }); it('renders the component', () => { const channels = [jest.fn() as any]; const setSelected = jest.fn(); const { container } = render( {}} services={notificationServiceMock} /> ); expect(container.firstChild).toMatchSnapshot(); }); it('clicks mute button', async () => { const setSelected = jest.fn(); const notificationServiceMock = jest.fn() as any; notificationServiceMock.notificationService = { updateConfig: async (id: string, config: any) => { return Promise.resolve(); }, }; const utils = render( {}} refresh={jest.fn()} services={notificationServiceMock} /> ); utils.getByText('Mute').click(); await waitFor(() => expect(setSelected).toBeCalled()) }); it('handles failures', async () => { const setSelected = jest.fn(); const notificationServiceMock = jest.fn() as any; notificationServiceMock.notificationService = { updateConfig: async (id: string, config: any) => { return Promise.reject(); }, }; const utils = render( {}} services={notificationServiceMock} /> ); utils.getByText('Mute').click(); expect(utils.container.firstChild).toMatchSnapshot(); }); });