Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/sour-pianos-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes an issue with the Thread List displaying unreadable errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { render, screen } from '@testing-library/react';
import { VirtuosoMockContext } from 'react-virtuoso';

import ThreadList from './ThreadList';
import { createFakeRoom } from '../../../../../tests/mocks/data';

const fakeRoom = createFakeRoom({ t: 'c' });

jest.mock('./components/ThreadListItem', () => <></>);
jest.mock('../../contexts/RoomContext', () => ({
useRoom: () => fakeRoom,
useRoomSubscription: () => fakeRoom,
}));

// TODO: Create a function to mock the lib/i18n to be used with mockAppRoot
jest.mock('../../../../../app/utils/lib/i18n', () => ({
t: (key: string) => key,
}));

describe('ThreadList Component', () => {
it('should display an error message when in error state', async () => {
render(<ThreadList />, {
wrapper: mockAppRoot()
.withRoom(fakeRoom)
.withEndpoint(
'GET',
'/v1/chat.getThreadsList',
jest.fn().mockRejectedValue({ success: false, error: 'error-not-allowed', errorType: 'error-not-allowed' }),
)
.wrap((children) => (
<VirtuosoMockContext.Provider value={{ viewportHeight: 300, itemHeight: 100 }}>{children}</VirtuosoMockContext.Provider>
))
.build(),
});
expect(await screen.findByText('error-not-allowed')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { VirtualizedScrollbars } from '../../../../components/CustomScrollbars';
import { useRecordList } from '../../../../hooks/lists/useRecordList';
import { AsyncStatePhase } from '../../../../lib/asyncState';
import { getErrorMessage } from '../../../../lib/errorHandling';
import type { ThreadsListOptions } from '../../../../lib/lists/ThreadsList';
import { useRoom, useRoomSubscription } from '../../contexts/RoomContext';
import { useRoomToolbox } from '../../contexts/RoomToolboxContext';
Expand Down Expand Up @@ -144,7 +145,7 @@ const ThreadList = () => {

{error && (
<Callout mi={24} type='danger'>
{error.toString()}
{getErrorMessage(error, t('Something_went_wrong'))}
</Callout>
)}

Expand Down
Loading