@@ -16,22 +16,27 @@ import { Preview } from "@/client/Preview";
1616import type { ParameterWithSource } from "@/gen/types" ;
1717import {
1818 defaultExampleParameters ,
19+ defaultExampleParamterValues ,
1920 formTypesExampleParameters ,
2021} from "@/test-data/preview" ;
2122import { mockUsers } from "@/user" ;
2223
2324type TestAppProps = {
2425 parameters : ParameterWithSource [ ] ;
26+ parameterValues ?: Record < string , string > ;
2527} ;
2628
27- const TestPreview : FC < TestAppProps > = ( { parameters } ) => {
29+ const TestPreview : FC < TestAppProps > = ( {
30+ parameters,
31+ parameterValues = { } ,
32+ } ) => {
2833 return (
2934 < PanelGroup direction = "horizontal" >
3035 < Preview
3136 wasmLoadState = "loaded"
3237 isDebouncing = { false }
3338 onDownloadOutput = { ( ) => null }
34- parameterValues = { { } }
39+ parameterValues = { parameterValues }
3540 setParameterValues = { ( ) => null }
3641 output = { null }
3742 parameters = { parameters }
@@ -44,20 +49,25 @@ const TestPreview: FC<TestAppProps> = ({ parameters }) => {
4449 ) ;
4550} ;
4651
47- const router = ( parameters : ParameterWithSource [ ] ) =>
52+ const router = ( parameters : ParameterWithSource [ ] , parameterValues = { } ) =>
4853 createBrowserRouter ( [
4954 {
5055 path : "*" ,
51- Component : ( ) => < TestPreview parameters = { parameters } /> ,
56+ Component : ( ) => (
57+ < TestPreview
58+ parameters = { parameters }
59+ parameterValues = { parameterValues }
60+ />
61+ ) ,
5262 } ,
5363 ] ) ;
5464
55- const TestApp : FC < TestAppProps > = ( { parameters } ) => {
65+ const TestApp : FC < TestAppProps > = ( { parameters, parameterValues } ) => {
5666 return (
5767 < ThemeProvider >
5868 < TooltipProvider >
5969 < EditorProvider >
60- < RouterProvider router = { router ( parameters ) } />
70+ < RouterProvider router = { router ( parameters , parameterValues ) } />
6171 </ EditorProvider >
6272 </ TooltipProvider >
6373 </ ThemeProvider >
@@ -73,8 +83,7 @@ describe("Preview - Rendering", () => {
7383 const page = render ( < TestApp parameters = { [ ] } /> ) ;
7484
7585 expect ( findByTestId ( page . container , "preview-empty-state" ) ) ;
76-
77- } )
86+ } ) ;
7887
7988 it ( "should render the default example as expected" , async ( ) => {
8089 const page = render ( < TestApp parameters = { defaultExampleParameters } /> ) ;
@@ -87,7 +96,7 @@ describe("Preview - Rendering", () => {
8796 ) ;
8897 } ) ;
8998
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 ( ) => {
91100 const page = render ( < TestApp parameters = { formTypesExampleParameters } /> ) ;
92101
93102 const formTypeSelects = queryAllByLabelText (
@@ -142,4 +151,57 @@ describe("Preview - Rendering", () => {
142151 ) ;
143152 expect ( checkbox . getAttribute ( "data-state" ) ) . toBe ( "unchecked" ) ;
144153 } ) ;
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+ } ) ;
145207} ) ;
0 commit comments