-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🩹 Address some slow or inconsistent tests (#4368)
* Refactor `useForumMultiQueryCategoryBreadCrumbs` * Speedup the `ThreadItemBreadcrumbs` test * Fix formatter inconsistency on newer node versions * Fix restore vote test suite on newer node versions
- Loading branch information
Showing
12 changed files
with
32 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 6 additions & 15 deletions
21
packages/ui/src/forum/hooks/useForumMultiQueryCategoryBreadCrumbs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,26 @@ | ||
import { useEffect, useMemo, useState } from 'react' | ||
|
||
import { useGetForumCategoryBreadcrumbLazyQuery } from '../queries' | ||
import { useGetForumCategoryBreadcrumbQuery } from '../queries' | ||
import { asSubCategory, CategoryBreadcrumb } from '../types' | ||
|
||
// The goal of this hook is to utilize apollo cache to be faster than `useForumCategoryBreadcrumbs` | ||
// when there are a lot of breadcrumbs to show, like on search results | ||
export const useForumMultiQueryCategoryBreadCrumbs = (id: string) => { | ||
const placeholder = useMemo(() => [{ id, title: `Category ${id}` }], [id]) | ||
const [isLoading, setIsLoading] = useState(true) | ||
const [breadcrumbs, setBreadcrumbs] = useState<CategoryBreadcrumb[]>([]) | ||
const [getCategory, { data }] = useGetForumCategoryBreadcrumbLazyQuery() | ||
|
||
useEffect(() => { | ||
setBreadcrumbs([]) | ||
getCategory({ variables: { where: { id } } }) | ||
}, [id]) | ||
const [nextId, setNextId] = useState(id) | ||
const { data } = useGetForumCategoryBreadcrumbQuery({ variables: { where: { id: nextId } }, skip: !nextId }) | ||
|
||
useEffect(() => { | ||
const category = data?.forumCategoryByUniqueInput | ||
if (!category) return | ||
|
||
if (category.parentId) { | ||
getCategory({ variables: { where: { id: category.parentId } } }) | ||
} else { | ||
setIsLoading(false) | ||
} | ||
setNextId(category.parentId ?? '') | ||
setBreadcrumbs([asSubCategory(category), ...breadcrumbs]) | ||
}, [data]) | ||
|
||
return { | ||
isLoading, | ||
breadcrumbs: isLoading ? placeholder : breadcrumbs, | ||
isLoading: !!nextId, | ||
breadcrumbs: nextId ? placeholder : breadcrumbs, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const mockUniqueQuery = <T extends { id: string }>(key: string, entities: T[]) => | ||
jest.fn(({ variables, skip }) => { | ||
if (skip) return {} | ||
const { id } = variables.where | ||
const entity = entities.find((entity) => entity.id === id) | ||
return { isLoading: false, data: { [key]: entity } } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def2999
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pioneer-2 – ./
pioneer-2.vercel.app
pioneer-2-joystream.vercel.app
pioneer-2-git-dev-joystream.vercel.app
def2999
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pioneer-2-storybook – ./
pioneer-2-storybook-joystream.vercel.app
pioneer-2-storybook.vercel.app
pioneer-2-storybook-git-dev-joystream.vercel.app