Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ const UnMemoizedChannel = (props: PropsWithChildren<ChannelProps>) => {
);
}

if (channelsQueryState.error && LoadingErrorIndicator) {
if (channelsQueryState.error && !channel && LoadingErrorIndicator) {
return (
<ChannelContainer>
<LoadingErrorIndicator error={channelsQueryState.error} />
</ChannelContainer>
);
}

if (channelsQueryState.error) {
if (channelsQueryState.error && !channel) {
return <ChannelContainer />;
}

Expand Down
54 changes: 53 additions & 1 deletion src/components/Channel/__tests__/Channel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ describe('Channel', () => {
await waitFor(() => expect(asFragment()).toMatchSnapshot());
});

it('should render empty channel container if channels query failed', async () => {
it('should render empty channel container if channels query failed and no channel is available', async () => {
const childrenContent = 'Channel children';
const { asFragment } = render(
<ChatProvider
Expand All @@ -399,6 +399,58 @@ describe('Channel', () => {
await waitFor(() => expect(asFragment()).toMatchSnapshot());
});

it('should render channel content if channels query failed but channel is available', async () => {
const childrenContent = 'Channel children';
await channel.watch();
render(
<ChatProvider
value={fromPartial<ChatContextValue>({
channelsQueryState: {
error: new Error('pagination failed'),
queryInProgress: null,
setError: vi.fn(),
setQueryInProgress: vi.fn(),
},
client: chatClient,
searchController: new SearchController(),
})}
>
<Channel channel={channel}>{childrenContent}</Channel>
</ChatProvider>,
);
await waitFor(() => expect(screen.getByText(childrenContent)).toBeInTheDocument());
});

it('should render channel content if channels query failed and channel is available even if LoadingErrorIndicator is provided', async () => {
const errMsg = 'Channels query failed';
const childrenContent = 'Channel children';
await channel.watch();
render(
<ChatProvider
value={fromPartial<ChatContextValue>({
channelsQueryState: {
error: new Error(errMsg),
queryInProgress: null,
setError: vi.fn(),
setQueryInProgress: vi.fn(),
},
client: chatClient,
searchController: new SearchController(),
})}
>
<WithComponents
overrides={{
LoadingErrorIndicator: ({ error }) => <div>{error.message}</div>,
}}
>
<Channel channel={channel}>{childrenContent}</Channel>
</WithComponents>
</ChatProvider>,
);
await waitFor(() => expect(screen.getByText(childrenContent)).toBeInTheDocument());
expect(screen.queryByText(errMsg)).not.toBeInTheDocument();
});

it('should render provided loading indicator if channels query is in progress', async () => {
const childrenContent = 'Channel children';
const loadingText = 'Loading channels';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports[`Channel > should render empty channel container if channel does not hav
</DocumentFragment>
`;

exports[`Channel > should render empty channel container if channels query failed 1`] = `
exports[`Channel > should render empty channel container if channels query failed and no channel is available 1`] = `
<DocumentFragment>
<div
class="str-chat str-chat__channel"
Expand Down