Skip to content

Commit

Permalink
test: add unit tests for chat context
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Dec 29, 2023
1 parent 1515890 commit 7578827
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions public/contexts/__tests__/chat_context.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { useChatContext, ChatContext } from '../chat_context';

describe('useChatContext', () => {
it('should return chat context after useChatContext called', () => {
const chatContextValueMock = {
setSessionId: jest.fn(),
selectedTabId: 'chat' as const,
setSelectedTabId: jest.fn(),
flyoutVisible: true,
flyoutFullScreen: true,
setFlyoutVisible: jest.fn(),
setFlyoutComponent: jest.fn(),
userHasAccess: true,
contentRenderers: {},
actionExecutors: {},
currentAccount: { username: 'foo', tenant: '' },
setTitle: jest.fn(),
setTraceId: jest.fn(),
};
const { result } = renderHook(useChatContext, {
wrapper: ({ children }) => (
<ChatContext.Provider value={chatContextValueMock}>{children}</ChatContext.Provider>
),
});

expect(result.current).toBe(chatContextValueMock);
});

it('should return error if context provider missed', () => {
const { result } = renderHook(useChatContext);

expect(result.error).toMatchInlineSnapshot(`[Error: ChatContext is not set]`);
});
});

0 comments on commit 7578827

Please sign in to comment.