From c85e49487f02b67acd8e89cce7d1eb1edbc3489d Mon Sep 17 00:00:00 2001 From: Howard Edwards Date: Thu, 20 Jun 2024 09:53:51 -0400 Subject: [PATCH] Revert creating new automation related files for bot UI -- modify existing files to hold a temporary branch to support Test Queue v2 until v1 is removed --- .../components/BotRunTestStatusList/index.js | 115 +++++++++++---- .../TestQueue2/BotRunTestStatusList/index.js | 132 ------------------ .../BotRunTestStatusList/queries.js | 27 ---- .../BotTestCompletionStatus/index.js | 52 ------- .../index.js | 53 ------- .../CompletionStatusListItem/index.jsx | 6 +- .../CompletionStatusListItem/queries.js | 19 --- client/components/TestQueue2/index.jsx | 3 +- .../BotTestCompletionStatus/index.js | 39 ++++-- .../index.js | 20 ++- 10 files changed, 136 insertions(+), 330 deletions(-) delete mode 100644 client/components/TestQueue2/BotRunTestStatusList/index.js delete mode 100644 client/components/TestQueue2/BotRunTestStatusList/queries.js delete mode 100644 client/components/TestQueue2/CompletionStatusListItem/BotTestCompletionStatus/index.js delete mode 100644 client/components/TestQueue2/CompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus/index.js delete mode 100644 client/components/TestQueue2/CompletionStatusListItem/queries.js diff --git a/client/components/BotRunTestStatusList/index.js b/client/components/BotRunTestStatusList/index.js index 6d1873c50..9a5bf389e 100644 --- a/client/components/BotRunTestStatusList/index.js +++ b/client/components/BotRunTestStatusList/index.js @@ -5,6 +5,7 @@ import { useQuery } from '@apollo/client'; import styled from '@emotion/styled'; import ReportStatusDot from '../common/ReportStatusDot'; +// TODO: Remove when Test Queue v1 is removed const BotRunTestStatusUnorderedList = styled.ul` list-style-type: none; background-color: #f6f8fa; @@ -14,6 +15,21 @@ const BotRunTestStatusUnorderedList = styled.ul` white-space: nowrap; `; +const BotRunTestContainer = styled.div` + font-size: 0.875rem !important; + padding: 0.5rem 0; + margin: 0.5rem 0; + + background: #f5f5f5; + border-radius: 0.25rem; + + white-space: nowrap; +`; + +const BotRunTestStatusUnorderedListV2 = styled.ul` + list-style-type: none; +`; + /** * Generate a string describing the status of some number of "Tests" where the * word "Test" is pluralized appropriately and qualified with the provided @@ -33,7 +49,10 @@ const testCountString = (count, status) => const pollInterval = 2000; -const BotRunTestStatusList = ({ testPlanReportId }) => { +const BotRunTestStatusList = ({ + testPlanReportId, + fromTestQueueV2 = false // TODO: Remove when Test Queue v1 is removed +}) => { const { data: testPlanRunsQueryResult, startPolling, @@ -84,40 +103,78 @@ const BotRunTestStatusList = ({ testPlanReportId }) => { ) { return null; } + return ( - - {RUNNING > 0 && ( -
  • - - {testCountString(RUNNING, 'Running')} -
  • - )} - {ERROR > 0 && ( -
  • - - {testCountString(ERROR, 'Error')} -
  • - )} -
  • - - {testCountString(COMPLETED, 'Completed')} -
  • -
  • - - {testCountString(QUEUED, 'Queued')} -
  • - {CANCELLED > 0 && ( -
  • - - {testCountString(CANCELLED, 'Cancelled')} -
  • + <> + {fromTestQueueV2 ? ( + + Bot Status: + + {RUNNING > 0 && ( +
  • + + {testCountString(RUNNING, 'Running')} +
  • + )} + {ERROR > 0 && ( +
  • + + {testCountString(ERROR, 'Error')} +
  • + )} +
  • + + {testCountString(COMPLETED, 'Completed')} +
  • +
  • + + {testCountString(QUEUED, 'Queued')} +
  • + {CANCELLED > 0 && ( +
  • + + {testCountString(CANCELLED, 'Cancelled')} +
  • + )} +
    +
    + ) : ( + + {RUNNING > 0 && ( +
  • + + {testCountString(RUNNING, 'Running')} +
  • + )} + {ERROR > 0 && ( +
  • + + {testCountString(ERROR, 'Error')} +
  • + )} +
  • + + {testCountString(COMPLETED, 'Completed')} +
  • +
  • + + {testCountString(QUEUED, 'Queued')} +
  • + {CANCELLED > 0 && ( +
  • + + {testCountString(CANCELLED, 'Cancelled')} +
  • + )} +
    )} -
    + ); }; BotRunTestStatusList.propTypes = { - testPlanReportId: PropTypes.string.isRequired + testPlanReportId: PropTypes.string.isRequired, + fromTestQueueV2: PropTypes.bool }; export default BotRunTestStatusList; diff --git a/client/components/TestQueue2/BotRunTestStatusList/index.js b/client/components/TestQueue2/BotRunTestStatusList/index.js deleted file mode 100644 index 9c8e30ae3..000000000 --- a/client/components/TestQueue2/BotRunTestStatusList/index.js +++ /dev/null @@ -1,132 +0,0 @@ -import React, { useMemo } from 'react'; -import PropTypes from 'prop-types'; -import { TEST_PLAN_RUNS_TEST_RESULTS_QUERY } from './queries'; -import { useQuery } from '@apollo/client'; -import styled from '@emotion/styled'; -import ReportStatusDot from '../../common/ReportStatusDot'; - -const BotRunTestContainer = styled.div` - font-size: 0.875rem !important; - padding: 0.5rem 0; - margin: 0.5rem 0; - - background: #f5f5f5; - border-radius: 0.25rem; - - white-space: nowrap; -`; - -const BotRunTestStatusUnorderedList = styled.ul` - list-style-type: none; -`; - -/** - * Generate a string describing the status of some number of "Tests" where the - * word "Test" is pluralized appropriately and qualified with the provided - * status. As a single primitive string value, the output of this utility - * function can be rendered into the document without interstitial space - * characters which produces unnatural speech in some screen readers: - * - * https://github.com/w3c/aria-at-app/issues/872 - * - * @param {number} count the integer number of tests being described - * @param {string} status the status of the tests being described - * - * @returns {string} the pluralized text - */ -const testCountString = (count, status) => - `${count} Test${count === 1 ? '' : 's'} ${status}`; - -const pollInterval = 2000; - -const BotRunTestStatusList = ({ testPlanReportId }) => { - const { - data: testPlanRunsQueryResult, - startPolling, - stopPolling - } = useQuery(TEST_PLAN_RUNS_TEST_RESULTS_QUERY, { - variables: { testPlanReportId }, - fetchPolicy: 'cache-and-network', - pollInterval - }); - - const { COMPLETED, ERROR, RUNNING, CANCELLED, QUEUED } = useMemo(() => { - const counter = { - COMPLETED: 0, - ERROR: 0, - RUNNING: 0, - CANCELLED: 0, - QUEUED: 0 - }; - let anyPossibleUpdates = false; - if (testPlanRunsQueryResult?.testPlanRuns) { - for (const { - collectionJob - } of testPlanRunsQueryResult.testPlanRuns) { - if (collectionJob?.testStatus) { - for (const { status } of collectionJob.testStatus) { - counter[status]++; - if (status === 'QUEUED' || status === 'RUNNING') { - anyPossibleUpdates = true; - } - } - } - } - // it's possible that we got incomplete data on first fetch and - // stopped the polling, so restart the polling if we detect any - // possible future updates, otherwise stop. - if (anyPossibleUpdates) { - startPolling(pollInterval); - } else { - stopPolling(); - } - } - return counter; - }, [testPlanRunsQueryResult, stopPolling, startPolling]); - - if ( - !testPlanRunsQueryResult || - testPlanRunsQueryResult.testPlanRuns.length === 0 - ) { - return null; - } - return ( - - Bot Status: - - {RUNNING > 0 && ( -
  • - - {testCountString(RUNNING, 'Running')} -
  • - )} - {ERROR > 0 && ( -
  • - - {testCountString(ERROR, 'Error')} -
  • - )} -
  • - - {testCountString(COMPLETED, 'Completed')} -
  • -
  • - - {testCountString(QUEUED, 'Queued')} -
  • - {CANCELLED > 0 && ( -
  • - - {testCountString(CANCELLED, 'Cancelled')} -
  • - )} -
    -
    - ); -}; - -BotRunTestStatusList.propTypes = { - testPlanReportId: PropTypes.string.isRequired -}; - -export default BotRunTestStatusList; diff --git a/client/components/TestQueue2/BotRunTestStatusList/queries.js b/client/components/TestQueue2/BotRunTestStatusList/queries.js deleted file mode 100644 index cd99fb2bc..000000000 --- a/client/components/TestQueue2/BotRunTestStatusList/queries.js +++ /dev/null @@ -1,27 +0,0 @@ -import { gql } from '@apollo/client'; - -export const TEST_PLAN_RUNS_TEST_RESULTS_QUERY = gql` - query TestPlanRunsTestResults($testPlanReportId: ID!) { - testPlanRuns(testPlanReportId: $testPlanReportId) { - id - tester { - username - } - testResults { - id - scenarioResults { - assertionResults { - passed - failedReason - } - } - } - collectionJob { - status - testStatus { - status - } - } - } - } -`; diff --git a/client/components/TestQueue2/CompletionStatusListItem/BotTestCompletionStatus/index.js b/client/components/TestQueue2/CompletionStatusListItem/BotTestCompletionStatus/index.js deleted file mode 100644 index 18729995a..000000000 --- a/client/components/TestQueue2/CompletionStatusListItem/BotTestCompletionStatus/index.js +++ /dev/null @@ -1,52 +0,0 @@ -import React, { useEffect } from 'react'; -import PropTypes from 'prop-types'; -import { useTestPlanRunValidatedAssertionCounts } from '../../../../hooks/useTestPlanRunValidatedAssertionCounts'; - -const BotTestCompletionStatus = ({ testPlanRun, id, runnableTestsLength }) => { - const { - totalValidatedAssertions, - totalPossibleAssertions, - testResultsLength, - stopPolling - } = useTestPlanRunValidatedAssertionCounts(testPlanRun, 2000); - - useEffect(() => { - if (testResultsLength === runnableTestsLength) { - stopPolling(); - } - }, [testResultsLength, stopPolling]); - - return ( - - ); -}; - -BotTestCompletionStatus.propTypes = { - testPlanRun: PropTypes.shape({ - id: PropTypes.string.isRequired, - testResults: PropTypes.arrayOf( - PropTypes.shape({ - scenarioResults: PropTypes.arrayOf( - PropTypes.shape({ - assertionResults: PropTypes.arrayOf( - PropTypes.shape({ - passed: PropTypes.bool - }) - ) - }) - ) - }) - ) - }).isRequired, - id: PropTypes.string.isRequired, - runnableTestsLength: PropTypes.number.isRequired -}; - -export default BotTestCompletionStatus; diff --git a/client/components/TestQueue2/CompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus/index.js b/client/components/TestQueue2/CompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus/index.js deleted file mode 100644 index 5dbd53ebd..000000000 --- a/client/components/TestQueue2/CompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus/index.js +++ /dev/null @@ -1,53 +0,0 @@ -import React, { useMemo } from 'react'; -import PropTypes from 'prop-types'; -import { useQuery } from '@apollo/client'; -import { TEST_PLAN_RUN_ASSERTION_RESULTS_QUERY } from '../queries'; - -const PreviouslyAutomatedTestCompletionStatus = ({ - runnableTestsLength, - testPlanRunId, - id -}) => { - const { data: testPlanRunAssertionsQueryResult } = useQuery( - TEST_PLAN_RUN_ASSERTION_RESULTS_QUERY, - { - variables: { - testPlanRunId: testPlanRunId - }, - fetchPolicy: 'cache-and-network' - } - ); - - const numValidatedTests = useMemo(() => { - if (!testPlanRunAssertionsQueryResult) { - return 0; - } - - const { testPlanRun } = testPlanRunAssertionsQueryResult; - - if (!testPlanRun) { - return 0; - } - - const { testResults = [] } = testPlanRun; - - return testResults.reduce( - (acc, { completedAt }) => acc + (completedAt ? 1 : 0), - 0 - ); - }, [testPlanRunAssertionsQueryResult]); - - return ( - - {`${numValidatedTests} of ${runnableTestsLength} tests evaluated`} - - ); -}; - -PreviouslyAutomatedTestCompletionStatus.propTypes = { - runnableTestsLength: PropTypes.number.isRequired, - testPlanRunId: PropTypes.string.isRequired, - id: PropTypes.string.isRequired -}; - -export default PreviouslyAutomatedTestCompletionStatus; diff --git a/client/components/TestQueue2/CompletionStatusListItem/index.jsx b/client/components/TestQueue2/CompletionStatusListItem/index.jsx index db7793f5a..9e55a58a1 100644 --- a/client/components/TestQueue2/CompletionStatusListItem/index.jsx +++ b/client/components/TestQueue2/CompletionStatusListItem/index.jsx @@ -2,8 +2,8 @@ import React, { useMemo } from 'react'; import PropTypes from 'prop-types'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faRobot } from '@fortawesome/free-solid-svg-icons'; -import BotTestCompletionStatus from '@components/TestQueue2/CompletionStatusListItem/BotTestCompletionStatus'; -import PreviouslyAutomatedTestCompletionStatus from '@components/TestQueue2/CompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus'; +import BotTestCompletionStatus from '@components/TestQueueCompletionStatusListItem/BotTestCompletionStatus'; +import PreviouslyAutomatedTestCompletionStatus from '@components/TestQueueCompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus'; const CompletionStatusListItem = ({ rowId, @@ -32,6 +32,7 @@ const CompletionStatusListItem = ({ id={`BotTestCompletionStatus_${rowId}`} testPlanRun={testPlanRun} runnableTestsLength={testPlanReport.runnableTestsLength} + fromTestQueueV2 /> ); } else { @@ -50,6 +51,7 @@ const CompletionStatusListItem = ({ id={`PreviouslyAutomatedTestCompletionStatus_${rowId}`} testPlanRunId={testPlanRun.id} runnableTestsLength={testPlanReport.runnableTestsLength} + fromTestQueueV2 /> ) : ( diff --git a/client/components/TestQueue2/CompletionStatusListItem/queries.js b/client/components/TestQueue2/CompletionStatusListItem/queries.js deleted file mode 100644 index 561579bd4..000000000 --- a/client/components/TestQueue2/CompletionStatusListItem/queries.js +++ /dev/null @@ -1,19 +0,0 @@ -import { gql } from '@apollo/client'; - -export const TEST_PLAN_RUN_ASSERTION_RESULTS_QUERY = gql` - query TestPlanRunAssertionResultsByTestPlanRunId($testPlanRunId: ID!) { - testPlanRun(id: $testPlanRunId) { - id - testResults { - id - completedAt - scenarioResults { - assertionResults { - passed - failedReason - } - } - } - } - } -`; diff --git a/client/components/TestQueue2/index.jsx b/client/components/TestQueue2/index.jsx index d0082163f..72e3b162f 100644 --- a/client/components/TestQueue2/index.jsx +++ b/client/components/TestQueue2/index.jsx @@ -20,7 +20,7 @@ import { calculatePercentComplete } from '../../utils/calculatePercentComplete'; import ProgressBar from '../common/ClippedProgressBar'; import AssignTesters from './AssignTesters'; import Actions from './Actions'; -import BotRunTestStatusList from './BotRunTestStatusList'; +import BotRunTestStatusList from '../BotRunTestStatusList'; const DisclosureComponent = styled(DisclosureComponentUnstyled)` h3 { @@ -350,6 +350,7 @@ const TestQueue = () => { {hasBotRun ? ( ) : null} diff --git a/client/components/TestQueueCompletionStatusListItem/BotTestCompletionStatus/index.js b/client/components/TestQueueCompletionStatusListItem/BotTestCompletionStatus/index.js index 7319020b1..a395cc48e 100644 --- a/client/components/TestQueueCompletionStatusListItem/BotTestCompletionStatus/index.js +++ b/client/components/TestQueueCompletionStatusListItem/BotTestCompletionStatus/index.js @@ -2,7 +2,12 @@ import React, { useEffect } from 'react'; import PropTypes from 'prop-types'; import { useTestPlanRunValidatedAssertionCounts } from '../../../hooks/useTestPlanRunValidatedAssertionCounts'; -const BotTestCompletionStatus = ({ testPlanRun, id, runnableTestsLength }) => { +const BotTestCompletionStatus = ({ + testPlanRun, + id, + runnableTestsLength, + fromTestQueueV2 = false // TODO: Remove when Test Queue v1 is removed +}) => { const { totalValidatedAssertions, totalPossibleAssertions, @@ -17,14 +22,27 @@ const BotTestCompletionStatus = ({ testPlanRun, id, runnableTestsLength }) => { }, [testResultsLength, stopPolling]); return ( -
      -
    • - {`Responses for ${testResultsLength} of ${runnableTestsLength} tests recorded`} -
    • -
    • - {`Verdicts for ${totalValidatedAssertions} of ${totalPossibleAssertions} assertions assigned`} -
    • -
    + <> + {fromTestQueueV2 ? ( +
      +
    • + {`Responses for ${testResultsLength} of ${runnableTestsLength} tests recorded`} +
    • +
    • + {`Verdicts for ${totalValidatedAssertions} of ${totalPossibleAssertions} assertions assigned`} +
    • +
    + ) : ( +
      +
    • + {`Responses for ${testResultsLength} of ${runnableTestsLength} tests recorded`} +
    • +
    • + {`Verdicts for ${totalValidatedAssertions} of ${totalPossibleAssertions} assertions assigned`} +
    • +
    + )} + ); }; @@ -46,7 +64,8 @@ BotTestCompletionStatus.propTypes = { ) }).isRequired, id: PropTypes.string.isRequired, - runnableTestsLength: PropTypes.number.isRequired + runnableTestsLength: PropTypes.number.isRequired, + fromTestQueueV2: PropTypes.bool }; export default BotTestCompletionStatus; diff --git a/client/components/TestQueueCompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus/index.js b/client/components/TestQueueCompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus/index.js index 7ec7cec7f..1ac71b589 100644 --- a/client/components/TestQueueCompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus/index.js +++ b/client/components/TestQueueCompletionStatusListItem/PreviouslyAutomatedTestCompletionStatus/index.js @@ -6,7 +6,8 @@ import { TEST_PLAN_RUN_ASSERTION_RESULTS_QUERY } from '../queries'; const PreviouslyAutomatedTestCompletionStatus = ({ runnableTestsLength, testPlanRunId, - id + id, + fromTestQueueV2 = false // TODO: Remove when Test Queue v1 is removed }) => { const { data: testPlanRunAssertionsQueryResult } = useQuery( TEST_PLAN_RUN_ASSERTION_RESULTS_QUERY, @@ -38,16 +39,25 @@ const PreviouslyAutomatedTestCompletionStatus = ({ }, [testPlanRunAssertionsQueryResult]); return ( -
    - {`${numValidatedTests} of ${runnableTestsLength} tests evaluated`} -
    + <> + {fromTestQueueV2 ? ( + + {`${numValidatedTests} of ${runnableTestsLength} tests evaluated`} + + ) : ( +
    + {`${numValidatedTests} of ${runnableTestsLength} tests evaluated`} +
    + )} + ); }; PreviouslyAutomatedTestCompletionStatus.propTypes = { runnableTestsLength: PropTypes.number.isRequired, testPlanRunId: PropTypes.string.isRequired, - id: PropTypes.string.isRequired + id: PropTypes.string.isRequired, + fromTestQueueV2: PropTypes.bool }; export default PreviouslyAutomatedTestCompletionStatus;