Skip to content

Commit 6885af8

Browse files
authored
Merge pull request #1154 from digital-land/fix/check-show-all
check page now shows all rows found by async
2 parents 15f9e26 + d2d4e19 commit 6885af8

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/controllers/resultsController.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const failedUrlRequestTemplate = 'results/failedUrlRequest'
1515
const resultsTemplate = 'results/results'
1616

1717
class ResultsController extends PageController {
18-
/* Custom middleware */
18+
/* Custom middleware, currently the controller can load results/results, results/failedFileRequest and results/failedUrlRequest templates */
1919
middlewareSetup () {
2020
super.middlewareSetup()
2121
this.use(validateParams)
@@ -129,10 +129,8 @@ export async function fetchResponseDetails (req, res, next) {
129129
try {
130130
if (req.locals.template !== failedFileRequestTemplate && req.locals.template !== failedUrlRequestTemplate) {
131131
const detailsOpts = req.locals.detailsOptions ?? {}
132-
const responseDetails = req.locals.template === resultsTemplate
133-
// pageNumber starts with: 1, fetchResponseDetails parameter `pageOffset` starts with 0
134-
? await req.locals.requestData.fetchResponseDetails(pageNumber - 1, 50, { severity: 'error', ...detailsOpts })
135-
: await req.locals.requestData.fetchResponseDetails(pageNumber - 1, 50, { ...detailsOpts })
132+
// Original code used a if statement to check template and filter by error severity accordingly, but move to always showing all details in results/results template
133+
const responseDetails = await req.locals.requestData.fetchResponseDetails(pageNumber - 1, 50, { ...detailsOpts })
136134
req.locals.responseDetails = responseDetails
137135
}
138136
} catch (e) {
@@ -161,7 +159,8 @@ export const fieldToColumnMapping = ({ columns }) => {
161159
export function setupTableParams (req, res, next) {
162160
if (req.locals.template !== failedFileRequestTemplate && req.locals.template !== failedUrlRequestTemplate) {
163161
const responseDetails = req.locals.responseDetails
164-
let rows = responseDetails.getRowsWithVerboseColumns(req.locals.requestData.hasErrors())
162+
// Optionally filter out all non - error rows from dataset
163+
let rows = responseDetails.getRowsWithVerboseColumns(false)
165164
// remove any issues that aren't of severity error
166165
rows = rows.map((row) => {
167166
const { columns, ...rest } = row
@@ -368,6 +367,7 @@ export function getTotalRows (req, res, next) {
368367
const totalRows = Number.parseInt(responseDetails.pagination.totalResults)
369368
// NOTE: the fallback number may not be accurate, but it's better than just giving up and throwing
370369
req.totalRows = Number.isInteger(totalRows) ? totalRows : responseDetails.getRows().length
370+
req.locals.totalRows = req.totalRows
371371
next()
372372
}
373373

@@ -471,13 +471,8 @@ export function getPassedChecks (req, res, next) {
471471
}
472472
}
473473

474-
// add task complete for how many rows are in the table
475-
if (totalRows > 0) {
476-
passedChecks.unshift(makePassedCheck(`Found ${totalRows} rows`))
477-
478-
if (tasks.length === 0 && missingColumnTasks.length === 0) {
479-
passedChecks.push(makePassedCheck('All data is valid'))
480-
}
474+
if (totalRows > 0 && tasks.length === 0 && missingColumnTasks.length === 0) {
475+
passedChecks.push(makePassedCheck('All data is valid'))
481476
}
482477

483478
req.locals.passedChecks = passedChecks

src/views/check/results/results.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ <h1 class="govuk-heading-l">
105105
value: {
106106
text: options.uploadInfo.checkedTime | govukDateTime
107107
}
108+
},
109+
{
110+
key: {
111+
text: "Found"
112+
},
113+
value: {
114+
text: options.totalRows + (" row" if options.totalRows === 1 else " rows")
115+
}
108116
}
109117
] %}
110118

test/integration/test_recieving_results.playwright.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ test('receiving a result with errors', async ({ page }) => {
5555

5656
expect(tableValues[0]).toEqual(expectedTableValues[0])
5757
expect(tableValues[1]).toEqual(expectedTableValues[1])
58-
expect(tableValues[2]).toEqual(expectedTableValues[3])
58+
expect(tableValues[2]).toEqual(expectedTableValues[2])
59+
expect(tableValues[3]).toEqual(expectedTableValues[3])
5960

6061
const issues = errorResponseDetails.map(detail => detail.issue_logs.filter(issue => issue.severity === 'error').map(issue => issue.message)).filter(issue => issue.length > 0)
6162

test/unit/resultsController.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,11 @@ describe('getPassedChecks()', () => {
299299
totalRows: 99,
300300
missingColumnTasks: []
301301
}
302-
it('displays correct number of rows', () => {
302+
it('shows all data is valid when no errors', () => {
303303
const req = structuredClone(reqTemplate)
304304
getPassedChecks(req, {}, vi.fn())
305305

306306
expect(req.locals.passedChecks).toMatchObject([
307-
{
308-
status: { tag: { text: 'Passed' } },
309-
title: { text: 'Found 99 rows' }
310-
},
311307
{
312308
status: { tag: { text: 'Passed' } },
313309
title: { text: 'All data is valid' }

0 commit comments

Comments
 (0)