on develop help sign in
Switch to MonadRef
00d3b91Luigy Leon
reflex-dom-core/reflex-dom-core.cabal+1
@@ -173,6 +173,7 @@ test-suite hydration
173 , lens
173 , lens
174 , network
174 , network
175 , random
175 , random
176+ , ref-tf
176 , reflex
177 , reflex
177 , reflex-dom-core
178 , reflex-dom-core
178 , process
179 , process
reflex-dom-core/test/hydration.hs+165−164
@@ -18,6 +18,7 @@ import Control.Monad
18import Control.Monad.Catch
18import Control.Monad.Catch
19import Control.Monad.Fix
19import Control.Monad.Fix
20import Control.Monad.IO.Class
20import Control.Monad.IO.Class
21+import Control.Monad.Ref
21import Data.Constraint (Dict(..))
22import Data.Constraint (Dict(..))
22import Data.Constraint.Extras
23import Data.Constraint.Extras
23import Data.Dependent.Map (DMap)
24import Data.Dependent.Map (DMap)
@@ -27,7 +28,7 @@ import Data.Functor.Identity
27import Data.Functor.Misc
28import Data.Functor.Misc
28import Data.GADT.Compare.TH
29import Data.GADT.Compare.TH
29import Data.GADT.Show.TH
30import Data.GADT.Show.TH
30−import Data.IORef
31+import Data.IORef (IORef)
31import Data.Maybe (fromMaybe, fromJust)
32import Data.Maybe (fromMaybe, fromJust)
32import Data.Proxy
33import Data.Proxy
33import Data.Text (Text)
34import Data.Text (Text)
@@ -175,31 +176,31 @@ tests _selenium = do
175
176
176 describe "element" $ do
177 describe "element" $ do
177 it "works with domEvent Click" $ do
178 it "works with domEvent Click" $ do
178− clickedRef <- newIORef False
179+ clickedRef <- newRef False
179 testWidget' (WD.findElem $ WD.ByTag "div") WD.click $ do
180 testWidget' (WD.findElem $ WD.ByTag "div") WD.click $ do
180 (e, _) <- el' "div" $ text "hello world"
181 (e, _) <- el' "div" $ text "hello world"
181− performEvent_ $ liftIO (writeIORef clickedRef True) <$ domEvent Click e
182+ performEvent_ $ liftIO (writeRef clickedRef True) <$ domEvent Click e
182− clicked <- readIORef clickedRef
183+ clicked <- readRef clickedRef
183 assertEqual "Not clicked" True clicked
184 assertEqual "Not clicked" True clicked
184 it "works with eventFlags stopPropagation" $ do
185 it "works with eventFlags stopPropagation" $ do
185− firstClickedRef <- newIORef False
186+ firstClickedRef <- newRef False
186− secondClickedRef <- newIORef False
187+ secondClickedRef <- newRef False
187 let clickBoth = do
188 let clickBoth = do
188 WD.findElem (WD.ById "first") >>= WD.click
189 WD.findElem (WD.ById "first") >>= WD.click
189 WD.findElem (WD.ById "second") >>= WD.click
190 WD.findElem (WD.ById "second") >>= WD.click
190 testWidget (pure ()) clickBoth $ do
191 testWidget (pure ()) clickBoth $ do
191 (firstDivEl, _) <- el' "div" $ prerender_ (pure ()) $ do
192 (firstDivEl, _) <- el' "div" $ prerender_ (pure ()) $ do
192 void $ elAttr "span" ("id" =: "first") $ text "hello world"
193 void $ elAttr "span" ("id" =: "first") $ text "hello world"
193− performEvent_ $ liftIO (writeIORef firstClickedRef True) <$ domEvent Click firstDivEl
194+ performEvent_ $ liftIO (writeRef firstClickedRef True) <$ domEvent Click firstDivEl
194 (secondDivEl, _) <- el' "div" $ prerender_ (pure ()) $ do
195 (secondDivEl, _) <- el' "div" $ prerender_ (pure ()) $ do
195 let conf :: ElementConfig EventResult (SpiderTimeline Global) GhcjsDomSpace
196 let conf :: ElementConfig EventResult (SpiderTimeline Global) GhcjsDomSpace
196 conf = (def :: ElementConfig EventResult (SpiderTimeline Global) GhcjsDomSpace)
197 conf = (def :: ElementConfig EventResult (SpiderTimeline Global) GhcjsDomSpace)
197 & initialAttributes .~ "id" =: "second"
198 & initialAttributes .~ "id" =: "second"
198 & elementConfig_eventSpec .~ (addEventSpecFlags (Proxy :: Proxy GhcjsDomSpace) Click (\_ -> stopPropagation) def)
199 & elementConfig_eventSpec .~ (addEventSpecFlags (Proxy :: Proxy GhcjsDomSpace) Click (\_ -> stopPropagation) def)
199 void $ element "span" conf $ text "hello world"
200 void $ element "span" conf $ text "hello world"
200− performEvent_ $ liftIO (writeIORef secondClickedRef True) <$ domEvent Click secondDivEl
201+ performEvent_ $ liftIO (writeRef secondClickedRef True) <$ domEvent Click secondDivEl
201− firstClicked <- readIORef firstClickedRef
202+ firstClicked <- readRef firstClickedRef
202− secondClicked <- readIORef secondClickedRef
203+ secondClicked <- readRef secondClickedRef
203 assertEqual "Click propagated when it should have stopped" (True, False) (firstClicked, secondClicked)
204 assertEqual "Click propagated when it should have stopped" (True, False) (firstClicked, secondClicked)
204 it "works with eventFlags preventDefault" $ do
205 it "works with eventFlags preventDefault" $ do
205 let click = do
206 let click = do
@@ -248,7 +249,7 @@ tests _selenium = do
248 describe "inputElement" $ do
249 describe "inputElement" $ do
249 describe "hydration" $ do
250 describe "hydration" $ do
250 it "doesn't wipe user input when switching over" $ do
251 it "doesn't wipe user input when switching over" $ do
251− inputRef <- newIORef ("" :: Text)
252+ inputRef <- newRef ("" :: Text)
252 testWidget'
253 testWidget'
253 (do
254 (do
254 e <- WD.findElem $ WD.ByTag "input"
255 e <- WD.findElem $ WD.ByTag "input"
@@ -258,204 +259,204 @@ tests _selenium = do
258 t <- WD.attr e "value"
259 t <- WD.attr e "value"
259 liftIO $ t `shouldBe` Just "hello world"
260 liftIO $ t `shouldBe` Just "hello world"
260 WD.click <=< WD.findElem $ WD.ByTag "button"
261 WD.click <=< WD.findElem $ WD.ByTag "button"
261− input <- liftIO $ readIORef inputRef
262+ input <- liftIO $ readRef inputRef
262 liftIO $ input `shouldBe` "hello world"
263 liftIO $ input `shouldBe` "hello world"
263 ) $ do
264 ) $ do
264 e <- inputElement def
265 e <- inputElement def
265 click <- button "save"
266 click <- button "save"
266− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
267+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
267 it "captures user input after switchover" $ do
268 it "captures user input after switchover" $ do
268− inputRef <- newIORef ("" :: Text)
269+ inputRef <- newRef ("" :: Text)
269 let checkValue = do
270 let checkValue = do
270 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "input"
271 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "input"
271 WD.click <=< WD.findElem $ WD.ByTag "button"
272 WD.click <=< WD.findElem $ WD.ByTag "button"
272− input <- liftIO $ readIORef inputRef
273+ input <- liftIO $ readRef inputRef
273 liftIO $ input `shouldBe` "hello world"
274 liftIO $ input `shouldBe` "hello world"
274 testWidget (pure ()) checkValue $ do
275 testWidget (pure ()) checkValue $ do
275 e <- inputElement def
276 e <- inputElement def
276 click <- button "save"
277 click <- button "save"
277− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
278+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
278 it "sets focus appropriately" $ do
279 it "sets focus appropriately" $ do
279− focusRef <- newIORef False
280+ focusRef <- newRef False
280 let checkValue = do
281 let checkValue = do
281− liftIO $ readIORef focusRef >>= flip shouldBe False
282+ liftIO $ readRef focusRef >>= flip shouldBe False
282 e <- WD.findElem $ WD.ByTag "input"
283 e <- WD.findElem $ WD.ByTag "input"
283 WD.click e
284 WD.click e
284 liftIO $ threadDelay 100000
285 liftIO $ threadDelay 100000
285− liftIO $ readIORef focusRef >>= flip shouldBe True
286+ liftIO $ readRef focusRef >>= flip shouldBe True
286 testWidget (pure ()) checkValue $ do
287 testWidget (pure ()) checkValue $ do
287 e <- inputElement def
288 e <- inputElement def
288− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_inputElement_hasFocus e)
289+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
289 it "sets focus when focus occurs before hydration" $ do
290 it "sets focus when focus occurs before hydration" $ do
290− focusRef <- newIORef False
291+ focusRef <- newRef False
291 let setup = do
292 let setup = do
292 e <- WD.findElem $ WD.ByTag "input"
293 e <- WD.findElem $ WD.ByTag "input"
293 WD.click e
294 WD.click e
294 hasFocus <- (== e) <$> WD.activeElem
295 hasFocus <- (== e) <$> WD.activeElem
295 liftIO $ do
296 liftIO $ do
296 hasFocus `shouldBe` True
297 hasFocus `shouldBe` True
297− readIORef focusRef >>= flip shouldBe False
298+ readRef focusRef >>= flip shouldBe False
298− check = liftIO $ readIORef focusRef >>= flip shouldBe True
299+ check = liftIO $ readRef focusRef >>= flip shouldBe True
299 testWidget setup check $ do
300 testWidget setup check $ do
300 e <- inputElement def
301 e <- inputElement def
301− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_inputElement_hasFocus e)
302+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
302 it "sets value appropriately" $ do
303 it "sets value appropriately" $ do
303− valueByUIRef <- newIORef ("" :: Text)
304+ valueByUIRef <- newRef ("" :: Text)
304− valueRef <- newIORef ("" :: Text)
305+ valueRef <- newRef ("" :: Text)
305 setValueChan :: Chan Text <- newChan
306 setValueChan :: Chan Text <- newChan
306 let checkValue = do
307 let checkValue = do
307− liftIO $ readIORef valueByUIRef >>= flip shouldBe ""
308+ liftIO $ readRef valueByUIRef >>= flip shouldBe ""
308− liftIO $ readIORef valueRef >>= flip shouldBe ""
309+ liftIO $ readRef valueRef >>= flip shouldBe ""
309 e <- WD.findElem $ WD.ByTag "input"
310 e <- WD.findElem $ WD.ByTag "input"
310 WD.sendKeys "hello" e
311 WD.sendKeys "hello" e
311 liftIO $ do
312 liftIO $ do
312 threadDelay 100000
313 threadDelay 100000
313− readIORef valueByUIRef >>= flip shouldBe "hello"
314+ readRef valueByUIRef >>= flip shouldBe "hello"
314− readIORef valueRef >>= flip shouldBe "hello"
315+ readRef valueRef >>= flip shouldBe "hello"
315 writeChan setValueChan "world"
316 writeChan setValueChan "world"
316 threadDelay 100000
317 threadDelay 100000
317− readIORef valueByUIRef >>= flip shouldBe "hello"
318+ readRef valueByUIRef >>= flip shouldBe "hello"
318− readIORef valueRef >>= flip shouldBe "world"
319+ readRef valueRef >>= flip shouldBe "world"
319 testWidget (pure ()) checkValue $ do
320 testWidget (pure ()) checkValue $ do
320 update <- triggerEventWithChan setValueChan
321 update <- triggerEventWithChan setValueChan
321 e <- inputElement $ def & inputElementConfig_setValue .~ update
322 e <- inputElement $ def & inputElementConfig_setValue .~ update
322− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _inputElement_input e
323+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _inputElement_input e
323− performEvent_ $ liftIO . writeIORef valueRef <$> updated (value e)
324+ performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
324 it "sets checked appropriately" $ do
325 it "sets checked appropriately" $ do
325− checkedByUIRef <- newIORef False
326+ checkedByUIRef <- newRef False
326− checkedRef <- newIORef False
327+ checkedRef <- newRef False
327 setCheckedChan <- newChan
328 setCheckedChan <- newChan
328 let checkValue = do
329 let checkValue = do
329− liftIO $ readIORef checkedByUIRef >>= flip shouldBe False
330+ liftIO $ readRef checkedByUIRef >>= flip shouldBe False
330− liftIO $ readIORef checkedRef >>= flip shouldBe False
331+ liftIO $ readRef checkedRef >>= flip shouldBe False
331 e <- WD.findElem $ WD.ByTag "input"
332 e <- WD.findElem $ WD.ByTag "input"
332 WD.moveToCenter e
333 WD.moveToCenter e
333 WD.click e
334 WD.click e
334 liftIO $ do
335 liftIO $ do
335 threadDelay 100000
336 threadDelay 100000
336− readIORef checkedByUIRef >>= flip shouldBe True
337+ readRef checkedByUIRef >>= flip shouldBe True
337− readIORef checkedRef >>= flip shouldBe True
338+ readRef checkedRef >>= flip shouldBe True
338 writeChan setCheckedChan False
339 writeChan setCheckedChan False
339 threadDelay 100000
340 threadDelay 100000
340− readIORef checkedByUIRef >>= flip shouldBe True
341+ readRef checkedByUIRef >>= flip shouldBe True
341− readIORef checkedRef >>= flip shouldBe False
342+ readRef checkedRef >>= flip shouldBe False
342 testWidget (pure ()) checkValue $ do
343 testWidget (pure ()) checkValue $ do
343 setChecked <- triggerEventWithChan setCheckedChan
344 setChecked <- triggerEventWithChan setCheckedChan
344 e <- inputElement $ def
345 e <- inputElement $ def
345 & initialAttributes .~ "type" =: "checkbox"
346 & initialAttributes .~ "type" =: "checkbox"
346 & inputElementConfig_setChecked .~ setChecked
347 & inputElementConfig_setChecked .~ setChecked
347− performEvent_ $ liftIO . writeIORef checkedByUIRef <$> _inputElement_checkedChange e
348+ performEvent_ $ liftIO . writeRef checkedByUIRef <$> _inputElement_checkedChange e
348− performEvent_ $ liftIO . writeIORef checkedRef <$> updated (_inputElement_checked e)
349+ performEvent_ $ liftIO . writeRef checkedRef <$> updated (_inputElement_checked e)
349 it "captures file uploads" $ do
350 it "captures file uploads" $ do
350− filesRef :: IORef [Text] <- newIORef []
351+ filesRef :: IORef [Text] <- newRef []
351 let uploadFile = do
352 let uploadFile = do
352 e <- WD.findElem $ WD.ByTag "input"
353 e <- WD.findElem $ WD.ByTag "input"
353 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
354 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
354 WD.sendKeys (T.pack path) e
355 WD.sendKeys (T.pack path) e
355 WD.click <=< WD.findElem $ WD.ByTag "button"
356 WD.click <=< WD.findElem $ WD.ByTag "button"
356 liftIO $ removeFile path
357 liftIO $ removeFile path
357− input <- liftIO $ readIORef filesRef
358+ input <- liftIO $ readRef filesRef
358 liftIO $ input `shouldBe` [T.pack $ FilePath.takeFileName path]
359 liftIO $ input `shouldBe` [T.pack $ FilePath.takeFileName path]
359 testWidget (pure ()) uploadFile $ do
360 testWidget (pure ()) uploadFile $ do
360 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
361 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
361 click <- button "save"
362 click <- button "save"
362 prerender_ (pure ()) $ performEvent_ $ ffor (tag (current (_inputElement_files e)) click) $ \fs -> do
363 prerender_ (pure ()) $ performEvent_ $ ffor (tag (current (_inputElement_files e)) click) $ \fs -> do
363 names <- liftJSM $ traverse File.getName fs
364 names <- liftJSM $ traverse File.getName fs
364− liftIO $ writeIORef filesRef names
365+ liftIO $ writeRef filesRef names
365
366
366 describe "hydration/immediate" $ do
367 describe "hydration/immediate" $ do
367 it "captures user input after switchover" $ do
368 it "captures user input after switchover" $ do
368− inputRef :: IORef Text <- newIORef ""
369+ inputRef :: IORef Text <- newRef ""
369 let checkValue = do
370 let checkValue = do
370 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "input"
371 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "input"
371 WD.click <=< WD.findElem $ WD.ByTag "button"
372 WD.click <=< WD.findElem $ WD.ByTag "button"
372− input <- liftIO $ readIORef inputRef
373+ input <- liftIO $ readRef inputRef
373 liftIO $ input `shouldBe` "hello world"
374 liftIO $ input `shouldBe` "hello world"
374 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
375 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
375 e <- inputElement def
376 e <- inputElement def
376 click <- button "save"
377 click <- button "save"
377− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
378+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
378 it "sets focus appropriately" $ do
379 it "sets focus appropriately" $ do
379− focusRef <- newIORef False
380+ focusRef <- newRef False
380 let checkValue = do
381 let checkValue = do
381− liftIO $ readIORef focusRef >>= flip shouldBe False
382+ liftIO $ readRef focusRef >>= flip shouldBe False
382 e <- WD.findElem $ WD.ByTag "input"
383 e <- WD.findElem $ WD.ByTag "input"
383 WD.click e
384 WD.click e
384 liftIO $ threadDelay 100000
385 liftIO $ threadDelay 100000
385− liftIO $ readIORef focusRef >>= flip shouldBe True
386+ liftIO $ readRef focusRef >>= flip shouldBe True
386 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
387 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
387 e <- inputElement def
388 e <- inputElement def
388− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_inputElement_hasFocus e)
389+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
389 it "sets value appropriately" $ do
390 it "sets value appropriately" $ do
390− valueByUIRef :: IORef Text <- newIORef ""
391+ valueByUIRef :: IORef Text <- newRef ""
391− valueRef :: IORef Text <- newIORef ""
392+ valueRef :: IORef Text <- newRef ""
392 setValueChan :: Chan Text <- newChan
393 setValueChan :: Chan Text <- newChan
393 let checkValue = do
394 let checkValue = do
394− liftIO $ readIORef valueByUIRef >>= flip shouldBe ""
395+ liftIO $ readRef valueByUIRef >>= flip shouldBe ""
395− liftIO $ readIORef valueRef >>= flip shouldBe ""
396+ liftIO $ readRef valueRef >>= flip shouldBe ""
396 e <- WD.findElem $ WD.ByTag "input"
397 e <- WD.findElem $ WD.ByTag "input"
397 WD.sendKeys "hello" e
398 WD.sendKeys "hello" e
398 liftIO $ do
399 liftIO $ do
399 threadDelay 100000
400 threadDelay 100000
400− readIORef valueByUIRef >>= flip shouldBe "hello"
401+ readRef valueByUIRef >>= flip shouldBe "hello"
401− readIORef valueRef >>= flip shouldBe "hello"
402+ readRef valueRef >>= flip shouldBe "hello"
402 writeChan setValueChan "world"
403 writeChan setValueChan "world"
403 threadDelay 100000
404 threadDelay 100000
404− readIORef valueByUIRef >>= flip shouldBe "hello"
405+ readRef valueByUIRef >>= flip shouldBe "hello"
405− readIORef valueRef >>= flip shouldBe "world"
406+ readRef valueRef >>= flip shouldBe "world"
406 testWidget (pure ()) checkValue $ do
407 testWidget (pure ()) checkValue $ do
407 update <- triggerEventWithChan setValueChan
408 update <- triggerEventWithChan setValueChan
408 prerender_ (pure ()) $ do
409 prerender_ (pure ()) $ do
409 e <- inputElement $ def & inputElementConfig_setValue .~ update
410 e <- inputElement $ def & inputElementConfig_setValue .~ update
410− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _inputElement_input e
411+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _inputElement_input e
411− performEvent_ $ liftIO . writeIORef valueRef <$> updated (value e)
412+ performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
412 it "sets checked appropriately" $ do
413 it "sets checked appropriately" $ do
413− checkedByUIRef <- newIORef False
414+ checkedByUIRef <- newRef False
414− checkedRef <- newIORef False
415+ checkedRef <- newRef False
415 setCheckedChan <- newChan
416 setCheckedChan <- newChan
416 let checkValue = do
417 let checkValue = do
417− liftIO $ readIORef checkedByUIRef >>= flip shouldBe False
418+ liftIO $ readRef checkedByUIRef >>= flip shouldBe False
418− liftIO $ readIORef checkedRef >>= flip shouldBe False
419+ liftIO $ readRef checkedRef >>= flip shouldBe False
419 e <- WD.findElem $ WD.ByTag "input"
420 e <- WD.findElem $ WD.ByTag "input"
420 WD.moveToCenter e
421 WD.moveToCenter e
421 WD.click e
422 WD.click e
422 liftIO $ do
423 liftIO $ do
423 threadDelay 100000
424 threadDelay 100000
424− readIORef checkedByUIRef >>= flip shouldBe True
425+ readRef checkedByUIRef >>= flip shouldBe True
425− readIORef checkedRef >>= flip shouldBe True
426+ readRef checkedRef >>= flip shouldBe True
426 writeChan setCheckedChan False
427 writeChan setCheckedChan False
427 threadDelay 100000
428 threadDelay 100000
428− readIORef checkedByUIRef >>= flip shouldBe True
429+ readRef checkedByUIRef >>= flip shouldBe True
429− readIORef checkedRef >>= flip shouldBe False
430+ readRef checkedRef >>= flip shouldBe False
430 testWidget (pure ()) checkValue $ do
431 testWidget (pure ()) checkValue $ do
431 setChecked <- triggerEventWithChan setCheckedChan
432 setChecked <- triggerEventWithChan setCheckedChan
432 prerender_ (pure ()) $ do
433 prerender_ (pure ()) $ do
433 e <- inputElement $ def
434 e <- inputElement $ def
434 & initialAttributes .~ "type" =: "checkbox"
435 & initialAttributes .~ "type" =: "checkbox"
435 & inputElementConfig_setChecked .~ setChecked
436 & inputElementConfig_setChecked .~ setChecked
436− performEvent_ $ liftIO . writeIORef checkedByUIRef <$> _inputElement_checkedChange e
437+ performEvent_ $ liftIO . writeRef checkedByUIRef <$> _inputElement_checkedChange e
437− performEvent_ $ liftIO . writeIORef checkedRef <$> updated (_inputElement_checked e)
438+ performEvent_ $ liftIO . writeRef checkedRef <$> updated (_inputElement_checked e)
438 it "captures file uploads" $ do
439 it "captures file uploads" $ do
439− filesRef :: IORef [Text] <- newIORef []
440+ filesRef :: IORef [Text] <- newRef []
440 let uploadFile = do
441 let uploadFile = do
441 e <- WD.findElem $ WD.ByTag "input"
442 e <- WD.findElem $ WD.ByTag "input"
442 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
443 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
443 WD.sendKeys (T.pack path) e
444 WD.sendKeys (T.pack path) e
444 WD.click <=< WD.findElem $ WD.ByTag "button"
445 WD.click <=< WD.findElem $ WD.ByTag "button"
445 liftIO $ removeFile path
446 liftIO $ removeFile path
446− input <- liftIO $ readIORef filesRef
447+ input <- liftIO $ readRef filesRef
447 liftIO $ input `shouldBe` [T.pack $ FilePath.takeFileName path]
448 liftIO $ input `shouldBe` [T.pack $ FilePath.takeFileName path]
448 testWidget (pure ()) uploadFile $ prerender_ (pure ()) $ do
449 testWidget (pure ()) uploadFile $ prerender_ (pure ()) $ do
449 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
450 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
450 click <- button "save"
451 click <- button "save"
451 performEvent_ $ ffor (tag (current (_inputElement_files e)) click) $ \fs -> do
452 performEvent_ $ ffor (tag (current (_inputElement_files e)) click) $ \fs -> do
452 names <- liftJSM $ traverse File.getName fs
453 names <- liftJSM $ traverse File.getName fs
453− liftIO $ writeIORef filesRef names
454+ liftIO $ writeRef filesRef names
454
455
455 describe "textAreaElement" $ do
456 describe "textAreaElement" $ do
456 describe "hydration" $ do
457 describe "hydration" $ do
457 it "doesn't wipe user input when switching over" $ do
458 it "doesn't wipe user input when switching over" $ do
458− inputRef <- newIORef ("" :: Text)
459+ inputRef <- newRef ("" :: Text)
459 testWidget'
460 testWidget'
460 (do
461 (do
461 e <- WD.findElem $ WD.ByTag "textarea"
462 e <- WD.findElem $ WD.ByTag "textarea"
@@ -465,116 +466,116 @@ tests _selenium = do
465 t <- WD.attr e "value"
466 t <- WD.attr e "value"
466 liftIO $ t `shouldBe` Just "hello world"
467 liftIO $ t `shouldBe` Just "hello world"
467 WD.click <=< WD.findElem $ WD.ByTag "button"
468 WD.click <=< WD.findElem $ WD.ByTag "button"
468− input <- liftIO $ readIORef inputRef
469+ input <- liftIO $ readRef inputRef
469 liftIO $ input `shouldBe` "hello world"
470 liftIO $ input `shouldBe` "hello world"
470 ) $ do
471 ) $ do
471 e <- textAreaElement def
472 e <- textAreaElement def
472 click <- button "save"
473 click <- button "save"
473− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
474+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
474 it "captures user input after switchover" $ do
475 it "captures user input after switchover" $ do
475− inputRef <- newIORef ("" :: Text)
476+ inputRef <- newRef ("" :: Text)
476 let checkValue = do
477 let checkValue = do
477 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "textarea"
478 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "textarea"
478 WD.click <=< WD.findElem $ WD.ByTag "button"
479 WD.click <=< WD.findElem $ WD.ByTag "button"
479− input <- liftIO $ readIORef inputRef
480+ input <- liftIO $ readRef inputRef
480 liftIO $ input `shouldBe` "hello world"
481 liftIO $ input `shouldBe` "hello world"
481 testWidget (pure ()) checkValue $ do
482 testWidget (pure ()) checkValue $ do
482 e <- textAreaElement def
483 e <- textAreaElement def
483 click <- button "save"
484 click <- button "save"
484− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
485+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
485 it "sets focus appropriately" $ do
486 it "sets focus appropriately" $ do
486− focusRef <- newIORef False
487+ focusRef <- newRef False
487 let checkValue = do
488 let checkValue = do
488− liftIO $ readIORef focusRef >>= flip shouldBe False
489+ liftIO $ readRef focusRef >>= flip shouldBe False
489 e <- WD.findElem $ WD.ByTag "textarea"
490 e <- WD.findElem $ WD.ByTag "textarea"
490 WD.click e
491 WD.click e
491 liftIO $ threadDelay 100000
492 liftIO $ threadDelay 100000
492− liftIO $ readIORef focusRef >>= flip shouldBe True
493+ liftIO $ readRef focusRef >>= flip shouldBe True
493 testWidget (pure ()) checkValue $ do
494 testWidget (pure ()) checkValue $ do
494 e <- textAreaElement def
495 e <- textAreaElement def
495− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_textAreaElement_hasFocus e)
496+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
496 it "sets focus when focus occurs before hydration" $ do
497 it "sets focus when focus occurs before hydration" $ do
497− focusRef <- newIORef False
498+ focusRef <- newRef False
498 let setup = do
499 let setup = do
499 e <- WD.findElem $ WD.ByTag "textarea"
500 e <- WD.findElem $ WD.ByTag "textarea"
500 WD.click e
501 WD.click e
501 hasFocus <- (== e) <$> WD.activeElem
502 hasFocus <- (== e) <$> WD.activeElem
502 liftIO $ do
503 liftIO $ do
503 hasFocus `shouldBe` True
504 hasFocus `shouldBe` True
504− readIORef focusRef >>= flip shouldBe False
505+ readRef focusRef >>= flip shouldBe False
505− check = liftIO $ readIORef focusRef >>= flip shouldBe True
506+ check = liftIO $ readRef focusRef >>= flip shouldBe True
506 testWidget setup check $ do
507 testWidget setup check $ do
507 e <- textAreaElement def
508 e <- textAreaElement def
508− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_textAreaElement_hasFocus e)
509+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
509 it "sets value appropriately" $ do
510 it "sets value appropriately" $ do
510− valueByUIRef <- newIORef ("" :: Text)
511+ valueByUIRef <- newRef ("" :: Text)
511− valueRef <- newIORef ("" :: Text)
512+ valueRef <- newRef ("" :: Text)
512 setValueChan :: Chan Text <- newChan
513 setValueChan :: Chan Text <- newChan
513 let checkValue = do
514 let checkValue = do
514− liftIO $ readIORef valueByUIRef >>= flip shouldBe ""
515+ liftIO $ readRef valueByUIRef >>= flip shouldBe ""
515− liftIO $ readIORef valueRef >>= flip shouldBe ""
516+ liftIO $ readRef valueRef >>= flip shouldBe ""
516 e <- WD.findElem $ WD.ByTag "textarea"
517 e <- WD.findElem $ WD.ByTag "textarea"
517 WD.sendKeys "hello" e
518 WD.sendKeys "hello" e
518 liftIO $ do
519 liftIO $ do
519 threadDelay 100000
520 threadDelay 100000
520− readIORef valueByUIRef >>= flip shouldBe "hello"
521+ readRef valueByUIRef >>= flip shouldBe "hello"
521− readIORef valueRef >>= flip shouldBe "hello"
522+ readRef valueRef >>= flip shouldBe "hello"
522 writeChan setValueChan "world"
523 writeChan setValueChan "world"
523 threadDelay 100000
524 threadDelay 100000
524− readIORef valueByUIRef >>= flip shouldBe "hello"
525+ readRef valueByUIRef >>= flip shouldBe "hello"
525− readIORef valueRef >>= flip shouldBe "world"
526+ readRef valueRef >>= flip shouldBe "world"
526 testWidget (pure ()) checkValue $ do
527 testWidget (pure ()) checkValue $ do
527 setValue' <- triggerEventWithChan setValueChan
528 setValue' <- triggerEventWithChan setValueChan
528 e <- textAreaElement $ def { _textAreaElementConfig_setValue = Just setValue' }
529 e <- textAreaElement $ def { _textAreaElementConfig_setValue = Just setValue' }
529− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _textAreaElement_input e
530+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _textAreaElement_input e
530− performEvent_ $ liftIO . writeIORef valueRef <$> updated (value e)
531+ performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
531
532
532 describe "hydration/immediate" $ do
533 describe "hydration/immediate" $ do
533 it "captures user input after switchover" $ do
534 it "captures user input after switchover" $ do
534− inputRef :: IORef Text <- newIORef ""
535+ inputRef :: IORef Text <- newRef ""
535 let checkValue = do
536 let checkValue = do
536 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "textarea"
537 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "textarea"
537 WD.click <=< WD.findElem $ WD.ByTag "button"
538 WD.click <=< WD.findElem $ WD.ByTag "button"
538− input <- liftIO $ readIORef inputRef
539+ input <- liftIO $ readRef inputRef
539 liftIO $ input `shouldBe` "hello world"
540 liftIO $ input `shouldBe` "hello world"
540 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
541 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
541 e <- textAreaElement def
542 e <- textAreaElement def
542 click <- button "save"
543 click <- button "save"
543− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
544+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
544 it "sets focus appropriately" $ do
545 it "sets focus appropriately" $ do
545− focusRef <- newIORef False
546+ focusRef <- newRef False
546 let checkValue = do
547 let checkValue = do
547− liftIO $ readIORef focusRef >>= flip shouldBe False
548+ liftIO $ readRef focusRef >>= flip shouldBe False
548 e <- WD.findElem $ WD.ByTag "textarea"
549 e <- WD.findElem $ WD.ByTag "textarea"
549 WD.click e
550 WD.click e
550 liftIO $ threadDelay 100000
551 liftIO $ threadDelay 100000
551− liftIO $ readIORef focusRef >>= flip shouldBe True
552+ liftIO $ readRef focusRef >>= flip shouldBe True
552 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
553 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
553 e <- textAreaElement def
554 e <- textAreaElement def
554− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_textAreaElement_hasFocus e)
555+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
555 it "sets value appropriately" $ do
556 it "sets value appropriately" $ do
556− valueByUIRef :: IORef Text <- newIORef ""
557+ valueByUIRef :: IORef Text <- newRef ""
557− valueRef :: IORef Text <- newIORef ""
558+ valueRef :: IORef Text <- newRef ""
558 setValueChan :: Chan Text <- newChan
559 setValueChan :: Chan Text <- newChan
559 let checkValue = do
560 let checkValue = do
560− liftIO $ readIORef valueByUIRef >>= flip shouldBe ""
561+ liftIO $ readRef valueByUIRef >>= flip shouldBe ""
561− liftIO $ readIORef valueRef >>= flip shouldBe ""
562+ liftIO $ readRef valueRef >>= flip shouldBe ""
562 e <- WD.findElem $ WD.ByTag "textarea"
563 e <- WD.findElem $ WD.ByTag "textarea"
563 WD.sendKeys "hello" e
564 WD.sendKeys "hello" e
564 liftIO $ do
565 liftIO $ do
565 threadDelay 100000
566 threadDelay 100000
566− readIORef valueByUIRef >>= flip shouldBe "hello"
567+ readRef valueByUIRef >>= flip shouldBe "hello"
567− readIORef valueRef >>= flip shouldBe "hello"
568+ readRef valueRef >>= flip shouldBe "hello"
568 writeChan setValueChan "world"
569 writeChan setValueChan "world"
569 threadDelay 100000
570 threadDelay 100000
570− readIORef valueByUIRef >>= flip shouldBe "hello"
571+ readRef valueByUIRef >>= flip shouldBe "hello"
571− readIORef valueRef >>= flip shouldBe "world"
572+ readRef valueRef >>= flip shouldBe "world"
572 testWidget (pure ()) checkValue $ do
573 testWidget (pure ()) checkValue $ do
573 setValue' <- triggerEventWithChan setValueChan
574 setValue' <- triggerEventWithChan setValueChan
574 prerender_ (pure ()) $ do
575 prerender_ (pure ()) $ do
575 e <- textAreaElement $ def { _textAreaElementConfig_setValue = Just setValue' }
576 e <- textAreaElement $ def { _textAreaElementConfig_setValue = Just setValue' }
576− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _textAreaElement_input e
577+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _textAreaElement_input e
577− performEvent_ $ liftIO . writeIORef valueRef <$> updated (value e)
578+ performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
578
579
579 describe "selectElement" $ do
580 describe "selectElement" $ do
580 let options :: DomBuilder t m => m ()
581 let options :: DomBuilder t m => m ()
@@ -584,7 +585,7 @@ tests _selenium = do
584 elAttr "option" ("value" =: "three" <> "id" =: "three") $ text "three"
585 elAttr "option" ("value" =: "three" <> "id" =: "three") $ text "three"
585 describe "hydration" $ do
586 describe "hydration" $ do
586 it "sets initial value correctly" $ do
587 it "sets initial value correctly" $ do
587− inputRef <- newIORef ("" :: Text)
588+ inputRef <- newRef ("" :: Text)
588 let setup = do
589 let setup = do
589 e <- WD.findElem $ WD.ByTag "select"
590 e <- WD.findElem $ WD.ByTag "select"
590 assertAttr e "value" (Just "three")
591 assertAttr e "value" (Just "three")
@@ -592,120 +593,120 @@ tests _selenium = do
592 pure e
593 pure e
593 check e = do
594 check e = do
594 assertAttr e "value" (Just "two")
595 assertAttr e "value" (Just "two")
595− liftIO $ readIORef inputRef >>= (`shouldBe` "three")
596+ liftIO $ readRef inputRef >>= (`shouldBe` "three")
596 WD.click <=< WD.findElem $ WD.ByTag "button"
597 WD.click <=< WD.findElem $ WD.ByTag "button"
597 assertAttr e "value" (Just "two")
598 assertAttr e "value" (Just "two")
598− liftIO $ readIORef inputRef >>= (`shouldBe` "two")
599+ liftIO $ readRef inputRef >>= (`shouldBe` "two")
599 testWidget' setup check $ do
600 testWidget' setup check $ do
600 (e, ()) <- selectElement (def { _selectElementConfig_initialValue = "three" }) options
601 (e, ()) <- selectElement (def { _selectElementConfig_initialValue = "three" }) options
601 click <- button "save"
602 click <- button "save"
602− liftIO . writeIORef inputRef <=< sample $ current $ _selectElement_value e
603+ liftIO . writeRef inputRef <=< sample $ current $ _selectElement_value e
603− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (_selectElement_value e)) click
604+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (_selectElement_value e)) click
604 it "captures user input after switchover" $ do
605 it "captures user input after switchover" $ do
605− inputRef <- newIORef ("" :: Text)
606+ inputRef <- newRef ("" :: Text)
606 let checkValue = do
607 let checkValue = do
607 e <- WD.findElem $ WD.ByTag "select"
608 e <- WD.findElem $ WD.ByTag "select"
608 assertAttr e "value" (Just "one")
609 assertAttr e "value" (Just "one")
609 WD.click <=< WD.findElem $ WD.ById "two"
610 WD.click <=< WD.findElem $ WD.ById "two"
610 assertAttr e "value" (Just "two")
611 assertAttr e "value" (Just "two")
611 WD.click <=< WD.findElem $ WD.ByTag "button"
612 WD.click <=< WD.findElem $ WD.ByTag "button"
612− liftIO $ readIORef inputRef >>= (`shouldBe` "two")
613+ liftIO $ readRef inputRef >>= (`shouldBe` "two")
613 testWidget (pure ()) checkValue $ do
614 testWidget (pure ()) checkValue $ do
614 (e, ()) <- selectElement def options
615 (e, ()) <- selectElement def options
615 click <- button "save"
616 click <- button "save"
616− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (_selectElement_value e)) click
617+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (_selectElement_value e)) click
617 it "sets focus appropriately" $ do
618 it "sets focus appropriately" $ do
618− focusRef <- newIORef False
619+ focusRef <- newRef False
619 let checkValue = do
620 let checkValue = do
620− liftIO $ readIORef focusRef >>= flip shouldBe False
621+ liftIO $ readRef focusRef >>= flip shouldBe False
621 e <- WD.findElem $ WD.ByTag "select"
622 e <- WD.findElem $ WD.ByTag "select"
622 WD.click e
623 WD.click e
623 liftIO $ threadDelay 100000
624 liftIO $ threadDelay 100000
624− liftIO $ readIORef focusRef >>= flip shouldBe True
625+ liftIO $ readRef focusRef >>= flip shouldBe True
625 testWidget (pure ()) checkValue $ do
626 testWidget (pure ()) checkValue $ do
626 (e, ()) <- selectElement def options
627 (e, ()) <- selectElement def options
627− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_selectElement_hasFocus e)
628+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
628 it "sets focus when focus occurs before hydration" $ do
629 it "sets focus when focus occurs before hydration" $ do
629− focusRef <- newIORef False
630+ focusRef <- newRef False
630 let setup = do
631 let setup = do
631 e <- WD.findElem $ WD.ByTag "select"
632 e <- WD.findElem $ WD.ByTag "select"
632 WD.click e
633 WD.click e
633 hasFocus <- (== e) <$> WD.activeElem
634 hasFocus <- (== e) <$> WD.activeElem
634 liftIO $ do
635 liftIO $ do
635 hasFocus `shouldBe` True
636 hasFocus `shouldBe` True
636− readIORef focusRef >>= flip shouldBe False
637+ readRef focusRef >>= flip shouldBe False
637− check = liftIO $ readIORef focusRef >>= flip shouldBe True
638+ check = liftIO $ readRef focusRef >>= flip shouldBe True
638 testWidget setup check $ do
639 testWidget setup check $ do
639 (e, ()) <- selectElement def options
640 (e, ()) <- selectElement def options
640− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_selectElement_hasFocus e)
641+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
641 it "sets value appropriately" $ do
642 it "sets value appropriately" $ do
642− valueByUIRef <- newIORef ("" :: Text)
643+ valueByUIRef <- newRef ("" :: Text)
643− valueRef <- newIORef ("" :: Text)
644+ valueRef <- newRef ("" :: Text)
644 setValueChan :: Chan Text <- newChan
645 setValueChan :: Chan Text <- newChan
645 let checkValue = do
646 let checkValue = do
646 e <- WD.findElem $ WD.ByTag "select"
647 e <- WD.findElem $ WD.ByTag "select"
647 assertAttr e "value" (Just "one")
648 assertAttr e "value" (Just "one")
648− liftIO $ readIORef valueByUIRef >>= flip shouldBe "one"
649+ liftIO $ readRef valueByUIRef >>= flip shouldBe "one"
649− liftIO $ readIORef valueRef >>= flip shouldBe "one"
650+ liftIO $ readRef valueRef >>= flip shouldBe "one"
650 WD.click <=< WD.findElem $ WD.ById "two"
651 WD.click <=< WD.findElem $ WD.ById "two"
651 liftIO $ do
652 liftIO $ do
652 threadDelay 100000
653 threadDelay 100000
653− readIORef valueByUIRef >>= flip shouldBe "two"
654+ readRef valueByUIRef >>= flip shouldBe "two"
654− readIORef valueRef >>= flip shouldBe "two"
655+ readRef valueRef >>= flip shouldBe "two"
655 writeChan setValueChan "three"
656 writeChan setValueChan "three"
656 threadDelay 100000
657 threadDelay 100000
657− readIORef valueByUIRef >>= flip shouldBe "two"
658+ readRef valueByUIRef >>= flip shouldBe "two"
658− readIORef valueRef >>= flip shouldBe "three"
659+ readRef valueRef >>= flip shouldBe "three"
659 testWidget (pure ()) checkValue $ do
660 testWidget (pure ()) checkValue $ do
660 setValue' <- triggerEventWithChan setValueChan
661 setValue' <- triggerEventWithChan setValueChan
661 (e, ()) <- selectElement def { _selectElementConfig_setValue = Just setValue' } options
662 (e, ()) <- selectElement def { _selectElementConfig_setValue = Just setValue' } options
662− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _selectElement_change e
663+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _selectElement_change e
663− performEvent_ $ liftIO . writeIORef valueRef <$> updated (_selectElement_value e)
664+ performEvent_ $ liftIO . writeRef valueRef <$> updated (_selectElement_value e)
664
665
665 describe "hydration/immediate" $ do
666 describe "hydration/immediate" $ do
666 it "captures user input after switchover" $ do
667 it "captures user input after switchover" $ do
667− inputRef :: IORef Text <- newIORef ""
668+ inputRef :: IORef Text <- newRef ""
668 let checkValue = do
669 let checkValue = do
669 WD.click <=< WD.findElem $ WD.ById "two"
670 WD.click <=< WD.findElem $ WD.ById "two"
670 WD.click <=< WD.findElem $ WD.ByTag "button"
671 WD.click <=< WD.findElem $ WD.ByTag "button"
671− liftIO $ readIORef inputRef >>= flip shouldBe "two"
672+ liftIO $ readRef inputRef >>= flip shouldBe "two"
672 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
673 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
673 (e, ()) <- selectElement def options
674 (e, ()) <- selectElement def options
674 click <- button "save"
675 click <- button "save"
675− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (_selectElement_value e)) click
676+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (_selectElement_value e)) click
676 it "sets focus appropriately" $ do
677 it "sets focus appropriately" $ do
677− focusRef <- newIORef False
678+ focusRef <- newRef False
678 let checkValue = do
679 let checkValue = do
679− liftIO $ readIORef focusRef >>= flip shouldBe False
680+ liftIO $ readRef focusRef >>= flip shouldBe False
680 e <- WD.findElem $ WD.ByTag "select"
681 e <- WD.findElem $ WD.ByTag "select"
681 WD.click e
682 WD.click e
682 liftIO $ threadDelay 100000
683 liftIO $ threadDelay 100000
683− liftIO $ readIORef focusRef >>= flip shouldBe True
684+ liftIO $ readRef focusRef >>= flip shouldBe True
684 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
685 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
685 (e, ()) <- selectElement def options
686 (e, ()) <- selectElement def options
686− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_selectElement_hasFocus e)
687+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
687 it "sets value appropriately" $ do
688 it "sets value appropriately" $ do
688− valueByUIRef :: IORef Text <- newIORef ""
689+ valueByUIRef :: IORef Text <- newRef ""
689− valueRef :: IORef Text <- newIORef ""
690+ valueRef :: IORef Text <- newRef ""
690 setValueChan :: Chan Text <- newChan
691 setValueChan :: Chan Text <- newChan
691 let checkValue = do
692 let checkValue = do
692− liftIO $ readIORef valueByUIRef >>= flip shouldBe "one"
693+ liftIO $ readRef valueByUIRef >>= flip shouldBe "one"
693− liftIO $ readIORef valueRef >>= flip shouldBe "one"
694+ liftIO $ readRef valueRef >>= flip shouldBe "one"
694 WD.click <=< WD.findElem $ WD.ById "two"
695 WD.click <=< WD.findElem $ WD.ById "two"
695 liftIO $ do
696 liftIO $ do
696 threadDelay 100000
697 threadDelay 100000
697− readIORef valueByUIRef >>= flip shouldBe "two"
698+ readRef valueByUIRef >>= flip shouldBe "two"
698− readIORef valueRef >>= flip shouldBe "two"
699+ readRef valueRef >>= flip shouldBe "two"
699 writeChan setValueChan "three"
700 writeChan setValueChan "three"
700 threadDelay 100000
701 threadDelay 100000
701− readIORef valueByUIRef >>= flip shouldBe "two"
702+ readRef valueByUIRef >>= flip shouldBe "two"
702− readIORef valueRef >>= flip shouldBe "three"
703+ readRef valueRef >>= flip shouldBe "three"
703 testWidget (pure ()) checkValue $ do
704 testWidget (pure ()) checkValue $ do
704 setValue' <- triggerEventWithChan setValueChan
705 setValue' <- triggerEventWithChan setValueChan
705 prerender_ (pure ()) $ do
706 prerender_ (pure ()) $ do
706 (e, ()) <- selectElement def { _selectElementConfig_setValue = Just setValue' } options
707 (e, ()) <- selectElement def { _selectElementConfig_setValue = Just setValue' } options
707− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _selectElement_change e
708+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _selectElement_change e
708− performEvent_ $ liftIO . writeIORef valueRef <$> updated (_selectElement_value e)
709+ performEvent_ $ liftIO . writeRef valueRef <$> updated (_selectElement_value e)
709
710
710 describe "prerender" $ do
711 describe "prerender" $ do
711 it "works in simple case" $ do
712 it "works in simple case" $ do
@@ -763,9 +764,9 @@ tests _selenium = do
763 it "can't exploit IO to break hydration" $ do
764 it "can't exploit IO to break hydration" $ do
764 let static = shouldContainText "Initial" =<< WD.findElem (WD.ByTag "body")
765 let static = shouldContainText "Initial" =<< WD.findElem (WD.ByTag "body")
765 testWidgetStatic static $ void $ do
766 testWidgetStatic static $ void $ do
766− ref <- liftIO $ newIORef "Initial"
767+ ref <- liftIO $ newRef "Initial"
767− prerender_ (pure ()) (liftIO $ writeIORef ref "Client")
768+ prerender_ (pure ()) (liftIO $ writeRef ref "Client")
768− text <=< liftIO $ readIORef ref
769+ text <=< liftIO $ readRef ref
769 -- As above, so below
770 -- As above, so below
770 it "can't exploit triggerEvent to break hydration" $ do
771 it "can't exploit triggerEvent to break hydration" $ do
771 let static = shouldContainText "Initial" =<< WD.findElem (WD.ByTag "body")
772 let static = shouldContainText "Initial" =<< WD.findElem (WD.ByTag "body")