@@ -16,22 +16,27 @@ import { Preview } from "@/client/Preview";
16
16
import type { ParameterWithSource } from "@/gen/types" ;
17
17
import {
18
18
defaultExampleParameters ,
19
+ defaultExampleParamterValues ,
19
20
formTypesExampleParameters ,
20
21
} from "@/test-data/preview" ;
21
22
import { mockUsers } from "@/user" ;
22
23
23
24
type TestAppProps = {
24
25
parameters : ParameterWithSource [ ] ;
26
+ parameterValues ?: Record < string , string > ;
25
27
} ;
26
28
27
- const TestPreview : FC < TestAppProps > = ( { parameters } ) => {
29
+ const TestPreview : FC < TestAppProps > = ( {
30
+ parameters,
31
+ parameterValues = { } ,
32
+ } ) => {
28
33
return (
29
34
< PanelGroup direction = "horizontal" >
30
35
< Preview
31
36
wasmLoadState = "loaded"
32
37
isDebouncing = { false }
33
38
onDownloadOutput = { ( ) => null }
34
- parameterValues = { { } }
39
+ parameterValues = { parameterValues }
35
40
setParameterValues = { ( ) => null }
36
41
output = { null }
37
42
parameters = { parameters }
@@ -44,20 +49,25 @@ const TestPreview: FC<TestAppProps> = ({ parameters }) => {
44
49
) ;
45
50
} ;
46
51
47
- const router = ( parameters : ParameterWithSource [ ] ) =>
52
+ const router = ( parameters : ParameterWithSource [ ] , parameterValues = { } ) =>
48
53
createBrowserRouter ( [
49
54
{
50
55
path : "*" ,
51
- Component : ( ) => < TestPreview parameters = { parameters } /> ,
56
+ Component : ( ) => (
57
+ < TestPreview
58
+ parameters = { parameters }
59
+ parameterValues = { parameterValues }
60
+ />
61
+ ) ,
52
62
} ,
53
63
] ) ;
54
64
55
- const TestApp : FC < TestAppProps > = ( { parameters } ) => {
65
+ const TestApp : FC < TestAppProps > = ( { parameters, parameterValues } ) => {
56
66
return (
57
67
< ThemeProvider >
58
68
< TooltipProvider >
59
69
< EditorProvider >
60
- < RouterProvider router = { router ( parameters ) } />
70
+ < RouterProvider router = { router ( parameters , parameterValues ) } />
61
71
</ EditorProvider >
62
72
</ TooltipProvider >
63
73
</ ThemeProvider >
@@ -73,8 +83,7 @@ describe("Preview - Rendering", () => {
73
83
const page = render ( < TestApp parameters = { [ ] } /> ) ;
74
84
75
85
expect ( findByTestId ( page . container , "preview-empty-state" ) ) ;
76
-
77
- } )
86
+ } ) ;
78
87
79
88
it ( "should render the default example as expected" , async ( ) => {
80
89
const page = render ( < TestApp parameters = { defaultExampleParameters } /> ) ;
@@ -87,7 +96,7 @@ describe("Preview - Rendering", () => {
87
96
) ;
88
97
} ) ;
89
98
90
- it ( "should render the form type example as expected" , async ( ) => {
99
+ it ( "should render the form type example as with the expected default values " , async ( ) => {
91
100
const page = render ( < TestApp parameters = { formTypesExampleParameters } /> ) ;
92
101
93
102
const formTypeSelects = queryAllByLabelText (
@@ -142,4 +151,57 @@ describe("Preview - Rendering", () => {
142
151
) ;
143
152
expect ( checkbox . getAttribute ( "data-state" ) ) . toBe ( "unchecked" ) ;
144
153
} ) ;
154
+
155
+ it ( "should render form elements with set values" , async ( ) => {
156
+ const page = render (
157
+ < TestApp
158
+ parameters = { formTypesExampleParameters }
159
+ parameterValues = { defaultExampleParamterValues }
160
+ />
161
+ ) ;
162
+
163
+ const formTypeSelects = queryAllByLabelText (
164
+ page . container ,
165
+ "How do you want to format the options of the next parameter?Immutable" ,
166
+ ) ;
167
+
168
+ expect ( formTypeSelects [ 0 ] . textContent ) . toBe ( "Radio Selector" ) ;
169
+
170
+ const singleRadioGroup = getByLabelText (
171
+ page . container ,
172
+ "Selecting a single value from a list of options.Immutable"
173
+ ) ;
174
+ expect ( getByLabelText ( singleRadioGroup , "Alpha" ) . getAttribute ( "data-state" ) ) . toBe (
175
+ "unchecked"
176
+ ) ;
177
+ expect ( getByLabelText ( singleRadioGroup , "Bravo" ) . getAttribute ( "data-state" ) ) . toBe (
178
+ "checked"
179
+ ) ;
180
+ expect ( getByLabelText ( singleRadioGroup , "Charlie" ) . getAttribute ( "data-state" ) ) . toBe (
181
+ "unchecked"
182
+ ) ;
183
+
184
+ const numberInput = getByLabelText (
185
+ page . container ,
186
+ "What is your favorite number?Immutable"
187
+ ) as HTMLInputElement ;
188
+ expect ( numberInput . value ) . toBe ( "48" ) ;
189
+
190
+ const booleanRadioGroup = getByLabelText (
191
+ page . container ,
192
+ "Do you agree with me?Immutable"
193
+ ) ;
194
+ expect ( getByLabelText ( booleanRadioGroup , "Yes" ) . getAttribute ( "data-state" ) ) . toBe (
195
+ "unchecked"
196
+ ) ;
197
+ expect ( getByLabelText ( booleanRadioGroup , "No" ) . getAttribute ( "data-state" ) ) . toBe (
198
+ "checked"
199
+ ) ;
200
+
201
+ const likeItCheckbox = getByLabelText (
202
+ page . container ,
203
+ "Did you like this demo?Immutable"
204
+ ) ;
205
+ expect ( likeItCheckbox . getAttribute ( "data-state" ) ) . toBe ( "checked" ) ;
206
+ } ) ;
145
207
} ) ;
0 commit comments