Skip to content

Commit 99b07df

Browse files
update GeneralTab tests and use query options API and also refactor to TS
1 parent 65b5975 commit 99b07df

File tree

3 files changed

+63
-26
lines changed

3 files changed

+63
-26
lines changed

src/pages/RepoPage/ConfigTab/tabs/GeneralTab/GeneralTab.test.jsx src/pages/RepoPage/ConfigTab/tabs/GeneralTab/GeneralTab.test.tsx

+46-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2+
import {
3+
QueryClientProvider as QueryClientProviderV5,
4+
QueryClient as QueryClientV5,
5+
} from '@tanstack/react-queryV5'
26
import { render, screen } from '@testing-library/react'
37
import { graphql, HttpResponse } from 'msw'
48
import { setupServer } from 'msw/node'
9+
import { Suspense } from 'react'
510
import { MemoryRouter, Route } from 'react-router-dom'
611

712
import GeneralTab from './GeneralTab'
@@ -22,29 +27,51 @@ vi.mock('./DefaultBranch', () => ({
2227
const queryClient = new QueryClient({
2328
defaultOptions: { queries: { retry: false } },
2429
})
25-
const server = setupServer()
30+
const queryClientV5 = new QueryClientV5({
31+
defaultOptions: { queries: { retry: false } },
32+
})
2633

27-
const wrapper = ({ children }) => (
28-
<QueryClientProvider client={queryClient}>
29-
<MemoryRouter initialEntries={['/gh/codecov/codecov-client/config']}>
30-
<Route path="/:provider/:owner/:repo/config">{children}</Route>
31-
</MemoryRouter>
32-
</QueryClientProvider>
34+
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
35+
<QueryClientProviderV5 client={queryClientV5}>
36+
<QueryClientProvider client={queryClient}>
37+
<MemoryRouter initialEntries={['/gh/codecov/codecov-client/config']}>
38+
<Route path="/:provider/:owner/:repo/config">
39+
<Suspense fallback={<p>Loading</p>}>{children}</Suspense>
40+
</Route>
41+
</MemoryRouter>
42+
</QueryClientProvider>
43+
</QueryClientProviderV5>
3344
)
3445

46+
const server = setupServer()
3547
beforeAll(() => {
3648
server.listen()
3749
console.error = () => {}
3850
})
51+
3952
afterEach(() => {
4053
queryClient.clear()
54+
queryClientV5.clear()
4155
server.resetHandlers()
4256
})
43-
afterAll(() => server.close())
57+
58+
afterAll(() => {
59+
server.close()
60+
})
61+
62+
interface SetupArgs {
63+
hasDefaultBranch?: boolean
64+
isTeamPlan?: boolean
65+
isPrivate?: boolean
66+
}
4467

4568
describe('GeneralTab', () => {
4669
function setup(
47-
{ hasDefaultBranch = false, isTeamPlan = false, isPrivate = false } = {
70+
{
71+
hasDefaultBranch = false,
72+
isTeamPlan = false,
73+
isPrivate = false,
74+
}: SetupArgs = {
4875
hasDefaultBranch: false,
4976
isTeamPlan: false,
5077
isPrivate: false,
@@ -112,19 +139,19 @@ describe('GeneralTab', () => {
112139
})
113140
})
114141

115-
it('render tokens component', () => {
142+
it('render tokens component', async () => {
116143
setup({ isTeamPlan: true })
117144
render(<GeneralTab />, { wrapper })
118145

119-
const tokensComponent = screen.getByText(/Tokens Component/)
146+
const tokensComponent = await screen.findByText(/Tokens Component/)
120147
expect(tokensComponent).toBeInTheDocument()
121148
})
122149

123-
it('render danger zone component', () => {
150+
it('render danger zone component', async () => {
124151
setup({ isTeamPlan: true })
125152
render(<GeneralTab />, { wrapper })
126153

127-
const tokensComponent = screen.getByText(/DangerZone Component/)
154+
const tokensComponent = await screen.findByText(/DangerZone Component/)
128155
expect(tokensComponent).toBeInTheDocument()
129156
})
130157
})
@@ -142,10 +169,10 @@ describe('GeneralTab', () => {
142169
expect(tokensComponent).toBeInTheDocument()
143170
})
144171

145-
it('render danger zone component', () => {
172+
it('render danger zone component', async () => {
146173
render(<GeneralTab />, { wrapper })
147174

148-
const tokensComponent = screen.getByText(/DangerZone Component/)
175+
const tokensComponent = await screen.findByText(/DangerZone Component/)
149176
expect(tokensComponent).toBeInTheDocument()
150177
})
151178
})
@@ -155,17 +182,17 @@ describe('GeneralTab', () => {
155182
setup({ isTeamPlan: true, isPrivate: false })
156183
})
157184

158-
it('render tokens component', () => {
185+
it('render tokens component', async () => {
159186
render(<GeneralTab />, { wrapper })
160187

161-
const tokensComponent = screen.getByText(/Tokens Component/)
188+
const tokensComponent = await screen.findByText(/Tokens Component/)
162189
expect(tokensComponent).toBeInTheDocument()
163190
})
164191

165-
it('render danger zone component', () => {
192+
it('render danger zone component', async () => {
166193
render(<GeneralTab />, { wrapper })
167194

168-
const tokensComponent = screen.getByText(/DangerZone Component/)
195+
const tokensComponent = await screen.findByText(/DangerZone Component/)
169196
expect(tokensComponent).toBeInTheDocument()
170197
})
171198
})

src/pages/RepoPage/ConfigTab/tabs/GeneralTab/GeneralTab.jsx src/pages/RepoPage/ConfigTab/tabs/GeneralTab/GeneralTab.tsx

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1+
import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
12
import { useParams } from 'react-router-dom'
23

34
import { useIsTeamPlan } from 'services/useIsTeamPlan'
45

56
import DangerZone from './DangerZone'
67
import DefaultBranch from './DefaultBranch'
7-
import { useRepoForTokensTeam } from './hooks'
8+
import { RepoForTokensTeamQueryOpts } from './queries/RepoForTokensTeamQueryOpts'
89
import { Tokens, TokensTeam } from './Tokens'
910

11+
interface URLParams {
12+
provider: string
13+
owner: string
14+
repo: string
15+
}
16+
1017
function GeneralTab() {
11-
const { provider, owner, repo } = useParams()
12-
const { data: repoData } = useRepoForTokensTeam({
13-
provider,
14-
owner,
15-
repo,
16-
})
18+
const { provider, owner, repo } = useParams<URLParams>()
1719
const { data: isTeamPlan } = useIsTeamPlan({ provider, owner })
20+
const { data: repoData } = useSuspenseQueryV5(
21+
RepoForTokensTeamQueryOpts({
22+
provider,
23+
owner,
24+
repo,
25+
})
26+
)
27+
1828
const defaultBranch = repoData?.defaultBranch
1929
const isPrivate = repoData?.private
2030
const showTokensTeam = isPrivate && isTeamPlan

0 commit comments

Comments
 (0)