Skip to content

Commit c64ce66

Browse files
get all selector working as well
1 parent 49a08d5 commit c64ce66

File tree

2 files changed

+87
-34
lines changed

2 files changed

+87
-34
lines changed

src/pages/CommitDetailPage/CommitCoverage/UploadsCard/UploadsCard.test.tsx

+50-23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { graphql, HttpResponse } from 'msw'
1414
import { setupServer } from 'msw/node'
1515
import { MemoryRouter, Route } from 'react-router-dom'
1616

17+
import { IgnoredIdsQueryOptions } from 'pages/CommitDetailPage/queries/IgnoredIdsQueryOptions'
18+
1719
import UploadsCard from './UploadsCard'
1820
import { useUploads } from './useUploads'
1921

@@ -47,13 +49,17 @@ beforeAll(() => {
4749
console.error = () => {}
4850
server.listen()
4951
})
52+
5053
afterEach(() => {
5154
queryClient.clear()
5255
queryClientV5.clear()
5356
server.resetHandlers()
5457
vi.clearAllMocks()
5558
})
56-
afterAll(() => server.close())
59+
60+
afterAll(() => {
61+
server.close()
62+
})
5763

5864
interface MockCommitErrors {
5965
data: {
@@ -197,6 +203,7 @@ describe('UploadsCard', () => {
197203
const covReportHistory = screen.getByText(/Coverage reports history/)
198204
expect(covReportHistory).toBeInTheDocument()
199205
})
206+
200207
it('renders different cis', () => {
201208
render(<UploadsCard />, { wrapper })
202209

@@ -205,6 +212,7 @@ describe('UploadsCard', () => {
205212
const travis = screen.getByText(/travis/)
206213
expect(travis).toBeInTheDocument()
207214
})
215+
208216
it('renders build ids', () => {
209217
render(<UploadsCard />, { wrapper })
210218

@@ -219,6 +227,7 @@ describe('UploadsCard', () => {
219227
const id5 = screen.getByText(/837462/)
220228
expect(id5).toBeInTheDocument()
221229
})
230+
222231
it('renders flags', () => {
223232
render(<UploadsCard />, { wrapper })
224233

@@ -259,6 +268,7 @@ describe('UploadsCard', () => {
259268
expect(currentlyNoUploads).toBeInTheDocument()
260269
})
261270
})
271+
262272
describe('renders empty Uploads', () => {
263273
// ??
264274
beforeEach(() => {
@@ -280,6 +290,7 @@ describe('UploadsCard', () => {
280290
expect(uploads).toBeInTheDocument()
281291
})
282292
})
293+
283294
describe('The yaml viewer', () => {
284295
beforeEach(() => {
285296
setup({
@@ -819,6 +830,7 @@ describe('UploadsCard', () => {
819830
})
820831
})
821832
})
833+
822834
describe('select all interactor', () => {
823835
beforeEach(() => {
824836
setup({
@@ -912,32 +924,47 @@ describe('UploadsCard', () => {
912924
})
913925
})
914926

915-
it('unselects all when clicked', async () => {
916-
const user = userEvent.setup()
917-
render(<UploadsCard />, { wrapper })
927+
describe('unselects all when clicked', () => {
928+
it('unselects all when clicked', async () => {
929+
const user = userEvent.setup()
930+
render(<UploadsCard />, { wrapper })
918931

919-
const checkboxes = screen.getAllByRole('checkbox')
920-
const travisCheckbox = checkboxes[0]
921-
const travisUploadCheckbox1 = checkboxes[1]
922-
const travisUploadCheckbox2 = checkboxes[2]
932+
const checkboxes = screen.getAllByRole('checkbox')
933+
const travisCheckbox = checkboxes[0]
934+
const travisUploadCheckbox1 = checkboxes[1]
935+
const travisUploadCheckbox2 = checkboxes[2]
923936

924-
expect(travisCheckbox).toBeChecked()
925-
expect(travisUploadCheckbox1).toBeChecked()
926-
expect(travisUploadCheckbox2).toBeChecked()
937+
expect(travisCheckbox).toBeChecked()
938+
expect(travisUploadCheckbox1).toBeChecked()
939+
expect(travisUploadCheckbox2).toBeChecked()
927940

928-
await user.click(travisCheckbox!)
941+
await user.click(travisCheckbox!)
929942

930-
expect(travisCheckbox).not.toBeChecked()
931-
expect(travisUploadCheckbox1).not.toBeChecked()
932-
expect(travisUploadCheckbox2).not.toBeChecked()
933-
934-
// 'circleci' uploads remain checked
935-
const circleciCheckbox = checkboxes[3]
936-
const circleciUploadCheckbox1 = checkboxes[4]
937-
const circleciUploadCheckbox2 = checkboxes[5]
938-
expect(circleciCheckbox).toBeChecked()
939-
expect(circleciUploadCheckbox1).toBeChecked()
940-
expect(circleciUploadCheckbox2).toBeChecked()
943+
expect(travisCheckbox).not.toBeChecked()
944+
expect(travisUploadCheckbox1).not.toBeChecked()
945+
expect(travisUploadCheckbox2).not.toBeChecked()
946+
947+
// 'circleci' uploads remain checked
948+
const circleciCheckbox = checkboxes[3]
949+
const circleciUploadCheckbox1 = checkboxes[4]
950+
const circleciUploadCheckbox2 = checkboxes[5]
951+
expect(circleciCheckbox).toBeChecked()
952+
expect(circleciUploadCheckbox1).toBeChecked()
953+
expect(circleciUploadCheckbox2).toBeChecked()
954+
})
955+
956+
it('adds ids to ignored ids query', async () => {
957+
const user = userEvent.setup()
958+
render(<UploadsCard />, { wrapper })
959+
960+
const checkboxes = screen.getAllByRole('checkbox')
961+
const travisCheckbox = checkboxes[0]
962+
await user.click(travisCheckbox!)
963+
964+
expect(
965+
queryClientV5.getQueryData(IgnoredIdsQueryOptions().queryKey)
966+
).toEqual([0, 1])
967+
})
941968
})
942969

943970
it('shows an intermediate state', async () => {

src/pages/CommitDetailPage/CommitCoverage/UploadsCard/UploadsCard.tsx

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { useQueryClient as useQueryClientV5 } from '@tanstack/react-queryV5'
12
import flatMap from 'lodash/flatMap'
23
import { Fragment, useState } from 'react'
34

5+
import { IgnoredIdsQueryOptions } from 'pages/CommitDetailPage/queries/IgnoredIdsQueryOptions'
46
import { useCommitErrors } from 'services/commitErrors'
57
import { cn } from 'shared/utils/cn'
68
import { NONE } from 'shared/utils/extractUploads'
@@ -28,6 +30,7 @@ export const SelectState = {
2830
} as const
2931

3032
function UploadsCard() {
33+
const queryClientV5 = useQueryClientV5()
3134
const [showYAMLModal, setShowYAMLModal] = useState(false)
3235
const [uploadFilters, setUploadFilters] = useState<UploadFilters>({
3336
flagErrors: false,
@@ -52,10 +55,22 @@ function UploadsCard() {
5255
const providerUploads = groupedUploads[provider]
5356
const providerUploadsIndex = providerUploads?.map((_, i) => i)
5457
const providerList = new Set(providerUploadsIndex)
55-
setSelectedProviderSelectedUploads((prevState) => ({
56-
...prevState,
57-
[provider]: new Set(providerUploadsIndex),
58-
}))
58+
setSelectedProviderSelectedUploads((prevState) => {
59+
const updatedIds = {
60+
...prevState,
61+
[provider]: new Set(providerUploadsIndex),
62+
}
63+
64+
// Ids added are ignored, so we need to use the previous state to remove them, we also use a Set to remove duplicates
65+
queryClientV5.setQueryData(
66+
IgnoredIdsQueryOptions().queryKey,
67+
Array.from(
68+
new Set(Object.values(prevState).flatMap((ids) => Array.from(ids)))
69+
)
70+
)
71+
72+
return updatedIds
73+
})
5974
return providerList
6075
}
6176

@@ -75,13 +90,24 @@ function UploadsCard() {
7590
}
7691

7792
const handleSelectAllForProviderGroup = (provider: string) => {
78-
setSelectedProviderSelectedUploads((prevState) => ({
79-
...prevState,
80-
[provider]:
81-
determineCheckboxState(provider) === SelectState.NONE_SELECTED
82-
? fillSelectedUploads(provider)
83-
: new Set(),
84-
}))
93+
setSelectedProviderSelectedUploads((prevState) => {
94+
const updatedIds = {
95+
...prevState,
96+
[provider]:
97+
determineCheckboxState(provider) === SelectState.NONE_SELECTED
98+
? fillSelectedUploads(provider)
99+
: new Set<number>(),
100+
}
101+
102+
// Ids added are ignored, so we need to use the previous state to remove them, we also use a Set to remove duplicates
103+
queryClientV5.setQueryData(
104+
IgnoredIdsQueryOptions().queryKey,
105+
Array.from(
106+
new Set(Object.values(prevState).flatMap((ids) => Array.from(ids)))
107+
)
108+
)
109+
return updatedIds
110+
})
85111
}
86112

87113
const determineCheckboxIcon = (title: string) => {

0 commit comments

Comments
 (0)