Skip to content

Commit 95fd2f4

Browse files
committed
add in new tests
1 parent 6251dd4 commit 95fd2f4

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/pages/RepoPage/BundlesTab/BundleContent/BundleSelection/BundleSelection.test.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ import { userEvent } from '@testing-library/user-event'
88
import { graphql, HttpResponse } from 'msw'
99
import { setupServer } from 'msw/node'
1010
import { Suspense } from 'react'
11+
import { Toaster } from 'react-hot-toast'
1112
import { MemoryRouter, Route } from 'react-router-dom'
1213

1314
import BundleSelection from './BundleSelection'
1415

16+
const mocks = vi.hoisted(() => ({
17+
useFlags: vi.fn().mockReturnValue({ displayBundleCachingModal: true }),
18+
}))
19+
20+
vi.mock('shared/featureFlags', () => ({
21+
useFlags: mocks.useFlags,
22+
}))
23+
1524
const mockRepoOverview = {
1625
__typename: 'Repository',
1726
private: false,
@@ -61,6 +70,27 @@ const mockBranchBundles = {
6170
},
6271
}
6372

73+
const mockCachedBundles = {
74+
owner: {
75+
repository: {
76+
__typename: 'Repository',
77+
branch: {
78+
head: {
79+
bundleAnalysis: {
80+
bundleAnalysisReport: {
81+
__typename: 'BundleAnalysisReport',
82+
bundles: [
83+
{ name: 'bundle1', isCached: true },
84+
{ name: 'bundle2', isCached: false },
85+
],
86+
},
87+
},
88+
},
89+
},
90+
},
91+
},
92+
}
93+
6494
const server = setupServer()
6595
const queryClient = new QueryClient({
6696
defaultOptions: { queries: { retry: false, suspense: true } },
@@ -85,6 +115,7 @@ const wrapper =
85115
]}
86116
>
87117
<Suspense fallback={<p>Loading</p>}>{children}</Suspense>
118+
<Toaster />
88119
</Route>
89120
</MemoryRouter>
90121
</QueryClientProvider>
@@ -136,6 +167,9 @@ describe('BundleSelection', () => {
136167
}),
137168
graphql.query('BranchBundlesNames', () => {
138169
return HttpResponse.json({ data: mockBranchBundles })
170+
}),
171+
graphql.query('CachedBundleList', () => {
172+
return HttpResponse.json({ data: mockCachedBundles })
139173
})
140174
)
141175

@@ -182,6 +216,16 @@ describe('BundleSelection', () => {
182216
expect(loadSelector).toBeInTheDocument()
183217
})
184218

219+
it('renders bundle caching button', async () => {
220+
setup()
221+
render(<BundleSelection />, { wrapper: wrapper() })
222+
223+
const bundleCachingButton = await screen.findByRole('button', {
224+
name: 'Configure data caching',
225+
})
226+
expect(bundleCachingButton).toBeInTheDocument()
227+
})
228+
185229
describe('user interacts with branch and bundle selectors', () => {
186230
describe('user selects a branch', () => {
187231
it('resets the bundle selector to the first available bundle', async () => {
@@ -277,4 +321,21 @@ describe('BundleSelection', () => {
277321
})
278322
})
279323
})
324+
325+
describe('user clicks bundle caching button', () => {
326+
it('renders bundle caching modal', async () => {
327+
const { user } = setup()
328+
render(<BundleSelection />, { wrapper: wrapper() })
329+
330+
const bundleCachingButton = await screen.findByRole('button', {
331+
name: 'Configure data caching',
332+
})
333+
await user.click(bundleCachingButton)
334+
335+
const modalHeader = await screen.findByText(
336+
'Configure bundle caching data'
337+
)
338+
expect(modalHeader).toBeInTheDocument()
339+
})
340+
})
280341
})

0 commit comments

Comments
 (0)