@@ -8,6 +8,7 @@ import OptionsInput from './OptionsInput';
8
8
9
9
type TestFormProps = {
10
10
engine : RegexEngine ;
11
+ testUrl ?: string ; // override for use during engine development
11
12
testInput : TestInput ;
12
13
}
13
14
@@ -16,8 +17,10 @@ async function runTest(test_url:string, testInput: TestInput): Promise<TestOutpu
16
17
const postData =
17
18
`regex=${ encodeURIComponent ( testInput . regex ) } ` +
18
19
`&replacement=${ encodeURIComponent ( testInput . replacement ) } ` +
19
- `&${ testInput . option . map ( ( option ) => `option=${ option } ` ) . join ( "&" ) } ` +
20
- `&${ testInput . inputs . map ( ( input ) => `input=${ input } ` ) . join ( "&" ) } ` ;
20
+ `&${ testInput . option . map ( ( option ) => `option=${ encodeURIComponent ( option ) } ` ) . join ( "&" ) } ` +
21
+ `&${ testInput . inputs . map ( ( input ) => `input=${ encodeURIComponent ( input ) } ` ) . join ( "&" ) } ` ;
22
+
23
+ console . log ( "posting" , test_url , postData ) ;
21
24
22
25
const response = await fetch ( test_url , {
23
26
method : "POST" ,
@@ -45,17 +48,17 @@ export default function TestForm(props: TestFormProps) {
45
48
) ) ;
46
49
console . log ( "render" , testInput . inputs ) ;
47
50
48
-
49
51
const onSubmit = async ( event : React . FormEvent < HTMLFormElement > ) => {
50
52
event . preventDefault ( ) ;
51
53
const form = event . currentTarget ;
52
54
const formData = new FormData ( form ) ;
53
55
const localInput = formDataToTestInput ( props . engine . handle , formData ) ;
54
- console . log ( props . engine . test_url , localInput ) ;
56
+ const testUrl = props . testUrl || props . engine . test_url ;
57
+ console . log ( testUrl , localInput ) ;
55
58
setTestInput ( localInput ) ;
56
59
setTestOutput ( null ) ;
57
- if ( props . engine . test_url ) {
58
- setTestOutput ( await runTest ( props . engine . test_url , localInput ) ) ;
60
+ if ( testUrl ) {
61
+ setTestOutput ( await runTest ( testUrl , localInput ) ) ;
59
62
}
60
63
} ;
61
64
@@ -96,13 +99,17 @@ export default function TestForm(props: TestFormProps) {
96
99
}
97
100
98
101
return (
99
- < >
102
+ < >
103
+ {
104
+ props . testUrl ? < div className = "alert alert-warning" > Testing against { props . testUrl } !</ div > : < > </ >
105
+ }
100
106
{ ( testInput . regex ?
101
107
( testOutput ? < TestResults testOutput = { testOutput } /> : < > < h2 > Results</ h2 > < p > Loading...</ p > </ > )
102
108
: < > </ > )
103
109
}
104
110
< h2 > Expression to test</ h2 >
105
- < form method = "post" action = "results.html" onSubmit = { onSubmit } >
111
+ < form method = "get" action = "index.html" onSubmit = { onSubmit } >
112
+ { props . testUrl ? < input type = "hidden" name = "testurl" value = { props . testUrl } /> : < > </ > }
106
113
< div className = "mb-3" >
107
114
< label htmlFor = "regex" className = "form-label" > Regular Expression</ label >
108
115
< input type = "text" className = "form-control" id = "regex" name = "regex" defaultValue = { testInput . regex } />
0 commit comments