Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address single page view format issues #944

Merged
merged 11 commits into from
Mar 6, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import { Button } from 'react-bootstrap';
import { Button, Table } from 'react-bootstrap';
import { unescape } from 'lodash';
import {
parseListContent,
Expand All @@ -19,6 +19,7 @@ import { TestWindow } from '../../../resources/aria-at-test-window.mjs';
import { evaluateAtNameKey } from '../../../utils/aria.js';
import commandsJson from '../../../resources/commands.json';
import supportJson from '../../../resources/support.json';
import { convertAssertionPriority } from 'shared';

const NumberedList = styled.ol`
counter-reset: numbered-list;
Expand Down Expand Up @@ -169,19 +170,147 @@ const InstructionsRenderer = ({
commandsContent
);

const assertions = [...pageContent.instructions.assertions.assertions];
const assertionsContent = parseListContent(assertions);

headingLevel = 5;
howard-e marked this conversation as resolved.
Show resolved Hide resolved
const Heading = `h${headingLevel}`;

return (
<>
<NumberedList>{allInstructionsContent}</NumberedList>
<Heading>{pageContent.instructions.assertions.header}</Heading>
{pageContent.instructions.assertions.description}
<NumberedList>{assertionsContent}</NumberedList>
{settingsContent.length ? settingsContent : null}

{renderableContent.commands.map(
({ id, settings, assertionExceptions = [] }, i) => {
const settingsScreenText = isV2
? renderableContent.target.at.raw.settings[settings]
?.screenText ?? ''
howard-e marked this conversation as resolved.
Show resolved Hide resolved
: null;

let mustCount = 0;
let shouldCount = 0;
let mayCount = 0;

let assertions = [...renderableContent.assertions];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed in the alert example the should assertions were coming before the must assertions, which makes me think that sorting this array might be needed.

Screenshot 2024-03-05 at 5 05 33 PM


assertionExceptions.forEach(exception => {
const assertionIndex = assertions.findIndex(
assertion => {
return (
assertion.assertionId ===
exception.assertionId
);
}
);
if (exception.priority === 0) {
assertions.splice(assertionIndex, 1);
} else {
assertions[assertionIndex].priority =
exception.priority;
}
});

assertions.forEach(({ priority }) => {
const priorityString =
convertAssertionPriority(priority);
if (priorityString === 'MUST') mustCount += 1;
if (priorityString === 'SHOULD') shouldCount += 1;
if (priorityString === 'MAY') mayCount += 1;
});

const settingsScreenTextFormatted =
settingsScreenText === null
? ''
: ` (${settingsScreenText})`;

const scenarioTitle =
`${renderableContent.commands[i].keystroke}` +
`${settingsScreenTextFormatted}: ${mustCount} MUST, ` +
`${shouldCount} SHOULD, ${mayCount} MAY Assertions`;

if (isV2) {
return (
<React.Fragment key={`command-${id}-${i}`}>
<Heading
id={renderableContent.commands[i].keystroke}
>
{scenarioTitle}
</Heading>
<Table
key={`${id}-${i}`}
bordered
responsive
aria-labelledby={
renderableContent.commands[i].keystroke
}
>
<thead>
<tr>
<th>Priority</th>
<th>Assertion Phrase</th>
<th>Assertion Statement</th>
</tr>
</thead>
<tbody>
{assertions.map(
({
assertionPhrase,
assertionStatement,
priority,
assertionId
}) => (
<tr key={`${i}-${assertionId}`}>
<td>
{convertAssertionPriority(
priority
)}
</td>
<td>{assertionPhrase}</td>
<td>
{assertionStatement}
</td>
</tr>
)
)}
</tbody>
</Table>
</React.Fragment>
);
} else {
return (
<React.Fragment key={`command-${id}-${i}`}>
<Heading>{scenarioTitle}</Heading>
<Table
key={`${id}-${i}`}
bordered
responsive
aria-label={`Results for test ${test.title}`}
>
<thead>
<tr>
<th>Priority</th>
<th>Assertion Statement</th>
</tr>
</thead>
<tbody>
{assertions.map(
({ expectation, priority }) => (
<tr key={`${i}-${expectation}`}>
<td>
{convertAssertionPriority(
priority
)}
</td>
<td>{expectation}</td>
</tr>
)
)}
</tbody>
</Table>
</React.Fragment>
);
}
}
)}

<Button
disabled={!pageContent.instructions.openTestPage.enabled}
onClick={pageContent.instructions.openTestPage.click}
Expand Down
Loading