1
1
import React , { useEffect , useState } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import nextId from 'react-id-generator' ;
4
3
import styled from '@emotion/styled' ;
5
4
import { Button } from 'react-bootstrap' ;
5
+ import { unescape } from 'lodash' ;
6
+ import { parseListContent } from '../../TestRenderer/utils' ;
6
7
import {
7
8
userCloseWindow ,
8
9
userOpenWindow
@@ -14,6 +15,7 @@ import {
14
15
import { TestWindow } from '../../../resources/aria-at-test-window.mjs' ;
15
16
import { evaluateAtNameKey } from '../../../utils/aria.js' ;
16
17
import commandsJson from '../../../resources/commands.json' ;
18
+ import supportJson from '../../../resources/support.json' ;
17
19
18
20
const Container = styled . div `
19
21
padding: 20px;
@@ -50,21 +52,16 @@ const NumberedList = styled.ol`
50
52
}
51
53
` ;
52
54
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
+ } ) => {
64
61
const { test = { } } = testResult ;
65
62
const { renderableContent } = test ;
66
63
const [ testRunExport , setTestRunExport ] = useState ( ) ;
67
- const [ instructionsContent , setInstructionsContent ] = useState ( {
64
+ const [ pageContent , setPageContent ] = useState ( {
68
65
instructions : {
69
66
assertions : { assertions : [ ] } ,
70
67
instructions : {
@@ -125,104 +122,66 @@ const InstructionsRenderer = ({ testResult, testPageUrl, at }) => {
125
122
126
123
useEffect ( ( ) => {
127
124
if ( testRunExport ) {
128
- setInstructionsContent ( testRunExport . instructions ( ) ) ;
125
+ setPageContent ( testRunExport . instructions ( ) ) ;
129
126
}
130
127
} , [ testRunExport ] ) ;
131
128
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
+ }
194
162
163
+ const commands = pageContent . instructions . instructions . commands . commands ;
195
164
const commandsContent = parseListContent ( commands ) ;
165
+
196
166
const allInstructionsContent = parseListContent (
197
167
allInstructions ,
198
168
commandsContent
199
169
) ;
200
170
201
- const assertions = [
202
- ...instructionsContent . instructions . assertions . assertions
203
- ] ;
204
-
171
+ const assertions = [ ...pageContent . instructions . assertions . assertions ] ;
205
172
const assertionsContent = parseListContent ( assertions ) ;
206
173
207
174
return (
208
175
< Container >
209
- < p > { instructionsContent . instructions . description } </ p >
210
- < Heading >
211
- { instructionsContent . instructions . instructions . header }
212
- </ Heading >
213
176
< 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 }
218
179
< NumberedList > { assertionsContent } </ NumberedList >
219
180
< 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 }
224
183
>
225
- { instructionsContent . instructions . openTestPage . button }
184
+ { pageContent . instructions . openTestPage . button }
226
185
</ Button >
227
186
</ Container >
228
187
) ;
@@ -235,7 +194,8 @@ InstructionsRenderer.propTypes = {
235
194
testPageUrl : PropTypes . string ,
236
195
at : PropTypes . shape ( {
237
196
name : PropTypes . string . isRequired
238
- } )
197
+ } ) ,
198
+ testFormatVersion : PropTypes . number
239
199
} ;
240
200
241
201
export default InstructionsRenderer ;
0 commit comments