Skip to content

Commit d1f9ce8

Browse files
committed
update mock context
Signed-off-by: tygao <[email protected]>
1 parent 6c622df commit d1f9ce8

File tree

4 files changed

+10
-27
lines changed

4 files changed

+10
-27
lines changed

public/chat_flyout.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ export const ChatFlyout = (props: ChatFlyoutProps) => {
2626
const chatContext = useChatContext();
2727
const chatHistoryPageLoadedRef = useRef(false);
2828
const core = useCore();
29+
const defaultDataSourceSelection$ = new BehaviorSubject(new Map());
30+
2931
// TODO: use DataSourceService to replace
3032
const selectedDS = useObservable(
3133
core.services.setupDeps?.dataSourceManagement?.dataSourceSelection?.getSelection$() ??
32-
new BehaviorSubject(new Map())
34+
defaultDataSourceSelection$
3335
);
3436
const currentDS = useMemo(() => {
3537
return selectedDS?.values().next().value;

public/contexts/__mocks__/core_context.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export const useCore = jest.fn(() => {
2424
load: jest.fn(),
2525
},
2626
conversationLoad: {},
27+
dataSource: {
28+
getDataSourceQuery() {
29+
return { dataSourceId: '' };
30+
},
31+
},
2732
},
2833
};
2934
useCoreMock.services.http.delete.mockReturnValue(Promise.resolve());

public/hooks/__tests__/use_conversations.test.ts

+2-23
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,17 @@ import { useDeleteConversation, usePatchConversation } from '../use_conversation
77
import { renderHook, act } from '@testing-library/react-hooks';
88
import { useCore } from '../../contexts/core_context';
99
import { HttpHandler } from '../../../../../src/core/public';
10-
import { DataSourceServiceMock } from '../../services/data_source_service.mock';
11-
import { httpServiceMock } from '../../../../../src/core/public/mocks';
12-
jest.mock('../../contexts/core_context');
13-
14-
const setup = () => {
15-
const useCoreMocked = useCore as jest.MockedFunction<typeof useCore>;
16-
const mockedDataSource = new DataSourceServiceMock();
17-
const mockedHttp = httpServiceMock.createStartContract();
18-
mockedHttp.delete = jest.fn(() => Promise.resolve());
19-
mockedHttp.put = jest.fn(() => Promise.resolve());
20-
21-
useCoreMocked.mockReturnValue({
22-
services: {
23-
dataSource: mockedDataSource,
24-
http: mockedHttp,
25-
},
26-
});
2710

28-
return useCoreMocked;
29-
};
11+
jest.mock('../../contexts/core_context');
12+
const useCoreMocked = useCore as jest.MockedFunction<typeof useCore>;
3013

3114
describe('useDeleteConversation', () => {
32-
const useCoreMocked = setup();
3315
it('should call delete with path and signal', async () => {
3416
const { result } = renderHook(() => useDeleteConversation());
3517

3618
await act(async () => {
3719
await result.current.deleteConversation('foo');
3820
});
39-
4021
expect(useCoreMocked.mock.results[0].value.services.http.delete).toHaveBeenCalledWith(
4122
'/api/assistant/conversation/foo',
4223
expect.objectContaining({
@@ -115,8 +96,6 @@ describe('useDeleteConversation', () => {
11596
});
11697

11798
describe('usePatchConversation', () => {
118-
const useCoreMocked = setup();
119-
12099
it('should call put with path, query and signal', async () => {
121100
const { result } = renderHook(() => usePatchConversation());
122101

public/services/data_source_service.ts

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { BehaviorSubject } from 'rxjs';
7-
import type { DataSourceManagementPluginSetup } from '../../../../src/plugins/data_source_management/public/plugin';
8-
96
export class DataSourceService {
107
constructor() {}
118

0 commit comments

Comments
 (0)