From 84e0bd0b46e80bea8c5c43eae3b5b4e6ffdce5b9 Mon Sep 17 00:00:00 2001 From: Howard Edwards Date: Thu, 10 Oct 2024 09:12:47 -0400 Subject: [PATCH] fix: Only include CollectionJob metrics in Bot Status calculation on Test Queue page when `tester.isBot` is true (#1237) * Check if user is a bot before including in Bot Status calculation * Update and add mock data for tests --------- Co-authored-by: Mike Pennisi --- .../components/BotRunTestStatusList/index.js | 7 ++- .../BotRunTestStatusList/queries.js | 1 + client/tests/BotRunTestStatusList.test.jsx | 58 +++++++++++++++++-- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/client/components/BotRunTestStatusList/index.js b/client/components/BotRunTestStatusList/index.js index 7fbae914a..f77fe8ca7 100644 --- a/client/components/BotRunTestStatusList/index.js +++ b/client/components/BotRunTestStatusList/index.js @@ -60,8 +60,11 @@ const BotRunTestStatusList = ({ testPlanReportId }) => { }; let anyPossibleUpdates = false; if (testPlanRunsQueryResult?.testPlanRuns) { - for (const { collectionJob } of testPlanRunsQueryResult.testPlanRuns) { - if (collectionJob?.testStatus) { + for (const { + collectionJob, + tester + } of testPlanRunsQueryResult.testPlanRuns) { + if (collectionJob?.testStatus && tester?.isBot) { for (const { status } of collectionJob.testStatus) { counter[status]++; if (status === 'QUEUED' || status === 'RUNNING') { diff --git a/client/components/BotRunTestStatusList/queries.js b/client/components/BotRunTestStatusList/queries.js index a12ab4d55..e6c635911 100644 --- a/client/components/BotRunTestStatusList/queries.js +++ b/client/components/BotRunTestStatusList/queries.js @@ -6,6 +6,7 @@ export const TEST_PLAN_RUNS_TEST_RESULTS_QUERY = gql` id tester { username + isBot } testResults { id diff --git a/client/tests/BotRunTestStatusList.test.jsx b/client/tests/BotRunTestStatusList.test.jsx index d6e5cc5a3..666d276f4 100644 --- a/client/tests/BotRunTestStatusList.test.jsx +++ b/client/tests/BotRunTestStatusList.test.jsx @@ -26,7 +26,7 @@ test('correctly displays statuses for single COMPLETED test run', async () => { { id: '0', testResults: new Array(3).fill(null), - tester: { username: 'bot' }, + tester: { username: 'bot', isBot: true }, collectionJob: { status: COLLECTION_JOB_STATUS.COMPLETED, testStatus: [ @@ -59,7 +59,7 @@ test('correctly ignores test results from a human-submitted test plan run', asyn { id: '0', testResults: new Array(2).fill(null), - tester: { username: 'bot' }, + tester: { username: 'bot', isBot: true }, collectionJob: { status: COLLECTION_JOB_STATUS.COMPLETED, testStatus: [ @@ -71,7 +71,7 @@ test('correctly ignores test results from a human-submitted test plan run', asyn { id: '1', testResults: new Array(2).fill(null), - tester: { username: 'human' }, + tester: { username: 'human', isBot: false }, collectionJob: null } ]; @@ -90,12 +90,58 @@ test('correctly ignores test results from a human-submitted test plan run', asyn }); }); +// See gh-1237 - Check if user is a bot, to include in Bot Status calculation on Test Queue page +// https://github.com/w3c/aria-at-app/pull/1237 +test('correctly ignores test results from a human-submitted test plan run with a collectionJob attribute', async () => { + const testPlanRuns = [ + { + id: '0', + testResults: new Array(3).fill(null), + tester: { username: 'bot', isBot: true }, + collectionJob: { + status: COLLECTION_JOB_STATUS.COMPLETED, + testStatus: [ + { status: COLLECTION_JOB_STATUS.COMPLETED }, + { status: COLLECTION_JOB_STATUS.COMPLETED }, + { status: COLLECTION_JOB_STATUS.COMPLETED } + ] + } + }, + { + id: '1', + testResults: new Array(3).fill(null), + tester: { username: 'human', isBot: false }, + collectionJob: { + status: COLLECTION_JOB_STATUS.COMPLETED, + testStatus: [ + { status: COLLECTION_JOB_STATUS.COMPLETED }, + { status: COLLECTION_JOB_STATUS.COMPLETED }, + { status: COLLECTION_JOB_STATUS.COMPLETED } + ] + } + } + ]; + + const mocks = getMocks(testPlanRuns); + + const { getByText } = render( + + + + ); + + await waitFor(async () => { + expect(getByText('3 Tests Completed')).toBeInTheDocument(); + expect(getByText('0 Tests Queued')).toBeInTheDocument(); + }); +}); + test('correctly displays statuses for CANCELLED test run', async () => { const testPlanRuns = [ { id: '0', testResults: new Array(2).fill(null), - tester: { username: 'bot' }, + tester: { username: 'bot', isBot: true }, collectionJob: { status: COLLECTION_JOB_STATUS.CANCELLED, testStatus: [ @@ -127,7 +173,7 @@ test('correctly displays statuses for multiple RUNNING and QUEUED test runs', as { id: '0', testResults: new Array(2).fill(null), - tester: { username: 'bot' }, + tester: { username: 'bot', isBot: true }, collectionJob: { status: COLLECTION_JOB_STATUS.RUNNING, testStatus: [ @@ -140,7 +186,7 @@ test('correctly displays statuses for multiple RUNNING and QUEUED test runs', as { id: '1', testResults: new Array(2).fill(null), - tester: { username: 'bot' }, + tester: { username: 'bot', isBot: true }, collectionJob: { status: COLLECTION_JOB_STATUS.CANCELLED, testStatus: [