|
| 1 | +/** @jest-environment @happy-dom/jest-environment */ |
| 2 | + |
| 3 | +import React from 'react'; |
| 4 | +import { render } from 'react-dom'; |
| 5 | +import { act } from 'react-dom/test-utils'; |
| 6 | + |
| 7 | +import { hooks } from 'botframework-webchat-api'; |
| 8 | + |
| 9 | +import LiveRegionSendFailed from './SendFailed'; |
| 10 | +import { useLiveRegion } from '../../providers/LiveRegionTwin'; |
| 11 | + |
| 12 | +jest.mock('botframework-webchat-api', () => ({ |
| 13 | + hooks: { |
| 14 | + useGetActivityByKey: jest.fn(), |
| 15 | + useLocalizer: jest.fn(), |
| 16 | + useSendStatusByActivityKey: jest.fn() |
| 17 | + } |
| 18 | +})); |
| 19 | +jest.mock('../../providers/LiveRegionTwin', () => ({ useLiveRegion: jest.fn() })); |
| 20 | + |
| 21 | +const mockUseGetActivityByKey = hooks.useGetActivityByKey as jest.Mock; |
| 22 | +const mockUseLiveRegion = useLiveRegion as jest.Mock; |
| 23 | +const mockUseLocalizer = hooks.useLocalizer as jest.Mock; |
| 24 | +const mockUseSendStatusByActivityKey = hooks.useSendStatusByActivityKey as jest.Mock; |
| 25 | + |
| 26 | +describe('LiveRegionSendFailed', () => { |
| 27 | + let container: HTMLDivElement; |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + container = document.createElement('div'); |
| 31 | + |
| 32 | + mockUseGetActivityByKey.mockReturnValue(() => ({ channelData: {}, text: 'Hello, World!', type: 'message' })); |
| 33 | + mockUseLocalizer.mockReturnValue(() => 'Failed to send message.'); |
| 34 | + mockUseSendStatusByActivityKey.mockReturnValue([new Map([['activity', 'send failed']])]); |
| 35 | + }); |
| 36 | + |
| 37 | + afterEach(() => { |
| 38 | + container.remove(); |
| 39 | + jest.clearAllMocks(); |
| 40 | + }); |
| 41 | + |
| 42 | + test('renders when the initial send status is failed', () => { |
| 43 | + act(() => { |
| 44 | + render(<LiveRegionSendFailed />, container); |
| 45 | + }); |
| 46 | + |
| 47 | + expect(mockUseLiveRegion.mock.calls[0][0]()).toBe(false); |
| 48 | + }); |
| 49 | +}); |
0 commit comments