diff --git a/app/soapbox/queries/__tests__/chats.test.ts b/app/soapbox/queries/__tests__/chats.test.ts index 7640fd511..3d72b9c0f 100644 --- a/app/soapbox/queries/__tests__/chats.test.ts +++ b/app/soapbox/queries/__tests__/chats.test.ts @@ -11,8 +11,6 @@ import { flattenPages } from 'soapbox/utils/queries'; import { IAccount } from '../accounts'; import { ChatKeys, IChat, IChatMessage, isLastMessage, useChat, useChatActions, useChatMessages, useChats } from '../chats'; -jest.mock('soapbox/utils/queries'); - const chat: IChat = { accepted: true, account: { diff --git a/app/soapbox/utils/__mocks__/queries.ts b/app/soapbox/utils/__mocks__/queries.ts deleted file mode 100644 index efc7447a3..000000000 --- a/app/soapbox/utils/__mocks__/queries.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { InfiniteData, QueryKey, UseInfiniteQueryResult } from '@tanstack/react-query'; - -import { queryClient } from 'soapbox/jest/test-helpers'; - -import { PaginatedResult } from '../queries'; - -const flattenPages = (queryData: UseInfiniteQueryResult>['data']) => { - return queryData?.pages.reduce( - (prev: T[], curr) => [...curr.result, ...prev], - [], - ); -}; - -const updatePageItem = (queryKey: QueryKey, newItem: T, isItem: (item: T, newItem: T) => boolean) => { - queryClient.setQueriesData>>(queryKey, (data) => { - if (data) { - const pages = data.pages.map(page => { - const result = page.result.map(item => isItem(item, newItem) ? newItem : item); - return { ...page, result }; - }); - return { ...data, pages }; - } - }); -}; - -/** Insert the new item at the beginning of the first page. */ -const appendPageItem = (queryKey: QueryKey, newItem: T) => { - queryClient.setQueryData>>(queryKey, (data) => { - if (data) { - const pages = [...data.pages]; - pages[0] = { ...pages[0], result: [...pages[0].result, newItem] }; - return { ...data, pages }; - } - }); -}; - -/** Remove an item inside if found. */ -const removePageItem = (queryKey: QueryKey, itemToRemove: T, isItem: (item: T, newItem: T) => boolean) => { - queryClient.setQueriesData>>(queryKey, (data) => { - if (data) { - const pages = data.pages.map(page => { - const result = page.result.filter(item => !isItem(item, itemToRemove)); - return { ...page, result }; - }); - return { ...data, pages }; - } - }); -}; - -export { - flattenPages, - updatePageItem, - appendPageItem, - removePageItem, -}; \ No newline at end of file