Skip to content

Commit 736fdca

Browse files
update GeneralTab tests and use query options API and also refactor to TS
1 parent 9a8df29 commit 736fdca

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

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

+43-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 { TierNames } from 'services/tier'
@@ -24,35 +29,54 @@ vi.mock('./DefaultBranch', () => ({
2429
const queryClient = new QueryClient({
2530
defaultOptions: { queries: { retry: false } },
2631
})
27-
const server = setupServer()
32+
const queryClientV5 = new QueryClientV5({
33+
defaultOptions: { queries: { retry: false } },
34+
})
2835

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

48+
const server = setupServer()
3749
beforeAll(() => {
3850
server.listen()
3951
console.error = () => {}
4052
})
53+
4154
afterEach(() => {
4255
queryClient.clear()
56+
queryClientV5.clear()
4357
server.resetHandlers()
4458
})
45-
afterAll(() => server.close())
59+
60+
afterAll(() => {
61+
server.close()
62+
})
63+
64+
interface SetupArgs {
65+
hasDefaultBranch?: boolean
66+
tierValue?: (typeof TierNames)[keyof typeof TierNames]
67+
isPrivate?: boolean
68+
}
4669

4770
describe('GeneralTab', () => {
4871
function setup(
4972
{
5073
hasDefaultBranch = false,
5174
tierValue = TierNames.PRO,
5275
isPrivate = false,
53-
} = {
76+
}: SetupArgs = {
5477
hasDefaultBranch: false,
5578
tierValue: TierNames.PRO,
79+
isPrivate: false,
5680
}
5781
) {
5882
server.use(
@@ -122,19 +146,19 @@ describe('GeneralTab', () => {
122146
})
123147
})
124148

125-
it('render tokens component', () => {
149+
it('render tokens component', async () => {
126150
setup({ tierValue: TierNames.TEAM })
127151
render(<GeneralTab />, { wrapper })
128152

129-
const tokensComponent = screen.getByText(/Tokens Component/)
153+
const tokensComponent = await screen.findByText(/Tokens Component/)
130154
expect(tokensComponent).toBeInTheDocument()
131155
})
132156

133-
it('render danger zone component', () => {
157+
it('render danger zone component', async () => {
134158
setup({ tierValue: TierNames.TEAM })
135159
render(<GeneralTab />, { wrapper })
136160

137-
const tokensComponent = screen.getByText(/DangerZone Component/)
161+
const tokensComponent = await screen.findByText(/DangerZone Component/)
138162
expect(tokensComponent).toBeInTheDocument()
139163
})
140164
})
@@ -152,10 +176,10 @@ describe('GeneralTab', () => {
152176
expect(tokensComponent).toBeInTheDocument()
153177
})
154178

155-
it('render danger zone component', () => {
179+
it('render danger zone component', async () => {
156180
render(<GeneralTab />, { wrapper })
157181

158-
const tokensComponent = screen.getByText(/DangerZone Component/)
182+
const tokensComponent = await screen.findByText(/DangerZone Component/)
159183
expect(tokensComponent).toBeInTheDocument()
160184
})
161185
})
@@ -165,17 +189,17 @@ describe('GeneralTab', () => {
165189
setup({ tierValue: TierNames.TEAM, isPrivate: false })
166190
})
167191

168-
it('render tokens component', () => {
192+
it('render tokens component', async () => {
169193
render(<GeneralTab />, { wrapper })
170194

171-
const tokensComponent = screen.getByText(/Tokens Component/)
195+
const tokensComponent = await screen.findByText(/Tokens Component/)
172196
expect(tokensComponent).toBeInTheDocument()
173197
})
174198

175-
it('render danger zone component', () => {
199+
it('render danger zone component', async () => {
176200
render(<GeneralTab />, { wrapper })
177201

178-
const tokensComponent = screen.getByText(/DangerZone Component/)
202+
const tokensComponent = await screen.findByText(/DangerZone Component/)
179203
expect(tokensComponent).toBeInTheDocument()
180204
})
181205
})

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,19 +1,29 @@
1+
import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
12
import { useParams } from 'react-router-dom'
23

34
import { TierNames, useTier } from 'services/tier'
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>()
19+
const { data: repoData } = useSuspenseQueryV5(
20+
RepoForTokensTeamQueryOpts({
21+
provider,
22+
owner,
23+
repo,
24+
})
25+
)
26+
1727
const { data: tierData } = useTier({ provider, owner })
1828
const defaultBranch = repoData?.defaultBranch
1929
const isPrivate = repoData?.private

0 commit comments

Comments
 (0)