@@ -2147,5 +2147,123 @@ describe('App', () => {
21472147 fireEvent ( panel , clickEvent )
21482148 expect ( clickEvent . stopPropagation ) . toHaveBeenCalledTimes ( 1 )
21492149 } )
2150+
2151+ describe ( 'Smooth Plots' , ( ) => {
2152+ const waitSetValuePostMessage = ( value : number ) =>
2153+ waitFor (
2154+ ( ) =>
2155+ expect ( mockPostMessage ) . toHaveBeenCalledWith ( {
2156+ payload : { id : smoothId , value } ,
2157+ type : MessageFromWebviewType . SET_SMOOTH_PLOT_VALUE
2158+ } ) ,
2159+ { timeout : 5000 }
2160+ )
2161+ it ( 'should send a message to save the value when a vega panel slider is interacted with' , async ( ) => {
2162+ renderAppWithOptionalData ( { template : withVegaPanels } )
2163+
2164+ const smoothPlot = screen . getByTestId ( `plot_${ smoothId } ` )
2165+ await waitForVega ( smoothPlot )
2166+
2167+ // eslint-disable-next-line testing-library/no-node-access
2168+ const slider = smoothPlot . querySelector (
2169+ '.vega-bindings input[name="smooth"]'
2170+ )
2171+ expect ( slider ) . toBeInTheDocument ( )
2172+
2173+ fireEvent . change ( slider as HTMLInputElement , { target : { value : 0.4 } } )
2174+
2175+ await waitSetValuePostMessage ( 0.4 )
2176+ } )
2177+
2178+ it ( 'should send a message to save the value when a zoomed in plot vega panel slider is interacted with' , async ( ) => {
2179+ renderAppWithOptionalData ( { template : withVegaPanels } )
2180+
2181+ const smoothPlot = within (
2182+ screen . getByTestId ( `plot_${ smoothId } ` )
2183+ ) . getByRole ( 'button' )
2184+ fireEvent . click ( smoothPlot )
2185+
2186+ const popup = screen . getByTestId ( 'zoomed-in-plot' )
2187+ await waitForVega ( popup )
2188+
2189+ // eslint-disable-next-line testing-library/no-node-access
2190+ const slider = popup . querySelector (
2191+ '.vega-bindings input[name="smooth"]'
2192+ )
2193+ expect ( slider ) . toBeInTheDocument ( )
2194+
2195+ fireEvent . change ( slider as HTMLInputElement , { target : { value : 0.4 } } )
2196+
2197+ await waitSetValuePostMessage ( 0.4 )
2198+ } )
2199+
2200+ it ( 'should set a vega panel slider value when given a default value' , async ( ) => {
2201+ renderAppWithOptionalData ( {
2202+ template : { ...withVegaPanels , smoothPlotValues : { [ smoothId ] : 0.6 } }
2203+ } )
2204+
2205+ const smoothPlot = screen . getByTestId ( `plot_${ smoothId } ` )
2206+ await waitForVega ( smoothPlot )
2207+
2208+ // eslint-disable-next-line testing-library/no-node-access
2209+ const slider = smoothPlot . querySelector (
2210+ '.vega-bindings input[name="smooth"]'
2211+ )
2212+ expect ( slider ) . toBeInTheDocument ( )
2213+
2214+ expect ( slider ) . toHaveValue ( '0.6' )
2215+ } )
2216+
2217+ it ( 'should set the zoomed in plot vega panel slider value when given a default value' , async ( ) => {
2218+ renderAppWithOptionalData ( {
2219+ template : { ...withVegaPanels , smoothPlotValues : { [ smoothId ] : 0.6 } }
2220+ } )
2221+
2222+ const smoothPlot = within (
2223+ screen . getByTestId ( `plot_${ smoothId } ` )
2224+ ) . getByRole ( 'button' )
2225+ fireEvent . click ( smoothPlot )
2226+
2227+ const popup = screen . getByTestId ( 'zoomed-in-plot' )
2228+ await waitForVega ( popup )
2229+
2230+ // eslint-disable-next-line testing-library/no-node-access
2231+ const slider = popup . querySelector (
2232+ '.vega-bindings input[name="smooth"]'
2233+ )
2234+ expect ( slider ) . toBeInTheDocument ( )
2235+
2236+ expect ( slider ) . toHaveValue ( '0.6' )
2237+ } )
2238+
2239+ it ( 'should update a vega panel slider value when given a new value' , async ( ) => {
2240+ renderAppWithOptionalData ( {
2241+ template : { ...withVegaPanels }
2242+ } )
2243+
2244+ const smoothPlot = screen . getByTestId ( `plot_${ smoothId } ` )
2245+
2246+ await waitForVega ( smoothPlot )
2247+
2248+ // eslint-disable-next-line testing-library/no-node-access
2249+ const slider = smoothPlot . querySelector (
2250+ '.vega-bindings input[name="smooth"]'
2251+ )
2252+
2253+ expect ( slider ) . toBeInTheDocument ( )
2254+ expect ( slider ) . toHaveValue ( '0.2' )
2255+
2256+ sendSetDataMessage ( {
2257+ template : {
2258+ ...withVegaPanels ,
2259+ smoothPlotValues : { [ smoothId ] : 0.7 }
2260+ }
2261+ } )
2262+
2263+ await waitFor ( ( ) => expect ( slider ) . toHaveValue ( '0.7' ) , {
2264+ timeout : 5000
2265+ } )
2266+ } )
2267+ } )
21502268 } )
21512269} )
0 commit comments