Skip to content

Commit 1be45b0

Browse files
committed
improve test coverage and remove some comments
1 parent f4be910 commit 1be45b0

File tree

14 files changed

+365
-156
lines changed

14 files changed

+365
-156
lines changed

app/src/components/blocks/_admin/reviewDetailsDocumentSelectOrderStage/ReviewDetailsDocumentSelectOrderStage.test.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ReviewDetails } from '../../../../types/generic/reviews';
77
import { UploadDocument } from '../../../../types/pages/UploadDocumentsPage/types';
88
import userEvent from '@testing-library/user-event';
99

10-
// Mock DocumentSelectOrderStage component
1110
vi.mock('../../_documentUpload/documentSelectOrderStage/DocumentSelectOrderStage', () => ({
1211
default: vi.fn(
1312
({ documents, setDocuments, setMergedPdfBlob, existingDocuments, onSuccess }) => (
@@ -71,7 +70,7 @@ describe('ReviewDetailsDocumentSelectOrderStage', () => {
7170
'1',
7271
'1234567890',
7372
);
74-
// Set files to empty array to avoid spinner due to null check
73+
7574
mockReviewData.files = [];
7675

7776
const mockDocument = {
@@ -100,7 +99,7 @@ describe('ReviewDetailsDocumentSelectOrderStage', () => {
10099
<MemoryRouter>
101100
<ReviewDetailsDocumentSelectOrderStage
102101
reviewData={reviewData}
103-
documents={documents as any} // TODO fix
102+
documents={documents}
104103
setDocuments={mockSetDocuments}
105104
existingDocuments={existingDocuments!}
106105
/>
@@ -128,7 +127,6 @@ describe('ReviewDetailsDocumentSelectOrderStage', () => {
128127
it('renders DocumentSelectOrderStage when documents are initialized', async () => {
129128
renderComponent(mockReviewData, [], [mockDocument]);
130129

131-
// Wait for documentsInitialised state to update
132130
await waitFor(() => {
133131
expect(screen.getByTestId('mock-document-select-order-stage')).toBeInTheDocument();
134132
});
@@ -234,7 +232,6 @@ describe('ReviewDetailsDocumentSelectOrderStage', () => {
234232
expect(mockSetDocuments).toHaveBeenCalled();
235233
});
236234

237-
// Navigation is mocked via MemoryRouter, just verify setDocuments was called
238235
expect(mockSetDocuments).toHaveBeenCalled();
239236
});
240237

@@ -266,12 +263,10 @@ describe('ReviewDetailsDocumentSelectOrderStage', () => {
266263
it('resets documentsInitialised when review changes', async () => {
267264
const { rerender } = renderComponent(mockReviewData, [], [mockDocument]);
268265

269-
// Component should render DocumentSelectOrderStage
270266
await waitFor(() => {
271267
expect(screen.getByTestId('mock-document-select-order-stage')).toBeInTheDocument();
272268
});
273269

274-
// Change review data
275270
const newReviewData = new ReviewDetails(
276271
'new-id',
277272
testReviewSnoMed,
@@ -294,17 +289,14 @@ describe('ReviewDetailsDocumentSelectOrderStage', () => {
294289
</MemoryRouter>,
295290
);
296291

297-
// Should show spinner because documentsInitialised was reset and documents is empty
298292
expect(screen.getByText('Loading')).toBeInTheDocument();
299293
});
300294

301295
it('initializes documents when documents length changes from 0 to > 0', async () => {
302296
const { rerender } = renderComponent(mockReviewData, [], []);
303297

304-
// Initially should show spinner
305298
expect(screen.getByText('Loading')).toBeInTheDocument();
306299

307-
// Update with documents
308300
rerender(
309301
<MemoryRouter>
310302
<ReviewDetailsDocumentSelectOrderStage
@@ -316,7 +308,6 @@ describe('ReviewDetailsDocumentSelectOrderStage', () => {
316308
</MemoryRouter>,
317309
);
318310

319-
// Should now show the DocumentSelectOrderStage
320311
await waitFor(() => {
321312
expect(screen.getByTestId('mock-document-select-order-stage')).toBeInTheDocument();
322313
});
@@ -347,7 +338,6 @@ describe('ReviewDetailsDocumentSelectOrderStage', () => {
347338
expect(screen.getByTestId('mock-document-select-order-stage')).toBeInTheDocument();
348339
});
349340

350-
// The component should be rendered (verified by presence of the mock)
351341
expect(screen.getByTestId('mock-document-select-order-stage')).toBeInTheDocument();
352342
});
353343
});

app/src/components/blocks/_admin/reviewDetailsDocumentSelectStage/ReviewDetailsDocumentSelectStage.test.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
UploadDocument,
99
} from '../../../../types/pages/UploadDocumentsPage/types';
1010

11-
// Mock DocumentSelectStage component we are testing just ReviewDetailsDocumentSelectStage component
1211
vi.mock('../../_documentUpload/documentSelectStage/DocumentSelectStage', () => ({
1312
default: vi.fn(({ documents, setDocuments, documentType, filesErrorRef }) => (
1413
<div data-testid="mock-document-select-stage">
@@ -40,12 +39,10 @@ vi.mock('../../_documentUpload/documentSelectStage/DocumentSelectStage', () => (
4039
)),
4140
}));
4241

43-
// Mock Spinner component
4442
vi.mock('../../../generic/spinner/Spinner', () => ({
4543
default: vi.fn(() => <div data-testid="mock-spinner">Loading...</div>),
4644
}));
4745

48-
// Mock react-router-dom
4946
vi.mock('react-router-dom', () => ({
5047
useNavigate: vi.fn(() => vi.fn()),
5148
}));
@@ -62,7 +59,7 @@ describe('ReviewDetailsDocumentSelectStage', () => {
6259
'1',
6360
'1234567890',
6461
);
65-
// Set files to an empty array so component doesn't show spinner
62+
6663
mockReviewData.files = [];
6764

6865
const mockDocuments: UploadDocument[] = [];
@@ -129,7 +126,6 @@ describe('ReviewDetailsDocumentSelectStage', () => {
129126
/>,
130127
);
131128

132-
// Rerender with documents to trigger documentsInitialised state change
133129
rerender(
134130
<ReviewDetailsDocumentSelectStage
135131
reviewData={mockReviewData}
@@ -166,7 +162,6 @@ describe('ReviewDetailsDocumentSelectStage', () => {
166162
/>,
167163
);
168164

169-
// Rerender with documents to trigger documentsInitialised state change
170165
rerender(
171166
<ReviewDetailsDocumentSelectStage
172167
reviewData={mockReviewData}

app/src/components/blocks/_admin/reviewDetailsDocumentUploadingStage/ReviewDetailsDocumentUploadingStage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const ReviewDetailsDocumentUploadingStage = ({
5858
const virusReference = useRef(false);
5959
const interval = useRef<number>(0);
6060

61-
// Normalise document state when entering this page so the UI starts from a known state.
6261
const [hasNormalisedOnEntry, setHasNormalisedOnEntry] = useState(false);
6362
const [isLoading, setIsLoading] = useState(true);
6463
const hasNormalisedOnEntryRef = useRef(false);

app/src/components/blocks/_admin/reviewDetailsDownloadChoiceStage/ReviewDetailsDownloadChoiceStage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const ReviewDetailsDownloadChoiceStage: React.FC<ReviewDetailsDownloadChoiceProp
2929
);
3030

3131
useEffect(() => {
32-
// If no unselected files in state, navigate back to file select page
3332
if (!unselectedFiles.length) {
3433
if (reviewId) {
3534
const path = routeChildren.ADMIN_REVIEW_CHOOSE_WHICH_FILES.replace(

app/src/components/blocks/_admin/reviewDetailsFileSelectStage/ReviewDetailsFileSelectStage.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ describe('ReviewDetailsFileSelectStage', () => {
7171
displayName: 'lloyd george record',
7272
});
7373

74-
// jsdom doesn’t provide these in all environments.
7574
(globalThis.URL as any).createObjectURL = vi.fn(() => 'blob:mock-url');
7675
(HTMLElement.prototype as any).scrollIntoView = vi.fn();
7776
});

app/src/components/blocks/_admin/reviewDetailsNoFilesChoiceStage/ReviewDetailsNoFilesChoiceStage.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,13 @@ describe('ReviewDetailsNoFilesChoicePage', () => {
159159
it('clears error when checkbox is checked', async () => {
160160
render(<ReviewDetailsNoFilesChoiceStage reviewData={mockReviewData} />);
161161

162-
// First trigger error
163162
const continueButton = screen.getByRole('button', { name: 'Continue' });
164163
await userEvent.click(continueButton);
165164

166165
await waitFor(() => {
167166
expect(screen.getByText('There is a problem')).toBeInTheDocument();
168167
});
169168

170-
// Then check the checkbox
171169
const checkbox = screen.getByRole('checkbox', {
172170
name: /I don't need to add any of these files/i,
173171
});
@@ -200,7 +198,6 @@ describe('ReviewDetailsNoFilesChoicePage', () => {
200198
name: /I don't need to add any of these files/i,
201199
});
202200

203-
// Check then uncheck
204201
await userEvent.click(checkbox);
205202
await waitFor(() => {
206203
expect(checkbox).toBeChecked();

app/src/components/blocks/_admin/reviewDetailsPatientSearchStage/ReviewDetailsPatientSearchStage.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { AxiosError } from 'axios';
1212
import { JSX } from 'react/jsx-runtime';
1313
import { ReviewDetails } from '../../../../types/generic/reviews';
1414

15-
// Mock dependencies
1615
const mockNavigate = vi.fn();
1716
const mockUseParams = vi.fn();
1817
const mockUseBaseAPIUrl = vi.fn();
@@ -410,15 +409,13 @@ describe('ReviewDetailsPatientSearchPage', () => {
410409
/>,
411410
);
412411

413-
// First submit with error
414412
await userEvent.click(screen.getByTestId('continue-button'));
415413

416414
await waitFor(() => {
417415
const errorMessages = screen.getAllByText(incorrectFormatMessage);
418416
expect(errorMessages.length).toBeGreaterThan(0);
419417
});
420418

421-
// Then submit with valid input
422419
const input = screen.getByTestId('nhs-number-input');
423420
await userEvent.clear(input);
424421
await userEvent.type(input, '9000000009');
@@ -649,7 +646,6 @@ describe('ReviewDetailsPatientSearchPage', () => {
649646
/>,
650647
);
651648

652-
// Component renders successfully with prop
653649
expect(screen.getByRole('heading')).toBeInTheDocument();
654650
});
655651
});

app/src/components/blocks/_admin/reviewsDetailsStage/ReviewsDetailsStage.test.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ const renderComponent = (reviewData?: ReviewDetails, reviewSnoMed?: DOCUMENT_TYP
8181
'9691914948',
8282
);
8383

84-
// Prevent the page from refetching review details in tests unless a test explicitly populates files.
8584
if (currentReviewData.files === null) {
8685
currentReviewData.files = [];
8786
}
@@ -129,10 +128,8 @@ describe('ReviewDetailsPage', () => {
129128
mockUsePatientDetailsContext.mockReturnValue([mockPatientDetails, mockSetPatientDetails]);
130129
mockUseSessionContext.mockReturnValue([mockSession, vi.fn()]);
131130

132-
// Mock isLocal to return false by default
133131
vi.spyOn(isLocalModule, 'isLocal', 'get').mockReturnValue(false);
134132

135-
// Mock getPdfObjectUrl
136133
vi.spyOn(getPdfObjectUrlModule, 'getPdfObjectUrl').mockImplementation(
137134
(url, setPdfUrl, setStage) => {
138135
setPdfUrl('blob:mock-pdf-url');
@@ -229,7 +226,6 @@ describe('ReviewDetailsPage', () => {
229226
renderComponent(mockReviewData);
230227

231228
await waitFor(() => {
232-
// The name should be formatted as "LastName, FirstName"
233229
expect(screen.getByText('Dae, Lillie')).toBeInTheDocument();
234230
});
235231
});
@@ -238,7 +234,6 @@ describe('ReviewDetailsPage', () => {
238234
renderComponent(mockReviewData);
239235

240236
await waitFor(() => {
241-
// NHS number should be formatted with spaces
242237
expect(screen.getByText('969 191 4948')).toBeInTheDocument();
243238
});
244239
});
@@ -247,7 +242,6 @@ describe('ReviewDetailsPage', () => {
247242
renderComponent(mockReviewData);
248243

249244
await waitFor(() => {
250-
// Date should be formatted as "3 June 2002"
251245
expect(screen.getByText('3 June 2002')).toBeInTheDocument();
252246
});
253247
});
@@ -565,17 +559,14 @@ describe('ReviewDetailsPage', () => {
565559
expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument();
566560
});
567561

568-
// Trigger error
569562
await user.click(screen.getByRole('button', { name: 'Continue' }));
570563
expect(screen.getByText('There is a problem')).toBeInTheDocument();
571564

572-
// Select option - error should remain until form is submitted again
573565
const yesRadio = screen.getByRole('radio', {
574566
name: 'Yes, the details match and I want to accept this document',
575567
});
576568
await user.click(yesRadio);
577569

578-
// Error is still visible until Continue is clicked again
579570
expect(screen.getByText('There is a problem')).toBeInTheDocument();
580571
});
581572
});
@@ -638,12 +629,10 @@ describe('ReviewDetailsPage', () => {
638629

639630
describe('Navigation - Missing Review Data', () => {
640631
it('renders content when review data is provided', async () => {
641-
// Mock isLocal to false so review data won't be loaded
642632
vi.spyOn(isLocalModule, 'isLocal', 'get').mockReturnValue(false);
643633

644634
renderComponent(mockReviewData);
645635

646-
// Wait for loading to complete and verify content is rendered
647636
await waitFor(
648637
() => {
649638
expect(
@@ -860,7 +849,6 @@ describe('ReviewDetailsPage', () => {
860849
await waitFor(() => {
861850
const pdfCard = screen.getByTestId('pdf-card');
862851
expect(pdfCard).toBeInTheDocument();
863-
// Check for the flex container wrapper
864852
expect(pdfCard.closest('.lloydgeorge_record-stage_flex')).toBeInTheDocument();
865853
});
866854
});

app/src/components/blocks/_admin/reviewsPage/ReviewsPage.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ describe('ReviewsPage', () => {
250250
screen.getByRole('columnheader', { name: 'Sender ODS code' }),
251251
).toBeInTheDocument();
252252
expect(screen.getByRole('columnheader', { name: 'Date uploaded' })).toBeInTheDocument();
253-
// Review reason column is commented out in the component
254-
// expect(screen.getByRole('columnheader', { name: 'Review reason' })).toBeInTheDocument();
255253
expect(screen.getByRole('columnheader', { name: 'View' })).toBeInTheDocument();
256254
});
257255

@@ -287,9 +285,6 @@ describe('ReviewsPage', () => {
287285
expect(screen.getByText('Electronic Health Record')).toBeInTheDocument();
288286
expect(screen.getByText('Y12345')).toBeInTheDocument();
289287
expect(screen.getByText('Y67890')).toBeInTheDocument();
290-
// Review reason is not displayed as the column is commented out
291-
// expect(screen.getByText('Missing metadata')).toBeInTheDocument();
292-
// expect(screen.getByText('Duplicate record')).toBeInTheDocument();
293288
});
294289

295290
it('displays formatted NHS numbers', async () => {

app/src/components/blocks/_admin/reviewsPage/ReviewsPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export const ReviewsPage = ({ setReviewData }: ReviewsPageProps): React.JSX.Elem
121121
const [failedLoading, setFailedLoading] = useState(false);
122122
const [count, setCount] = useState(0);
123123

124-
// Store page tokens: index is page number - 1, value is the startKey for that page
125124
const [pageTokens, setPageTokens] = useState<string[]>(['']);
126125

127126
const isLastPage = (): boolean => !nextPageToken || count < pageLimit;
@@ -153,7 +152,6 @@ export const ReviewsPage = ({ setReviewData }: ReviewsPageProps): React.JSX.Elem
153152
setCount(response.count);
154153
setCurrentPage(pageNumber);
155154

156-
// If we got a nextPageToken and don't have it stored yet, add it to our history
157155
const hasNextPage = nextPageToken.includes(response.nextPageToken || '');
158156
if (!hasNextPage || (response.nextPageToken && !pageTokens[pageNumber])) {
159157
setPageTokens((prev) => {
@@ -174,7 +172,6 @@ export const ReviewsPage = ({ setReviewData }: ReviewsPageProps): React.JSX.Elem
174172
};
175173

176174
const handleSearch = async (): Promise<void> => {
177-
// Reset pagination when searching
178175
setIsLoading(true);
179176
setSearchValue(inputValue);
180177
setCurrentPage(1);

0 commit comments

Comments
 (0)