Skip to content

Commit

Permalink
fix: Only include CollectionJob metrics in Bot Status calculation on …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
howard-e and jugglinmike authored Oct 10, 2024
1 parent 3efd025 commit 84e0bd0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
7 changes: 5 additions & 2 deletions client/components/BotRunTestStatusList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions client/components/BotRunTestStatusList/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const TEST_PLAN_RUNS_TEST_RESULTS_QUERY = gql`
id
tester {
username
isBot
}
testResults {
id
Expand Down
58 changes: 52 additions & 6 deletions client/tests/BotRunTestStatusList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand All @@ -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
}
];
Expand All @@ -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(
<MockedProvider mocks={mocks} addTypename={false}>
<BotRunTestStatusList testPlanReportId="1" />
</MockedProvider>
);

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: [
Expand Down Expand Up @@ -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: [
Expand All @@ -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: [
Expand Down

0 comments on commit 84e0bd0

Please sign in to comment.