Do not make requests to chats endpoint from profile page if chats are not supported

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-12-28 17:07:08 +01:00
parent e77c309e8a
commit b6bd46d417
3 changed files with 12 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import { __stub } from 'soapbox/api';
import { ChatContext } from 'soapbox/contexts/chat-context'; import { ChatContext } from 'soapbox/contexts/chat-context';
import { StatProvider } from 'soapbox/contexts/stat-context'; import { StatProvider } from 'soapbox/contexts/stat-context';
import chats from 'soapbox/jest/fixtures/chats.json'; 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'; import ChatPane from '../chat-pane';
@ -23,7 +23,12 @@ const renderComponentWithChatContext = (store = {}) => render(
describe('<ChatPane />', () => { describe('<ChatPane />', () => {
describe('when there are no chats', () => { describe('when there are no chats', () => {
let store: ReturnType<typeof mockStore>;
beforeEach(() => { beforeEach(() => {
const state = rootState.setIn(['instance', 'version'], '2.7.2 (compatible; Pleroma 2.2.0)');
store = mockStore(state);
__stub((mock) => { __stub((mock) => {
mock.onGet('/api/v1/pleroma/chats').reply(200, [], { mock.onGet('/api/v1/pleroma/chats').reply(200, [], {
link: null, link: null,
@ -32,7 +37,7 @@ describe('<ChatPane />', () => {
}); });
it('renders the blankslate', async () => { it('renders the blankslate', async () => {
renderComponentWithChatContext(); renderComponentWithChatContext(store);
await waitFor(() => { await waitFor(() => {
expect(screen.getByTestId('chat-pane-blankslate')).toBeInTheDocument(); expect(screen.getByTestId('chat-pane-blankslate')).toBeInTheDocument();

View File

@ -178,7 +178,8 @@ describe('useChats', () => {
describe('with a successful request', () => { describe('with a successful request', () => {
beforeEach(() => { beforeEach(() => {
store = mockStore(rootState); const state = rootState.setIn(['instance', 'version'], '2.7.2 (compatible; Pleroma 2.2.0)');
store = mockStore(state);
__stub((mock) => { __stub((mock) => {
mock.onGet('/api/v1/pleroma/chats') mock.onGet('/api/v1/pleroma/chats')

View File

@ -157,6 +157,7 @@ const useChats = (search?: string) => {
const queryInfo = useInfiniteQuery(ChatKeys.chatSearch(search), ({ pageParam }) => getChats(pageParam), { const queryInfo = useInfiniteQuery(ChatKeys.chatSearch(search), ({ pageParam }) => getChats(pageParam), {
keepPreviousData: true, keepPreviousData: true,
enabled: features.chats,
getNextPageParam: (config) => { getNextPageParam: (config) => {
if (config.hasMore) { if (config.hasMore) {
return { link: config.link }; return { link: config.link };