Skip to content

Commit 03c6f39

Browse files
authored
Merge pull request #843 from w3c/v2-test-format-testrun
Update Test Runner for V2 Test Format
2 parents 7146600 + 68e3eea commit 03c6f39

File tree

8 files changed

+828
-212
lines changed

8 files changed

+828
-212
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { useEffect, useState } from 'react';
22
import PropTypes from 'prop-types';
3-
import nextId from 'react-id-generator';
43
import styled from '@emotion/styled';
54
import { Button } from 'react-bootstrap';
5+
import { unescape } from 'lodash';
6+
import { parseListContent } from '../../TestRenderer/utils';
67
import {
78
userCloseWindow,
89
userOpenWindow
@@ -14,6 +15,7 @@ import {
1415
import { TestWindow } from '../../../resources/aria-at-test-window.mjs';
1516
import { evaluateAtNameKey } from '../../../utils/aria.js';
1617
import commandsJson from '../../../resources/commands.json';
18+
import supportJson from '../../../resources/support.json';
1719

1820
const Container = styled.div`
1921
padding: 20px;
@@ -50,21 +52,16 @@ const NumberedList = styled.ol`
5052
}
5153
`;
5254

53-
const BulletList = styled.ul`
54-
padding-inline-start: 2.5rem;
55-
list-style-type: circle;
56-
57-
> li {
58-
display: list-item;
59-
list-style: circle;
60-
}
61-
`;
62-
63-
const InstructionsRenderer = ({ testResult, testPageUrl, at }) => {
55+
const InstructionsRenderer = ({
56+
testResult,
57+
testPageUrl,
58+
at,
59+
testFormatVersion = 1
60+
}) => {
6461
const { test = {} } = testResult;
6562
const { renderableContent } = test;
6663
const [testRunExport, setTestRunExport] = useState();
67-
const [instructionsContent, setInstructionsContent] = useState({
64+
const [pageContent, setPageContent] = useState({
6865
instructions: {
6966
assertions: { assertions: [] },
7067
instructions: {
@@ -125,104 +122,66 @@ const InstructionsRenderer = ({ testResult, testPageUrl, at }) => {
125122

126123
useEffect(() => {
127124
if (testRunExport) {
128-
setInstructionsContent(testRunExport.instructions());
125+
setPageContent(testRunExport.instructions());
129126
}
130127
}, [testRunExport]);
131128

132-
const parseRichContent = (instruction = []) => {
133-
let content = null;
134-
for (let value of instruction) {
135-
if (typeof value === 'string') {
136-
if (value === '.')
137-
content = (
138-
<>
139-
{content}
140-
{value}
141-
</>
142-
);
143-
else
144-
content = content = (
145-
<>
146-
{content} {value}
147-
</>
148-
);
149-
} else if ('href' in value) {
150-
const { href, description } = value;
151-
content = (
152-
<>
153-
{content} <a href={href}>{description}</a>
154-
</>
155-
);
156-
}
157-
}
158-
return content;
159-
};
160-
161-
const parseListContent = (instructions = [], commandsContent = null) => {
162-
return instructions.map((value, index) => {
163-
if (typeof value === 'string')
164-
return (
165-
<li key={nextId()}>
166-
{value}
167-
{commandsContent &&
168-
index === instructions.length - 1 && (
169-
<BulletList>{commandsContent}</BulletList>
170-
)}
171-
</li>
172-
);
173-
else if (Array.isArray(value))
174-
return (
175-
<li key={nextId()}>
176-
{parseRichContent(value)}
177-
{commandsContent &&
178-
index === instructions.length - 1 && (
179-
<BulletList>{commandsContent}</BulletList>
180-
)}
181-
</li>
182-
);
183-
});
184-
};
185-
186-
const allInstructions = [
187-
...instructionsContent.instructions.instructions.instructions,
188-
...instructionsContent.instructions.instructions.strongInstructions,
189-
instructionsContent.instructions.instructions.commands.description
190-
];
191-
192-
const commands =
193-
instructionsContent.instructions.instructions.commands.commands;
129+
let allInstructions;
130+
const isV2 = testFormatVersion === 2;
131+
132+
if (isV2) {
133+
const commandSettingSpecified = renderableContent.commands.some(
134+
({ settings }) => settings && settings !== 'defaultMode'
135+
);
136+
137+
const defaultInstructions =
138+
renderableContent.target.at.raw
139+
.defaultConfigurationInstructionsHTML;
140+
const setupScriptDescription = `${supportJson.testPlanStrings.openExampleInstruction} ${renderableContent.target.setupScript.scriptDescription}`;
141+
const testInstructions = renderableContent.instructions.instructions;
142+
const settingsInstructions = `${
143+
supportJson.testPlanStrings.commandListPreface
144+
}${
145+
commandSettingSpecified
146+
? ` ${supportJson.testPlanStrings.commandListSettingsPreface}`
147+
: ''
148+
}`;
149+
150+
allInstructions = [
151+
defaultInstructions,
152+
setupScriptDescription + '.',
153+
testInstructions + ' ' + settingsInstructions
154+
].map(e => unescape(e));
155+
} else {
156+
allInstructions = [
157+
...pageContent.instructions.instructions.instructions,
158+
...pageContent.instructions.instructions.strongInstructions,
159+
pageContent.instructions.instructions.commands.description
160+
];
161+
}
194162

163+
const commands = pageContent.instructions.instructions.commands.commands;
195164
const commandsContent = parseListContent(commands);
165+
196166
const allInstructionsContent = parseListContent(
197167
allInstructions,
198168
commandsContent
199169
);
200170

201-
const assertions = [
202-
...instructionsContent.instructions.assertions.assertions
203-
];
204-
171+
const assertions = [...pageContent.instructions.assertions.assertions];
205172
const assertionsContent = parseListContent(assertions);
206173

207174
return (
208175
<Container>
209-
<p>{instructionsContent.instructions.description}</p>
210-
<Heading>
211-
{instructionsContent.instructions.instructions.header}
212-
</Heading>
213176
<NumberedList>{allInstructionsContent}</NumberedList>
214-
<Heading>
215-
{instructionsContent.instructions.assertions.header}
216-
</Heading>
217-
{instructionsContent.instructions.assertions.description}
177+
<Heading>{pageContent.instructions.assertions.header}</Heading>
178+
{pageContent.instructions.assertions.description}
218179
<NumberedList>{assertionsContent}</NumberedList>
219180
<Button
220-
disabled={
221-
!instructionsContent.instructions.openTestPage.enabled
222-
}
223-
onClick={instructionsContent.instructions.openTestPage.click}
181+
disabled={!pageContent.instructions.openTestPage.enabled}
182+
onClick={pageContent.instructions.openTestPage.click}
224183
>
225-
{instructionsContent.instructions.openTestPage.button}
184+
{pageContent.instructions.openTestPage.button}
226185
</Button>
227186
</Container>
228187
);
@@ -235,7 +194,8 @@ InstructionsRenderer.propTypes = {
235194
testPageUrl: PropTypes.string,
236195
at: PropTypes.shape({
237196
name: PropTypes.string.isRequired
238-
})
197+
}),
198+
testFormatVersion: PropTypes.number
239199
};
240200

241201
export default InstructionsRenderer;

client/components/CandidateReview/CandidateTestPlanRun/index.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ const CandidateTestPlanRun = () => {
502502
completedAt: new Date()
503503
}}
504504
testPageUrl={testPlanReport.testPlanVersion.testPageUrl}
505+
testFormatVersion={
506+
testPlanVersion.metadata.testFormatVersion
507+
}
505508
/>,
506509
...testPlanReports.map(testPlanReport => {
507510
const testResult =

0 commit comments

Comments
 (0)