File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
src/components/ChannelList Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,35 @@ describe('ChannelList', () => {
324324 expect ( results ) . toHaveNoViolations ( ) ;
325325 } ) ;
326326
327+ it ( 'should show unique channels' , async ( ) => {
328+ useMockedApis ( chatClientUthred , [ queryChannelsApi ( [ testChannel1 , testChannel2 ] ) ] ) ;
329+ const ChannelPreview = ( props ) => < div data-testid = { props . channel . id } role = 'listitem' /> ;
330+ render (
331+ < Chat client = { chatClientUthred } >
332+ < ChannelList filters = { { } } options = { { limit : 2 } } Preview = { ChannelPreview } />
333+ </ Chat > ,
334+ ) ;
335+
336+ await waitFor ( ( ) => {
337+ expect ( screen . getByTestId ( testChannel1 . channel . id ) ) . toBeInTheDocument ( ) ;
338+ expect ( screen . getByTestId ( testChannel2 . channel . id ) ) . toBeInTheDocument ( ) ;
339+ expect ( screen . getAllByRole ( 'listitem' ) ) . toHaveLength ( 2 ) ;
340+ } ) ;
341+
342+ useMockedApis ( chatClientUthred , [ queryChannelsApi ( [ testChannel1 , testChannel3 ] ) ] ) ;
343+
344+ await act ( ( ) => {
345+ fireEvent . click ( screen . getByTestId ( 'load-more-button' ) ) ;
346+ } ) ;
347+
348+ await waitFor ( ( ) => {
349+ expect ( screen . getByTestId ( testChannel1 . channel . id ) ) . toBeInTheDocument ( ) ;
350+ expect ( screen . getByTestId ( testChannel2 . channel . id ) ) . toBeInTheDocument ( ) ;
351+ expect ( screen . getByTestId ( testChannel3 . channel . id ) ) . toBeInTheDocument ( ) ;
352+ expect ( screen . getAllByRole ( 'listitem' ) ) . toHaveLength ( 3 ) ;
353+ } ) ;
354+ } ) ;
355+
327356 describe ( 'Default and custom active channel' , ( ) => {
328357 let setActiveChannel ;
329358 const watchersConfig = { limit : 20 , offset : 0 } ;
Original file line number Diff line number Diff line change 11import { useEffect , useMemo , useState } from 'react' ;
2+ import uniqBy from 'lodash.uniqby' ;
23
34import { MAX_QUERY_CHANNELS_LIMIT } from '../utils' ;
45
@@ -52,7 +53,9 @@ export const usePaginatedChannels = <
5253 const channelQueryResponse = await client . queryChannels ( filters , sort || { } , newOptions ) ;
5354
5455 const newChannels =
55- queryType === 'reload' ? channelQueryResponse : [ ...channels , ...channelQueryResponse ] ;
56+ queryType === 'reload'
57+ ? channelQueryResponse
58+ : uniqBy ( [ ...channels , ...channelQueryResponse ] , 'cid' ) ;
5659
5760 setChannels ( newChannels ) ;
5861 setHasNextPage ( channelQueryResponse . length >= newOptions . limit ) ;
You can’t perform that action at this time.
0 commit comments