Skip to content

Commit 12d8acb

Browse files
authored
feat: Add bundle cache modal to repo config tab (#3655)
1 parent 333b4e9 commit 12d8acb

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

src/pages/RepoPage/ConfigTab/tabs/ConfigurationManager/ConfigurationManager.test.tsx

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@ import {
44
QueryClient as QueryClientV5,
55
} from '@tanstack/react-queryV5'
66
import { render, screen, waitFor } from '@testing-library/react'
7+
import { userEvent } from '@testing-library/user-event'
78
import { graphql, HttpResponse } from 'msw'
89
import { setupServer } from 'msw/node'
10+
import { Suspense } from 'react'
11+
import { Toaster } from 'react-hot-toast'
912
import { MemoryRouter, Route } from 'react-router'
1013

1114
import { TierNames, TTierNames } from 'services/tier'
1215

1316
import ConfigurationManager from './ConfigurationManager'
1417
import { RepositoryConfiguration } from './hooks/useRepoConfigurationStatus/RepoConfigurationStatusQueryOpts'
1518

19+
const mocks = vi.hoisted(() => ({
20+
useFlags: vi.fn().mockReturnValue({ displayBundleCachingModal: true }),
21+
}))
22+
23+
vi.mock('shared/featureFlags', () => ({
24+
useFlags: mocks.useFlags,
25+
}))
26+
1627
interface mockRepoConfigArgs {
1728
tierName?: TTierNames
1829
flags?: boolean
@@ -55,6 +66,27 @@ function mockRepoConfig({
5566
}
5667
}
5768

69+
const mockCachedBundles = {
70+
owner: {
71+
repository: {
72+
__typename: 'Repository',
73+
branch: {
74+
head: {
75+
bundleAnalysis: {
76+
bundleAnalysisReport: {
77+
__typename: 'BundleAnalysisReport',
78+
bundles: [
79+
{ name: 'bundle1', isCached: true },
80+
{ name: 'bundle2', isCached: false },
81+
],
82+
},
83+
},
84+
},
85+
},
86+
},
87+
},
88+
}
89+
5890
const queryClient = new QueryClient({
5991
defaultOptions: { queries: { retry: false } },
6092
})
@@ -66,8 +98,11 @@ const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
6698
<QueryClientProviderV5 client={queryClientV5}>
6799
<QueryClientProvider client={queryClient}>
68100
<MemoryRouter initialEntries={['/gh/codecov/cool-repo/config']}>
69-
<Route path="/:provider/:owner/:repo/config">{children}</Route>
101+
<Route path="/:provider/:owner/:repo/config">
102+
<Suspense fallback={<div>Loading</div>}>{children}</Suspense>
103+
</Route>
70104
</MemoryRouter>
105+
<Toaster />
71106
</QueryClientProvider>
72107
</QueryClientProviderV5>
73108
)
@@ -90,11 +125,18 @@ interface SetupArgs {
90125

91126
describe('Configuration Manager', () => {
92127
function setup({ repoConfig = mockRepoConfig({}) }: SetupArgs) {
128+
const user = userEvent.setup()
129+
93130
server.use(
94131
graphql.query('GetRepoConfigurationStatus', () => {
95132
return HttpResponse.json({ data: { owner: repoConfig } })
133+
}),
134+
graphql.query('CachedBundleList', () => {
135+
return HttpResponse.json({ data: mockCachedBundles })
96136
})
97137
)
138+
139+
return { user }
98140
}
99141

100142
describe('CoverageConfiguration', () => {
@@ -374,6 +416,41 @@ describe('Configuration Manager', () => {
374416
expect(configuredStatus).toBeInTheDocument()
375417
})
376418
})
419+
420+
describe('bundle caching', () => {
421+
it('renders bundle caching button', async () => {
422+
setup({
423+
repoConfig: mockRepoConfig({
424+
bundleAnalysis: true,
425+
languages: ['typescript'],
426+
}),
427+
})
428+
render(<ConfigurationManager />, { wrapper })
429+
430+
const button = await screen.findByText('Configure data caching')
431+
expect(button).toBeInTheDocument()
432+
})
433+
434+
it('renders bundle caching modal', async () => {
435+
const { user } = setup({
436+
repoConfig: mockRepoConfig({
437+
bundleAnalysis: true,
438+
languages: ['typescript'],
439+
}),
440+
})
441+
render(<ConfigurationManager />, { wrapper })
442+
443+
const button = await screen.findByText('Configure data caching')
444+
expect(button).toBeInTheDocument()
445+
446+
await user.click(button)
447+
448+
const modalHeader = await screen.findByText(
449+
'Configure bundle caching data'
450+
)
451+
expect(modalHeader).toBeInTheDocument()
452+
})
453+
})
377454
})
378455

379456
describe('TestAnalyticsConfiguration', () => {

src/pages/RepoPage/ConfigTab/tabs/ConfigurationManager/ConfigurationManager.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { useSuspenseQuery as useSuspenseQueryV5 } from '@tanstack/react-queryV5'
2+
import { useState } from 'react'
23
import { useParams } from 'react-router'
34

5+
import { ConfigureCachedBundleModal } from 'pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal'
46
import { TierNames } from 'services/tier'
7+
import { useFlags } from 'shared/featureFlags'
8+
import Icon from 'ui/Icon'
59

610
import FeatureGroup from './components/FeatureGroup'
711
import FeatureItem from './components/FeatureItem/FeatureItem'
@@ -141,6 +145,11 @@ function TestAnalyticsConfiguration({
141145
function BundleAnalysisConfiguration({
142146
repoConfiguration,
143147
}: ConfigurationGroupProps) {
148+
const { displayBundleCachingModal } = useFlags({
149+
displayBundleCachingModal: false,
150+
})
151+
152+
const [showBundleCachingModal, setShowBundleCachingModal] = useState(false)
144153
const jsOrTsPresent = !!repoConfiguration?.repository?.languages?.some(
145154
(lang) =>
146155
lang.toLowerCase() === 'javascript' || lang.toLowerCase() === 'typescript'
@@ -169,6 +178,21 @@ function BundleAnalysisConfiguration({
169178
>
170179
Track, monitor, and manage your bundle
171180
</FeatureItem>
181+
{displayBundleCachingModal ? (
182+
<div>
183+
<button
184+
onClick={() => setShowBundleCachingModal(true)}
185+
className="flex items-center gap-0.5 text-xs font-semibold text-ds-blue-darker hover:cursor-pointer hover:underline"
186+
>
187+
<Icon name="cog" size="sm" variant="outline" />
188+
Configure data caching
189+
</button>
190+
<ConfigureCachedBundleModal
191+
isOpen={showBundleCachingModal}
192+
setIsOpen={setShowBundleCachingModal}
193+
/>
194+
</div>
195+
) : null}
172196
</FeatureGroup.UniversalItems>
173197
</FeatureGroup>
174198
)

src/pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export const ConfigureCachedBundleModal = ({
203203

204204
const { data: bundleData, isPending: isBundlesPending } = useQueryV5({
205205
...CachedBundlesQueryOpts({ provider, owner, repo, branch: defaultBranch }),
206-
207206
select: (data) =>
208207
data.bundles.map((bundle) => ({
209208
bundleName: bundle.bundleName,

0 commit comments

Comments
 (0)