on develop help sign in
Switch to MonadRef
commit00d3b91bc98ac5ca759a8a8e5a13facbbb1ba48d authorLuigy Leon <luigy.leon@obsidian.systems> dateSat 15 Dec 2018, 16:08 (8 years ago) parentcf6d925
2 files changed+166−164
reflex-dom-core/reflex-dom-core.cabal+1 reflex-dom-core/test/hydration.hs+165−164
reflex-dom-core/reflex-dom-core.cabal+1
@@ -173,6 +173,7 @@ test-suite hydration
173173 , lens
174174 , network
175175 , random
176+ , ref-tf
176177 , reflex
177178 , reflex-dom-core
178179 , process
reflex-dom-core/test/hydration.hs+165−164
@@ -18,6 +18,7 @@ import Control.Monad
1818import Control.Monad.Catch
1919import Control.Monad.Fix
2020import Control.Monad.IO.Class
21+import Control.Monad.Ref
2122import Data.Constraint (Dict(..))
2223import Data.Constraint.Extras
2324import Data.Dependent.Map (DMap)
@@ -27,7 +28,7 @@ import Data.Functor.Identity
2728import Data.Functor.Misc
2829import Data.GADT.Compare.TH
2930import Data.GADT.Show.TH
30−import Data.IORef
31+import Data.IORef (IORef)
3132import Data.Maybe (fromMaybe, fromJust)
3233import Data.Proxy
3334import Data.Text (Text)
@@ -175,31 +176,31 @@ tests _selenium = do
175176
176177 describe "element" $ do
177178 it "works with domEvent Click" $ do
178− clickedRef <- newIORef False
179+ clickedRef <- newRef False
179180 testWidget' (WD.findElem $ WD.ByTag "div") WD.click $ do
180181 (e, _) <- el' "div" $ text "hello world"
181− performEvent_ $ liftIO (writeIORef clickedRef True) <$ domEvent Click e
182− clicked <- readIORef clickedRef
182+ performEvent_ $ liftIO (writeRef clickedRef True) <$ domEvent Click e
183+ clicked <- readRef clickedRef
183184 assertEqual "Not clicked" True clicked
184185 it "works with eventFlags stopPropagation" $ do
185− firstClickedRef <- newIORef False
186− secondClickedRef <- newIORef False
186+ firstClickedRef <- newRef False
187+ secondClickedRef <- newRef False
187188 let clickBoth = do
188189 WD.findElem (WD.ById "first") >>= WD.click
189190 WD.findElem (WD.ById "second") >>= WD.click
190191 testWidget (pure ()) clickBoth $ do
191192 (firstDivEl, _) <- el' "div" $ prerender_ (pure ()) $ do
192193 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
194195 (secondDivEl, _) <- el' "div" $ prerender_ (pure ()) $ do
195196 let conf :: ElementConfig EventResult (SpiderTimeline Global) GhcjsDomSpace
196197 conf = (def :: ElementConfig EventResult (SpiderTimeline Global) GhcjsDomSpace)
197198 & initialAttributes .~ "id" =: "second"
198199 & elementConfig_eventSpec .~ (addEventSpecFlags (Proxy :: Proxy GhcjsDomSpace) Click (\_ -> stopPropagation) def)
199200 void $ element "span" conf $ text "hello world"
200− performEvent_ $ liftIO (writeIORef secondClickedRef True) <$ domEvent Click secondDivEl
201− firstClicked <- readIORef firstClickedRef
202− secondClicked <- readIORef secondClickedRef
201+ performEvent_ $ liftIO (writeRef secondClickedRef True) <$ domEvent Click secondDivEl
202+ firstClicked <- readRef firstClickedRef
203+ secondClicked <- readRef secondClickedRef
203204 assertEqual "Click propagated when it should have stopped" (True, False) (firstClicked, secondClicked)
204205 it "works with eventFlags preventDefault" $ do
205206 let click = do
@@ -248,7 +249,7 @@ tests _selenium = do
248249 describe "inputElement" $ do
249250 describe "hydration" $ do
250251 it "doesn't wipe user input when switching over" $ do
251− inputRef <- newIORef ("" :: Text)
252+ inputRef <- newRef ("" :: Text)
252253 testWidget'
253254 (do
254255 e <- WD.findElem $ WD.ByTag "input"
@@ -258,204 +259,204 @@ tests _selenium = do
258259 t <- WD.attr e "value"
259260 liftIO $ t `shouldBe` Just "hello world"
260261 WD.click <=< WD.findElem $ WD.ByTag "button"
261− input <- liftIO $ readIORef inputRef
262+ input <- liftIO $ readRef inputRef
262263 liftIO $ input `shouldBe` "hello world"
263264 ) $ do
264265 e <- inputElement def
265266 click <- button "save"
266− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
267+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
267268 it "captures user input after switchover" $ do
268− inputRef <- newIORef ("" :: Text)
269+ inputRef <- newRef ("" :: Text)
269270 let checkValue = do
270271 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "input"
271272 WD.click <=< WD.findElem $ WD.ByTag "button"
272− input <- liftIO $ readIORef inputRef
273+ input <- liftIO $ readRef inputRef
273274 liftIO $ input `shouldBe` "hello world"
274275 testWidget (pure ()) checkValue $ do
275276 e <- inputElement def
276277 click <- button "save"
277− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
278+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
278279 it "sets focus appropriately" $ do
279− focusRef <- newIORef False
280+ focusRef <- newRef False
280281 let checkValue = do
281− liftIO $ readIORef focusRef >>= flip shouldBe False
282+ liftIO $ readRef focusRef >>= flip shouldBe False
282283 e <- WD.findElem $ WD.ByTag "input"
283284 WD.click e
284285 liftIO $ threadDelay 100000
285− liftIO $ readIORef focusRef >>= flip shouldBe True
286+ liftIO $ readRef focusRef >>= flip shouldBe True
286287 testWidget (pure ()) checkValue $ do
287288 e <- inputElement def
288− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_inputElement_hasFocus e)
289+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
289290 it "sets focus when focus occurs before hydration" $ do
290− focusRef <- newIORef False
291+ focusRef <- newRef False
291292 let setup = do
292293 e <- WD.findElem $ WD.ByTag "input"
293294 WD.click e
294295 hasFocus <- (== e) <$> WD.activeElem
295296 liftIO $ do
296297 hasFocus `shouldBe` True
297− readIORef focusRef >>= flip shouldBe False
298− check = liftIO $ readIORef focusRef >>= flip shouldBe True
298+ readRef focusRef >>= flip shouldBe False
299+ check = liftIO $ readRef focusRef >>= flip shouldBe True
299300 testWidget setup check $ do
300301 e <- inputElement def
301− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_inputElement_hasFocus e)
302+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
302303 it "sets value appropriately" $ do
303− valueByUIRef <- newIORef ("" :: Text)
304− valueRef <- newIORef ("" :: Text)
304+ valueByUIRef <- newRef ("" :: Text)
305+ valueRef <- newRef ("" :: Text)
305306 setValueChan :: Chan Text <- newChan
306307 let checkValue = do
307− liftIO $ readIORef valueByUIRef >>= flip shouldBe ""
308− liftIO $ readIORef valueRef >>= flip shouldBe ""
308+ liftIO $ readRef valueByUIRef >>= flip shouldBe ""
309+ liftIO $ readRef valueRef >>= flip shouldBe ""
309310 e <- WD.findElem $ WD.ByTag "input"
310311 WD.sendKeys "hello" e
311312 liftIO $ do
312313 threadDelay 100000
313− readIORef valueByUIRef >>= flip shouldBe "hello"
314− readIORef valueRef >>= flip shouldBe "hello"
314+ readRef valueByUIRef >>= flip shouldBe "hello"
315+ readRef valueRef >>= flip shouldBe "hello"
315316 writeChan setValueChan "world"
316317 threadDelay 100000
317− readIORef valueByUIRef >>= flip shouldBe "hello"
318− readIORef valueRef >>= flip shouldBe "world"
318+ readRef valueByUIRef >>= flip shouldBe "hello"
319+ readRef valueRef >>= flip shouldBe "world"
319320 testWidget (pure ()) checkValue $ do
320321 update <- triggerEventWithChan setValueChan
321322 e <- inputElement $ def & inputElementConfig_setValue .~ update
322− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _inputElement_input e
323− performEvent_ $ liftIO . writeIORef valueRef <$> updated (value e)
323+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _inputElement_input e
324+ performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
324325 it "sets checked appropriately" $ do
325− checkedByUIRef <- newIORef False
326− checkedRef <- newIORef False
326+ checkedByUIRef <- newRef False
327+ checkedRef <- newRef False
327328 setCheckedChan <- newChan
328329 let checkValue = do
329− liftIO $ readIORef checkedByUIRef >>= flip shouldBe False
330− liftIO $ readIORef checkedRef >>= flip shouldBe False
330+ liftIO $ readRef checkedByUIRef >>= flip shouldBe False
331+ liftIO $ readRef checkedRef >>= flip shouldBe False
331332 e <- WD.findElem $ WD.ByTag "input"
332333 WD.moveToCenter e
333334 WD.click e
334335 liftIO $ do
335336 threadDelay 100000
336− readIORef checkedByUIRef >>= flip shouldBe True
337− readIORef checkedRef >>= flip shouldBe True
337+ readRef checkedByUIRef >>= flip shouldBe True
338+ readRef checkedRef >>= flip shouldBe True
338339 writeChan setCheckedChan False
339340 threadDelay 100000
340− readIORef checkedByUIRef >>= flip shouldBe True
341− readIORef checkedRef >>= flip shouldBe False
341+ readRef checkedByUIRef >>= flip shouldBe True
342+ readRef checkedRef >>= flip shouldBe False
342343 testWidget (pure ()) checkValue $ do
343344 setChecked <- triggerEventWithChan setCheckedChan
344345 e <- inputElement $ def
345346 & initialAttributes .~ "type" =: "checkbox"
346347 & inputElementConfig_setChecked .~ setChecked
347− performEvent_ $ liftIO . writeIORef checkedByUIRef <$> _inputElement_checkedChange e
348− performEvent_ $ liftIO . writeIORef checkedRef <$> updated (_inputElement_checked e)
348+ performEvent_ $ liftIO . writeRef checkedByUIRef <$> _inputElement_checkedChange e
349+ performEvent_ $ liftIO . writeRef checkedRef <$> updated (_inputElement_checked e)
349350 it "captures file uploads" $ do
350− filesRef :: IORef [Text] <- newIORef []
351+ filesRef :: IORef [Text] <- newRef []
351352 let uploadFile = do
352353 e <- WD.findElem $ WD.ByTag "input"
353354 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
354355 WD.sendKeys (T.pack path) e
355356 WD.click <=< WD.findElem $ WD.ByTag "button"
356357 liftIO $ removeFile path
357− input <- liftIO $ readIORef filesRef
358+ input <- liftIO $ readRef filesRef
358359 liftIO $ input `shouldBe` [T.pack $ FilePath.takeFileName path]
359360 testWidget (pure ()) uploadFile $ do
360361 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
361362 click <- button "save"
362363 prerender_ (pure ()) $ performEvent_ $ ffor (tag (current (_inputElement_files e)) click) $ \fs -> do
363364 names <- liftJSM $ traverse File.getName fs
364− liftIO $ writeIORef filesRef names
365+ liftIO $ writeRef filesRef names
365366
366367 describe "hydration/immediate" $ do
367368 it "captures user input after switchover" $ do
368− inputRef :: IORef Text <- newIORef ""
369+ inputRef :: IORef Text <- newRef ""
369370 let checkValue = do
370371 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "input"
371372 WD.click <=< WD.findElem $ WD.ByTag "button"
372− input <- liftIO $ readIORef inputRef
373+ input <- liftIO $ readRef inputRef
373374 liftIO $ input `shouldBe` "hello world"
374375 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
375376 e <- inputElement def
376377 click <- button "save"
377− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
378+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
378379 it "sets focus appropriately" $ do
379− focusRef <- newIORef False
380+ focusRef <- newRef False
380381 let checkValue = do
381− liftIO $ readIORef focusRef >>= flip shouldBe False
382+ liftIO $ readRef focusRef >>= flip shouldBe False
382383 e <- WD.findElem $ WD.ByTag "input"
383384 WD.click e
384385 liftIO $ threadDelay 100000
385− liftIO $ readIORef focusRef >>= flip shouldBe True
386+ liftIO $ readRef focusRef >>= flip shouldBe True
386387 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
387388 e <- inputElement def
388− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_inputElement_hasFocus e)
389+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
389390 it "sets value appropriately" $ do
390− valueByUIRef :: IORef Text <- newIORef ""
391− valueRef :: IORef Text <- newIORef ""
391+ valueByUIRef :: IORef Text <- newRef ""
392+ valueRef :: IORef Text <- newRef ""
392393 setValueChan :: Chan Text <- newChan
393394 let checkValue = do
394− liftIO $ readIORef valueByUIRef >>= flip shouldBe ""
395− liftIO $ readIORef valueRef >>= flip shouldBe ""
395+ liftIO $ readRef valueByUIRef >>= flip shouldBe ""
396+ liftIO $ readRef valueRef >>= flip shouldBe ""
396397 e <- WD.findElem $ WD.ByTag "input"
397398 WD.sendKeys "hello" e
398399 liftIO $ do
399400 threadDelay 100000
400− readIORef valueByUIRef >>= flip shouldBe "hello"
401− readIORef valueRef >>= flip shouldBe "hello"
401+ readRef valueByUIRef >>= flip shouldBe "hello"
402+ readRef valueRef >>= flip shouldBe "hello"
402403 writeChan setValueChan "world"
403404 threadDelay 100000
404− readIORef valueByUIRef >>= flip shouldBe "hello"
405− readIORef valueRef >>= flip shouldBe "world"
405+ readRef valueByUIRef >>= flip shouldBe "hello"
406+ readRef valueRef >>= flip shouldBe "world"
406407 testWidget (pure ()) checkValue $ do
407408 update <- triggerEventWithChan setValueChan
408409 prerender_ (pure ()) $ do
409410 e <- inputElement $ def & inputElementConfig_setValue .~ update
410− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _inputElement_input e
411− performEvent_ $ liftIO . writeIORef valueRef <$> updated (value e)
411+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _inputElement_input e
412+ performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
412413 it "sets checked appropriately" $ do
413− checkedByUIRef <- newIORef False
414− checkedRef <- newIORef False
414+ checkedByUIRef <- newRef False
415+ checkedRef <- newRef False
415416 setCheckedChan <- newChan
416417 let checkValue = do
417− liftIO $ readIORef checkedByUIRef >>= flip shouldBe False
418− liftIO $ readIORef checkedRef >>= flip shouldBe False
418+ liftIO $ readRef checkedByUIRef >>= flip shouldBe False
419+ liftIO $ readRef checkedRef >>= flip shouldBe False
419420 e <- WD.findElem $ WD.ByTag "input"
420421 WD.moveToCenter e
421422 WD.click e
422423 liftIO $ do
423424 threadDelay 100000
424− readIORef checkedByUIRef >>= flip shouldBe True
425− readIORef checkedRef >>= flip shouldBe True
425+ readRef checkedByUIRef >>= flip shouldBe True
426+ readRef checkedRef >>= flip shouldBe True
426427 writeChan setCheckedChan False
427428 threadDelay 100000
428− readIORef checkedByUIRef >>= flip shouldBe True
429− readIORef checkedRef >>= flip shouldBe False
429+ readRef checkedByUIRef >>= flip shouldBe True
430+ readRef checkedRef >>= flip shouldBe False
430431 testWidget (pure ()) checkValue $ do
431432 setChecked <- triggerEventWithChan setCheckedChan
432433 prerender_ (pure ()) $ do
433434 e <- inputElement $ def
434435 & initialAttributes .~ "type" =: "checkbox"
435436 & inputElementConfig_setChecked .~ setChecked
436− performEvent_ $ liftIO . writeIORef checkedByUIRef <$> _inputElement_checkedChange e
437− performEvent_ $ liftIO . writeIORef checkedRef <$> updated (_inputElement_checked e)
437+ performEvent_ $ liftIO . writeRef checkedByUIRef <$> _inputElement_checkedChange e
438+ performEvent_ $ liftIO . writeRef checkedRef <$> updated (_inputElement_checked e)
438439 it "captures file uploads" $ do
439− filesRef :: IORef [Text] <- newIORef []
440+ filesRef :: IORef [Text] <- newRef []
440441 let uploadFile = do
441442 e <- WD.findElem $ WD.ByTag "input"
442443 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
443444 WD.sendKeys (T.pack path) e
444445 WD.click <=< WD.findElem $ WD.ByTag "button"
445446 liftIO $ removeFile path
446− input <- liftIO $ readIORef filesRef
447+ input <- liftIO $ readRef filesRef
447448 liftIO $ input `shouldBe` [T.pack $ FilePath.takeFileName path]
448449 testWidget (pure ()) uploadFile $ prerender_ (pure ()) $ do
449450 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
450451 click <- button "save"
451452 performEvent_ $ ffor (tag (current (_inputElement_files e)) click) $ \fs -> do
452453 names <- liftJSM $ traverse File.getName fs
453− liftIO $ writeIORef filesRef names
454+ liftIO $ writeRef filesRef names
454455
455456 describe "textAreaElement" $ do
456457 describe "hydration" $ do
457458 it "doesn't wipe user input when switching over" $ do
458− inputRef <- newIORef ("" :: Text)
459+ inputRef <- newRef ("" :: Text)
459460 testWidget'
460461 (do
461462 e <- WD.findElem $ WD.ByTag "textarea"
@@ -465,116 +466,116 @@ tests _selenium = do
465466 t <- WD.attr e "value"
466467 liftIO $ t `shouldBe` Just "hello world"
467468 WD.click <=< WD.findElem $ WD.ByTag "button"
468− input <- liftIO $ readIORef inputRef
469+ input <- liftIO $ readRef inputRef
469470 liftIO $ input `shouldBe` "hello world"
470471 ) $ do
471472 e <- textAreaElement def
472473 click <- button "save"
473− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
474+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
474475 it "captures user input after switchover" $ do
475− inputRef <- newIORef ("" :: Text)
476+ inputRef <- newRef ("" :: Text)
476477 let checkValue = do
477478 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "textarea"
478479 WD.click <=< WD.findElem $ WD.ByTag "button"
479− input <- liftIO $ readIORef inputRef
480+ input <- liftIO $ readRef inputRef
480481 liftIO $ input `shouldBe` "hello world"
481482 testWidget (pure ()) checkValue $ do
482483 e <- textAreaElement def
483484 click <- button "save"
484− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
485+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
485486 it "sets focus appropriately" $ do
486− focusRef <- newIORef False
487+ focusRef <- newRef False
487488 let checkValue = do
488− liftIO $ readIORef focusRef >>= flip shouldBe False
489+ liftIO $ readRef focusRef >>= flip shouldBe False
489490 e <- WD.findElem $ WD.ByTag "textarea"
490491 WD.click e
491492 liftIO $ threadDelay 100000
492− liftIO $ readIORef focusRef >>= flip shouldBe True
493+ liftIO $ readRef focusRef >>= flip shouldBe True
493494 testWidget (pure ()) checkValue $ do
494495 e <- textAreaElement def
495− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_textAreaElement_hasFocus e)
496+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
496497 it "sets focus when focus occurs before hydration" $ do
497− focusRef <- newIORef False
498+ focusRef <- newRef False
498499 let setup = do
499500 e <- WD.findElem $ WD.ByTag "textarea"
500501 WD.click e
501502 hasFocus <- (== e) <$> WD.activeElem
502503 liftIO $ do
503504 hasFocus `shouldBe` True
504− readIORef focusRef >>= flip shouldBe False
505− check = liftIO $ readIORef focusRef >>= flip shouldBe True
505+ readRef focusRef >>= flip shouldBe False
506+ check = liftIO $ readRef focusRef >>= flip shouldBe True
506507 testWidget setup check $ do
507508 e <- textAreaElement def
508− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_textAreaElement_hasFocus e)
509+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
509510 it "sets value appropriately" $ do
510− valueByUIRef <- newIORef ("" :: Text)
511− valueRef <- newIORef ("" :: Text)
511+ valueByUIRef <- newRef ("" :: Text)
512+ valueRef <- newRef ("" :: Text)
512513 setValueChan :: Chan Text <- newChan
513514 let checkValue = do
514− liftIO $ readIORef valueByUIRef >>= flip shouldBe ""
515− liftIO $ readIORef valueRef >>= flip shouldBe ""
515+ liftIO $ readRef valueByUIRef >>= flip shouldBe ""
516+ liftIO $ readRef valueRef >>= flip shouldBe ""
516517 e <- WD.findElem $ WD.ByTag "textarea"
517518 WD.sendKeys "hello" e
518519 liftIO $ do
519520 threadDelay 100000
520− readIORef valueByUIRef >>= flip shouldBe "hello"
521− readIORef valueRef >>= flip shouldBe "hello"
521+ readRef valueByUIRef >>= flip shouldBe "hello"
522+ readRef valueRef >>= flip shouldBe "hello"
522523 writeChan setValueChan "world"
523524 threadDelay 100000
524− readIORef valueByUIRef >>= flip shouldBe "hello"
525− readIORef valueRef >>= flip shouldBe "world"
525+ readRef valueByUIRef >>= flip shouldBe "hello"
526+ readRef valueRef >>= flip shouldBe "world"
526527 testWidget (pure ()) checkValue $ do
527528 setValue' <- triggerEventWithChan setValueChan
528529 e <- textAreaElement $ def { _textAreaElementConfig_setValue = Just setValue' }
529− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _textAreaElement_input e
530− performEvent_ $ liftIO . writeIORef valueRef <$> updated (value e)
530+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _textAreaElement_input e
531+ performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
531532
532533 describe "hydration/immediate" $ do
533534 it "captures user input after switchover" $ do
534− inputRef :: IORef Text <- newIORef ""
535+ inputRef :: IORef Text <- newRef ""
535536 let checkValue = do
536537 WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "textarea"
537538 WD.click <=< WD.findElem $ WD.ByTag "button"
538− input <- liftIO $ readIORef inputRef
539+ input <- liftIO $ readRef inputRef
539540 liftIO $ input `shouldBe` "hello world"
540541 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
541542 e <- textAreaElement def
542543 click <- button "save"
543− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (value e)) click
544+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
544545 it "sets focus appropriately" $ do
545− focusRef <- newIORef False
546+ focusRef <- newRef False
546547 let checkValue = do
547− liftIO $ readIORef focusRef >>= flip shouldBe False
548+ liftIO $ readRef focusRef >>= flip shouldBe False
548549 e <- WD.findElem $ WD.ByTag "textarea"
549550 WD.click e
550551 liftIO $ threadDelay 100000
551− liftIO $ readIORef focusRef >>= flip shouldBe True
552+ liftIO $ readRef focusRef >>= flip shouldBe True
552553 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
553554 e <- textAreaElement def
554− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_textAreaElement_hasFocus e)
555+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
555556 it "sets value appropriately" $ do
556− valueByUIRef :: IORef Text <- newIORef ""
557− valueRef :: IORef Text <- newIORef ""
557+ valueByUIRef :: IORef Text <- newRef ""
558+ valueRef :: IORef Text <- newRef ""
558559 setValueChan :: Chan Text <- newChan
559560 let checkValue = do
560− liftIO $ readIORef valueByUIRef >>= flip shouldBe ""
561− liftIO $ readIORef valueRef >>= flip shouldBe ""
561+ liftIO $ readRef valueByUIRef >>= flip shouldBe ""
562+ liftIO $ readRef valueRef >>= flip shouldBe ""
562563 e <- WD.findElem $ WD.ByTag "textarea"
563564 WD.sendKeys "hello" e
564565 liftIO $ do
565566 threadDelay 100000
566− readIORef valueByUIRef >>= flip shouldBe "hello"
567− readIORef valueRef >>= flip shouldBe "hello"
567+ readRef valueByUIRef >>= flip shouldBe "hello"
568+ readRef valueRef >>= flip shouldBe "hello"
568569 writeChan setValueChan "world"
569570 threadDelay 100000
570− readIORef valueByUIRef >>= flip shouldBe "hello"
571− readIORef valueRef >>= flip shouldBe "world"
571+ readRef valueByUIRef >>= flip shouldBe "hello"
572+ readRef valueRef >>= flip shouldBe "world"
572573 testWidget (pure ()) checkValue $ do
573574 setValue' <- triggerEventWithChan setValueChan
574575 prerender_ (pure ()) $ do
575576 e <- textAreaElement $ def { _textAreaElementConfig_setValue = Just setValue' }
576− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _textAreaElement_input e
577− performEvent_ $ liftIO . writeIORef valueRef <$> updated (value e)
577+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _textAreaElement_input e
578+ performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
578579
579580 describe "selectElement" $ do
580581 let options :: DomBuilder t m => m ()
@@ -584,7 +585,7 @@ tests _selenium = do
584585 elAttr "option" ("value" =: "three" <> "id" =: "three") $ text "three"
585586 describe "hydration" $ do
586587 it "sets initial value correctly" $ do
587− inputRef <- newIORef ("" :: Text)
588+ inputRef <- newRef ("" :: Text)
588589 let setup = do
589590 e <- WD.findElem $ WD.ByTag "select"
590591 assertAttr e "value" (Just "three")
@@ -592,120 +593,120 @@ tests _selenium = do
592593 pure e
593594 check e = do
594595 assertAttr e "value" (Just "two")
595− liftIO $ readIORef inputRef >>= (`shouldBe` "three")
596+ liftIO $ readRef inputRef >>= (`shouldBe` "three")
596597 WD.click <=< WD.findElem $ WD.ByTag "button"
597598 assertAttr e "value" (Just "two")
598− liftIO $ readIORef inputRef >>= (`shouldBe` "two")
599+ liftIO $ readRef inputRef >>= (`shouldBe` "two")
599600 testWidget' setup check $ do
600601 (e, ()) <- selectElement (def { _selectElementConfig_initialValue = "three" }) options
601602 click <- button "save"
602− liftIO . writeIORef inputRef <=< sample $ current $ _selectElement_value e
603− performEvent_ $ liftIO . writeIORef inputRef <$> tag (current (_selectElement_value e)) click
603+ liftIO . writeRef inputRef <=< sample $ current $ _selectElement_value e
604+ performEvent_ $ liftIO . writeRef inputRef <$> tag (current (_selectElement_value e)) click
604605 it "captures user input after switchover" $ do
605− inputRef <- newIORef ("" :: Text)
606+ inputRef <- newRef ("" :: Text)
606607 let checkValue = do
607608 e <- WD.findElem $ WD.ByTag "select"
608609 assertAttr e "value" (Just "one")
609610 WD.click <=< WD.findElem $ WD.ById "two"
610611 assertAttr e "value" (Just "two")
611612 WD.click <=< WD.findElem $ WD.ByTag "button"
612− liftIO $ readIORef inputRef >>= (`shouldBe` "two")
613+ liftIO $ readRef inputRef >>= (`shouldBe` "two")
613614 testWidget (pure ()) checkValue $ do
614615 (e, ()) <- selectElement def options
615616 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
617618 it "sets focus appropriately" $ do
618− focusRef <- newIORef False
619+ focusRef <- newRef False
619620 let checkValue = do
620− liftIO $ readIORef focusRef >>= flip shouldBe False
621+ liftIO $ readRef focusRef >>= flip shouldBe False
621622 e <- WD.findElem $ WD.ByTag "select"
622623 WD.click e
623624 liftIO $ threadDelay 100000
624− liftIO $ readIORef focusRef >>= flip shouldBe True
625+ liftIO $ readRef focusRef >>= flip shouldBe True
625626 testWidget (pure ()) checkValue $ do
626627 (e, ()) <- selectElement def options
627− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_selectElement_hasFocus e)
628+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
628629 it "sets focus when focus occurs before hydration" $ do
629− focusRef <- newIORef False
630+ focusRef <- newRef False
630631 let setup = do
631632 e <- WD.findElem $ WD.ByTag "select"
632633 WD.click e
633634 hasFocus <- (== e) <$> WD.activeElem
634635 liftIO $ do
635636 hasFocus `shouldBe` True
636− readIORef focusRef >>= flip shouldBe False
637− check = liftIO $ readIORef focusRef >>= flip shouldBe True
637+ readRef focusRef >>= flip shouldBe False
638+ check = liftIO $ readRef focusRef >>= flip shouldBe True
638639 testWidget setup check $ do
639640 (e, ()) <- selectElement def options
640− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_selectElement_hasFocus e)
641+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
641642 it "sets value appropriately" $ do
642− valueByUIRef <- newIORef ("" :: Text)
643− valueRef <- newIORef ("" :: Text)
643+ valueByUIRef <- newRef ("" :: Text)
644+ valueRef <- newRef ("" :: Text)
644645 setValueChan :: Chan Text <- newChan
645646 let checkValue = do
646647 e <- WD.findElem $ WD.ByTag "select"
647648 assertAttr e "value" (Just "one")
648− liftIO $ readIORef valueByUIRef >>= flip shouldBe "one"
649− liftIO $ readIORef valueRef >>= flip shouldBe "one"
649+ liftIO $ readRef valueByUIRef >>= flip shouldBe "one"
650+ liftIO $ readRef valueRef >>= flip shouldBe "one"
650651 WD.click <=< WD.findElem $ WD.ById "two"
651652 liftIO $ do
652653 threadDelay 100000
653− readIORef valueByUIRef >>= flip shouldBe "two"
654− readIORef valueRef >>= flip shouldBe "two"
654+ readRef valueByUIRef >>= flip shouldBe "two"
655+ readRef valueRef >>= flip shouldBe "two"
655656 writeChan setValueChan "three"
656657 threadDelay 100000
657− readIORef valueByUIRef >>= flip shouldBe "two"
658− readIORef valueRef >>= flip shouldBe "three"
658+ readRef valueByUIRef >>= flip shouldBe "two"
659+ readRef valueRef >>= flip shouldBe "three"
659660 testWidget (pure ()) checkValue $ do
660661 setValue' <- triggerEventWithChan setValueChan
661662 (e, ()) <- selectElement def { _selectElementConfig_setValue = Just setValue' } options
662− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _selectElement_change e
663− performEvent_ $ liftIO . writeIORef valueRef <$> updated (_selectElement_value e)
663+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _selectElement_change e
664+ performEvent_ $ liftIO . writeRef valueRef <$> updated (_selectElement_value e)
664665
665666 describe "hydration/immediate" $ do
666667 it "captures user input after switchover" $ do
667− inputRef :: IORef Text <- newIORef ""
668+ inputRef :: IORef Text <- newRef ""
668669 let checkValue = do
669670 WD.click <=< WD.findElem $ WD.ById "two"
670671 WD.click <=< WD.findElem $ WD.ByTag "button"
671− liftIO $ readIORef inputRef >>= flip shouldBe "two"
672+ liftIO $ readRef inputRef >>= flip shouldBe "two"
672673 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
673674 (e, ()) <- selectElement def options
674675 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
676677 it "sets focus appropriately" $ do
677− focusRef <- newIORef False
678+ focusRef <- newRef False
678679 let checkValue = do
679− liftIO $ readIORef focusRef >>= flip shouldBe False
680+ liftIO $ readRef focusRef >>= flip shouldBe False
680681 e <- WD.findElem $ WD.ByTag "select"
681682 WD.click e
682683 liftIO $ threadDelay 100000
683− liftIO $ readIORef focusRef >>= flip shouldBe True
684+ liftIO $ readRef focusRef >>= flip shouldBe True
684685 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
685686 (e, ()) <- selectElement def options
686− performEvent_ $ liftIO . writeIORef focusRef <$> updated (_selectElement_hasFocus e)
687+ performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
687688 it "sets value appropriately" $ do
688− valueByUIRef :: IORef Text <- newIORef ""
689− valueRef :: IORef Text <- newIORef ""
689+ valueByUIRef :: IORef Text <- newRef ""
690+ valueRef :: IORef Text <- newRef ""
690691 setValueChan :: Chan Text <- newChan
691692 let checkValue = do
692− liftIO $ readIORef valueByUIRef >>= flip shouldBe "one"
693− liftIO $ readIORef valueRef >>= flip shouldBe "one"
693+ liftIO $ readRef valueByUIRef >>= flip shouldBe "one"
694+ liftIO $ readRef valueRef >>= flip shouldBe "one"
694695 WD.click <=< WD.findElem $ WD.ById "two"
695696 liftIO $ do
696697 threadDelay 100000
697− readIORef valueByUIRef >>= flip shouldBe "two"
698− readIORef valueRef >>= flip shouldBe "two"
698+ readRef valueByUIRef >>= flip shouldBe "two"
699+ readRef valueRef >>= flip shouldBe "two"
699700 writeChan setValueChan "three"
700701 threadDelay 100000
701− readIORef valueByUIRef >>= flip shouldBe "two"
702− readIORef valueRef >>= flip shouldBe "three"
702+ readRef valueByUIRef >>= flip shouldBe "two"
703+ readRef valueRef >>= flip shouldBe "three"
703704 testWidget (pure ()) checkValue $ do
704705 setValue' <- triggerEventWithChan setValueChan
705706 prerender_ (pure ()) $ do
706707 (e, ()) <- selectElement def { _selectElementConfig_setValue = Just setValue' } options
707− performEvent_ $ liftIO . writeIORef valueByUIRef <$> _selectElement_change e
708− performEvent_ $ liftIO . writeIORef valueRef <$> updated (_selectElement_value e)
708+ performEvent_ $ liftIO . writeRef valueByUIRef <$> _selectElement_change e
709+ performEvent_ $ liftIO . writeRef valueRef <$> updated (_selectElement_value e)
709710
710711 describe "prerender" $ do
711712 it "works in simple case" $ do
@@ -763,9 +764,9 @@ tests _selenium = do
763764 it "can't exploit IO to break hydration" $ do
764765 let static = shouldContainText "Initial" =<< WD.findElem (WD.ByTag "body")
765766 testWidgetStatic static $ void $ do
766− ref <- liftIO $ newIORef "Initial"
767− prerender_ (pure ()) (liftIO $ writeIORef ref "Client")
768− text <=< liftIO $ readIORef ref
767+ ref <- liftIO $ newRef "Initial"
768+ prerender_ (pure ()) (liftIO $ writeRef ref "Client")
769+ text <=< liftIO $ readRef ref
769770 -- As above, so below
770771 it "can't exploit triggerEvent to break hydration" $ do
771772 let static = shouldContainText "Initial" =<< WD.findElem (WD.ByTag "body")