From b6bd46d417bb532f1e959ce875c5c4f76ea0da99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 28 Dec 2022 17:07:08 +0100 Subject: [PATCH] Do not make requests to chats endpoint from profile page if chats are not supported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../components/chat-pane/__tests__/chat-pane.test.tsx | 11 ++++++++--- app/soapbox/queries/__tests__/chats.test.ts | 5 +++-- app/soapbox/queries/chats.ts | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/soapbox/features/chats/components/chat-pane/__tests__/chat-pane.test.tsx b/app/soapbox/features/chats/components/chat-pane/__tests__/chat-pane.test.tsx index b28f8aafd..5dcfda549 100644 --- a/app/soapbox/features/chats/components/chat-pane/__tests__/chat-pane.test.tsx +++ b/app/soapbox/features/chats/components/chat-pane/__tests__/chat-pane.test.tsx @@ -5,7 +5,7 @@ import { __stub } from 'soapbox/api'; import { ChatContext } from 'soapbox/contexts/chat-context'; import { StatProvider } from 'soapbox/contexts/stat-context'; import chats from 'soapbox/jest/fixtures/chats.json'; -import { render, screen, waitFor } from 'soapbox/jest/test-helpers'; +import { mockStore, render, rootState, screen, waitFor } from 'soapbox/jest/test-helpers'; import ChatPane from '../chat-pane'; @@ -23,7 +23,12 @@ const renderComponentWithChatContext = (store = {}) => render( describe('', () => { describe('when there are no chats', () => { + let store: ReturnType; + beforeEach(() => { + const state = rootState.setIn(['instance', 'version'], '2.7.2 (compatible; Pleroma 2.2.0)'); + store = mockStore(state); + __stub((mock) => { mock.onGet('/api/v1/pleroma/chats').reply(200, [], { link: null, @@ -32,7 +37,7 @@ describe('', () => { }); it('renders the blankslate', async () => { - renderComponentWithChatContext(); + renderComponentWithChatContext(store); await waitFor(() => { expect(screen.getByTestId('chat-pane-blankslate')).toBeInTheDocument(); @@ -57,4 +62,4 @@ describe('', () => { }); }); }); -}); \ No newline at end of file +}); diff --git a/app/soapbox/queries/__tests__/chats.test.ts b/app/soapbox/queries/__tests__/chats.test.ts index 3d72b9c0f..0c7fdec8f 100644 --- a/app/soapbox/queries/__tests__/chats.test.ts +++ b/app/soapbox/queries/__tests__/chats.test.ts @@ -178,7 +178,8 @@ describe('useChats', () => { describe('with a successful request', () => { beforeEach(() => { - store = mockStore(rootState); + const state = rootState.setIn(['instance', 'version'], '2.7.2 (compatible; Pleroma 2.2.0)'); + store = mockStore(state); __stub((mock) => { mock.onGet('/api/v1/pleroma/chats') @@ -378,4 +379,4 @@ describe('useChatActions', () => { expect((nextQueryData as any).message_expiration).toBe(1200); }); }); -}); \ No newline at end of file +}); diff --git a/app/soapbox/queries/chats.ts b/app/soapbox/queries/chats.ts index 261122819..ace2722a8 100644 --- a/app/soapbox/queries/chats.ts +++ b/app/soapbox/queries/chats.ts @@ -157,6 +157,7 @@ const useChats = (search?: string) => { const queryInfo = useInfiniteQuery(ChatKeys.chatSearch(search), ({ pageParam }) => getChats(pageParam), { keepPreviousData: true, + enabled: features.chats, getNextPageParam: (config) => { if (config.hasMore) { return { link: config.link };