Skip to content

Commit a7d2de5

Browse files
[PRM-58] Fix for Select Download File Checkboxes (#604)
* Changed handleChangeClickCheckboxes * Changes to make sure selectedDocuments is always an array * Removed previous refactor attempt changes and corrected sorting issue * checking values of selected documents and search results * fixed selected document allowing duplicates * ignoring linting issues with consolge .log * Added additional logging * console log result * Refactored code SearchResults should used id not ID * Replaced all instanced of ID with id for SearchResults * Removed debugging logs
1 parent 12d5a2a commit a7d2de5

File tree

8 files changed

+30
-27
lines changed

8 files changed

+30
-27
lines changed

app/src/components/blocks/_lloydGeorge/lloydGeorgeDownloadComplete/LloydGeorgeDownloadComplete.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const numberOfFiles = 7;
1717
const selectedDocuments = ['test-id-1', 'test-id-2'];
1818
const downloadAllSelectedDocuments: Array<string> = [];
1919
const searchResults = [
20-
buildSearchResult({ fileName: '1of2_test.pdf', ID: 'test-id-1' }),
21-
buildSearchResult({ fileName: '2of2_test.pdf', ID: 'test-id-2' }),
22-
buildSearchResult({ fileName: '1of1_test.pdf', ID: 'test-id-3' }),
20+
buildSearchResult({ fileName: '1of2_test.pdf', id: 'test-id-1' }),
21+
buildSearchResult({ fileName: '2of2_test.pdf', id: 'test-id-2' }),
22+
buildSearchResult({ fileName: '1of1_test.pdf', id: 'test-id-3' }),
2323
];
2424

2525
jest.mock('react-router-dom', () => ({

app/src/components/blocks/_lloydGeorge/lloydGeorgeDownloadComplete/LloydGeorgeDownloadComplete.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ function LloydGeorgeDownloadComplete({ numberOfFiles, selectedDocuments, searchR
2626
};
2727

2828
const documentsList = searchResults
29-
?.filter((document) => selectedDocuments?.includes(document.ID))
29+
?.filter((document) => selectedDocuments?.includes(document.id))
3030
.map((document) => {
3131
return {
32-
ref: document.ID,
33-
id: document.ID,
32+
ref: document.id,
33+
id: document.id,
3434
fileName: document.fileName,
3535
};
3636
}) as GenericDocument[];

app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectDownloadStage/LloydGeorgeSelectDownloadStage.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ let history: MemoryHistory = createMemoryHistory({
3232
});
3333

3434
const searchResults = [
35-
buildSearchResult({ fileName: '1of2_test.pdf', ID: 'test-id-1' }),
36-
buildSearchResult({ fileName: '2of2_test.pdf', ID: 'test-id-2' }),
37-
buildSearchResult({ fileName: '1of1_test.pdf', ID: 'test-id-3' }),
35+
buildSearchResult({ fileName: '1of2_test.pdf', id: 'test-id-1' }),
36+
buildSearchResult({ fileName: '2of2_test.pdf', id: 'test-id-2' }),
37+
buildSearchResult({ fileName: '1of1_test.pdf', id: 'test-id-3' }),
3838
];
3939

4040
describe('LloydGeorgeSelectDownloadStage', () => {

app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectDownloadStage/LloydGeorgeSelectDownloadStage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ function LloydGeorgeSelectDownloadStage({ setDownloadStage, numberOfFiles }: Pro
102102
if (isMock(error)) {
103103
setSearchResults([
104104
buildSearchResult(),
105-
buildSearchResult({ fileName: 'fileName2.pdf', ID: '1234qwer-241ewewr-2' }),
106-
buildSearchResult({ fileName: 'fileName3.pdf', ID: '1234qwer-241ewewr-3' }),
105+
buildSearchResult({ fileName: 'fileName2.pdf', id: '1234qwer-241ewewr-2' }),
106+
buildSearchResult({ fileName: 'fileName3.pdf', id: '1234qwer-241ewewr-3' }),
107107
]);
108108
setSubmissionSearchState(SEARCH_AND_DOWNLOAD_STATE.SEARCH_SUCCEEDED);
109109
} else if (error.response?.status === 403) {

app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectSearchResults/LloydGeorgeSelectSearchResults.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const mockSetSelectedDocuments = jest.fn();
2222
const mockSetSubmissionSearchState = jest.fn();
2323
const mockSelectedDocuments = ['test-id-1', 'test-id-2'];
2424
const searchResults = [
25-
buildSearchResult({ fileName: '1of2_test.pdf', ID: 'test-id-1' }),
26-
buildSearchResult({ fileName: '2of2_test.pdf', ID: 'test-id-2' }),
27-
buildSearchResult({ fileName: '1of1_test.pdf', ID: 'test-id-3' }),
25+
buildSearchResult({ fileName: '1of2_test.pdf', id: 'test-id-1' }),
26+
buildSearchResult({ fileName: '2of2_test.pdf', id: 'test-id-2' }),
27+
buildSearchResult({ fileName: '1of1_test.pdf', id: 'test-id-3' }),
2828
];
2929
const searchResultOneFileOnly = [searchResults[0]];
30-
const mockAllSelectedDocuments = [searchResults[2].ID, searchResults[0].ID, searchResults[1].ID];
30+
const mockAllSelectedDocuments = [searchResults[2].id, searchResults[0].id, searchResults[1].id];
3131

3232
describe('LloydGeorgeSelectSearchResults', () => {
3333
beforeEach(() => {
@@ -85,7 +85,7 @@ describe('LloydGeorgeSelectSearchResults', () => {
8585

8686
it('add documentId to selectedDocument when checkbox is checked', async () => {
8787
renderComponent({ selectedDocuments: mockSelectedDocuments });
88-
const expectedSelectedDocument = [...mockSelectedDocuments, searchResults[2].ID];
88+
const expectedSelectedDocument = [...mockSelectedDocuments, searchResults[2].id];
8989

9090
const checkbox = screen.getByRole('checkbox', {
9191
name: `Select Filename ${searchResults[2].fileName}`,
@@ -101,7 +101,7 @@ describe('LloydGeorgeSelectSearchResults', () => {
101101
it('remove documentId from selectedDocument when a checkbox is unchecked', async () => {
102102
renderComponent({ selectedDocuments: mockSelectedDocuments });
103103
const expectedSelectedDocument = mockSelectedDocuments.filter(
104-
(id) => id !== searchResults[0].ID,
104+
(id) => id !== searchResults[0].id,
105105
);
106106

107107
const checkbox = screen.getByRole('checkbox', {

app/src/components/blocks/_lloydGeorge/lloydGeorgeSelectSearchResults/LloydGeorgeSelectSearchResults.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,21 @@ const AvailableFilesTable = ({
3636
if (selectedDocuments.length < searchResults.length) {
3737
const downloadableItems: string[] = [];
3838
searchResults.forEach((result) => {
39-
downloadableItems.push(result.ID);
39+
downloadableItems.push(result.id);
4040
});
4141
setSelectedDocuments(downloadableItems);
4242
} else {
4343
setSelectedDocuments([]);
4444
}
4545
};
46+
4647
const handleChangeCheckboxes = (e: React.FormEvent<HTMLInputElement>) => {
4748
const target = e.target as HTMLInputElement;
4849
const toggledDocumentId = target.value;
4950
if (target.checked) {
50-
setSelectedDocuments([...selectedDocuments, toggledDocumentId]);
51+
if (!selectedDocuments.includes(toggledDocumentId)) {
52+
setSelectedDocuments([...selectedDocuments, toggledDocumentId]);
53+
}
5154
} else {
5255
setSelectedDocuments(selectedDocuments.filter((id) => id !== toggledDocumentId));
5356
}
@@ -82,7 +85,7 @@ const AvailableFilesTable = ({
8285
aria-description={getToggleButtonAriaDescription()}
8386
>
8487
<span>
85-
{selectedDocuments.length === searchResults.length &&
88+
{selectedDocuments.length >= searchResults.length &&
8689
'Deselect all files'}
8790
{selectedDocuments.length < searchResults.length && 'Select all files'}
8891
</span>
@@ -123,11 +126,11 @@ const AvailableFilesTable = ({
123126
{allowSelectDocument && (
124127
<Table.Cell id={`selected-files-row-${index}`}>
125128
<Checkboxes.Box
126-
value={result.ID}
127-
id={result.ID}
129+
value={result.id}
130+
id={result.id}
128131
data-testid={`checkbox-${index}`}
129-
checked={selectedDocuments.includes(result.ID)}
130-
aria-checked={selectedDocuments.includes(result.ID)}
132+
checked={selectedDocuments.includes(result.id)}
133+
aria-checked={selectedDocuments.includes(result.id)}
131134
aria-label={`Select Filename ${result.fileName}`}
132135
onChange={(e) => handleChangeCheckboxes(e)}
133136
>
@@ -172,7 +175,7 @@ const LloydGeorgeSelectSearchResults = ({
172175
}: Props) => {
173176
const sortByFileName = (a: SearchResult, b: SearchResult) => {
174177
const fileNumberOfA = parseInt(a.fileName.substring(0, a.fileName.indexOf('of')));
175-
const fileNumberOfB = parseInt(b.fileName.substring(0, a.fileName.indexOf('of')));
178+
const fileNumberOfB = parseInt(b.fileName.substring(0, b.fileName.indexOf('of')));
176179
if (fileNumberOfA && fileNumberOfB) {
177180
return fileNumberOfA > fileNumberOfB ? 1 : -1;
178181
} else {

app/src/helpers/test/testBuilders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const buildSearchResult = (searchResultOverride?: Partial<SearchResult>) => {
127127
fileName: 'fileName.pdf',
128128
created: moment().format(),
129129
virusScannerResult: 'Clean',
130-
ID: '1234qwer-241ewewr',
130+
id: '1234qwer-241ewewr',
131131
fileSize: 224,
132132
...searchResultOverride,
133133
};

app/src/types/generic/searchResult.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export type SearchResult = {
22
fileName: string;
33
created: string;
44
virusScannerResult: string;
5-
ID: string;
5+
id: string;
66
fileSize: number;
77
};

0 commit comments

Comments
 (0)