@@ -1,54 +1,39 @@
1{-# LANGUAGE BangPatterns #-}
1{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE StandaloneDeriving #-}
3+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4+{-# LANGUAGE UndecidableInstances #-}
2{-# LANGUAGE ConstraintKinds #-}
5{-# LANGUAGE ConstraintKinds #-}
3{-# LANGUAGE FlexibleContexts #-}
7{-# LANGUAGE FlexibleContexts #-}
4−{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE GADTs #-}
8{-# LANGUAGE GADTs #-}
6−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7{-# LANGUAGE LambdaCase #-}
9{-# LANGUAGE LambdaCase #-}
8{-# LANGUAGE MultiParamTypeClasses #-}
10{-# LANGUAGE MultiParamTypeClasses #-}
9{-# LANGUAGE OverloadedStrings #-}
11{-# LANGUAGE OverloadedStrings #-}
10−{-# LANGUAGE PolyKinds #-}
11{-# LANGUAGE RankNTypes #-}
12{-# LANGUAGE RankNTypes #-}
12{-# LANGUAGE RecursiveDo #-}
13{-# LANGUAGE RecursiveDo #-}
13{-# LANGUAGE ScopedTypeVariables #-}
14{-# LANGUAGE ScopedTypeVariables #-}
14−{-# LANGUAGE StandaloneDeriving #-}
15{-# LANGUAGE TemplateHaskell #-}
15{-# LANGUAGE TemplateHaskell #-}
16{-# LANGUAGE TupleSections #-}
16{-# LANGUAGE TupleSections #-}
17{-# LANGUAGE TypeApplications #-}
17{-# LANGUAGE TypeApplications #-}
18{-# LANGUAGE TypeFamilies #-}
18{-# LANGUAGE TypeFamilies #-}
19−{-# LANGUAGE UndecidableInstances #-}
21−{-# OPTIONS_GHC -fno-warn-orphans #-}
23−-- Notice to those working on this test suite:
24−-- It doesn't appear to be possible to use --match to run a particular test, in
25−-- this situation the test may hang before reaching our code. This seems to
26−-- happen when the test is not the first test in the block. As a workaround, you
27−-- can just comment out the other tests. Also, using `xit` will cause the same
28−-- issue. `xit` tests must be the last tests in the session, or the session will
29−-- hang in the following test.
31−import Prelude hiding (fail)
32import Control.Concurrent
20import Control.Concurrent
33−import qualified Control.Concurrent.Async as Async
34−import Control.Lens.Operators
35−import Control.Monad hiding (fail)
21+import Control.Monad
36import Control.Monad.Catch
22import Control.Monad.Catch
37−import Control.Monad.Fail
38import Control.Monad.Fix
23import Control.Monad.Fix
39import Control.Monad.IO.Class
24import Control.Monad.IO.Class
40import Control.Monad.Ref
25import Control.Monad.Ref
26+import Data.Constraint (Dict(..))
41import Data.Constraint.Extras
27import Data.Constraint.Extras
42−import Data.Constraint.Extras.TH
43import Data.Dependent.Map (DMap)
28import Data.Dependent.Map (DMap)
44−import Data.Dependent.Sum (DSum(..), (==>))
29+import Data.Dependent.Sum (DSum(..), (==>), EqTag(..), ShowTag(..))
30+import Data.Foldable (traverse_)
45import Data.Functor.Identity
31import Data.Functor.Identity
46import Data.Functor.Misc
32import Data.Functor.Misc
47import Data.GADT.Compare.TH
33import Data.GADT.Compare.TH
48import Data.GADT.Show.TH
34import Data.GADT.Show.TH
49import Data.IORef (IORef)
35import Data.IORef (IORef)
50−import Data.List (sort)
36+import Data.Maybe (fromMaybe, fromJust)
52import Data.Proxy
37import Data.Proxy
53import Data.Text (Text)
38import Data.Text (Text)
54import Language.Javascript.JSaddle (syncPoint, liftJSM)
39import Language.Javascript.JSaddle (syncPoint, liftJSM)
@@ -58,22 +43,18 @@ import Network.Socket
58import Network.Wai
43import Network.Wai
59import Network.WebSockets
44import Network.WebSockets
60import Reflex.Dom.Core
45import Reflex.Dom.Core
61−import Reflex.Dom.Widget.Input (dropdown)
62import Reflex.Patch.DMapWithMove
46import Reflex.Patch.DMapWithMove
63import System.Directory
47import System.Directory
64−import System.Environment
65import System.IO (stderr)
48import System.IO (stderr)
66import System.IO.Silently
49import System.IO.Silently
67import System.IO.Temp
50import System.IO.Temp
68import System.Process
51import System.Process
69−import System.Which (staticWhich)
52+import System.Timeout.Lifted
70−import qualified Test.HUnit as HUnit
53+import qualified Test.HUnit as HUnit (assertEqual, assertFailure)
71import qualified Test.Hspec as H
54import qualified Test.Hspec as H
72−import qualified Test.Hspec.Core.Spec as H
73−import Test.Hspec (xit)
74−import Test.Hspec.WebDriver hiding (runWD, click, uploadFile, WD)
55+import Test.Hspec.WebDriver hiding (runWD)
75import qualified Test.Hspec.WebDriver as WD
56import qualified Test.Hspec.WebDriver as WD
76−import Test.WebDriver (WD(..))
57+import Test.WebDriver (WD)
78import qualified Data.ByteString.Lazy as LBS
59import qualified Data.ByteString.Lazy as LBS
79import qualified Data.Dependent.Map as DMap
60import qualified Data.Dependent.Map as DMap
@@ -86,37 +67,20 @@ import qualified System.FilePath as FilePath
86import qualified Test.WebDriver as WD
67import qualified Test.WebDriver as WD
87import qualified Test.WebDriver.Capabilities as WD
68import qualified Test.WebDriver.Capabilities as WD
89−import Test.Util.ChromeFlags
90−import Test.Util.UnshareNetwork
92−-- ORPHAN: https://github.com/kallisti-dev/hs-webdriver/pull/167
93−deriving instance MonadMask WD
96−chromium = $(staticWhich "chromium")
98−seleniumPort, jsaddlePort :: PortNumber
102-- TODO Remove orphan
70-- TODO Remove orphan
103−instance MonadRef WD where
71+deriving instance MonadRef WD
104− type Ref WD = Ref IO
105− newRef = WD . newRef
106− readRef = WD . readRef
107− writeRef r = WD . writeRef r
109assertEqual :: (MonadIO m, Eq a, Show a) => String -> a -> a -> m ()
73assertEqual :: (MonadIO m, Eq a, Show a) => String -> a -> a -> m ()
110−assertEqual msg a b = liftIO $ HUnit.assertEqual msg a b
74+assertEqual a b = liftIO . HUnit.assertEqual a b
112assertFailure :: MonadIO m => String -> m ()
76assertFailure :: MonadIO m => String -> m ()
113assertFailure = liftIO . HUnit.assertFailure
77assertFailure = liftIO . HUnit.assertFailure
115−assertBool :: (MonadIO m) => String -> Bool -> m ()
79+testTimeLimit :: Int
116−assertBool msg bool = liftIO $ HUnit.assertBool msg bool
80+testTimeLimit = 5 * 1000 * 1000
118−chromeConfig :: Text -> [Text] -> WD.WDConfig
82+chromeConfig :: Text -> WD.WDConfig
119−chromeConfig fp flags = WD.useBrowser (WD.chrome { WD.chromeBinary = Just $ T.unpack fp, WD.chromeOptions = T.unpack <$> flags }) WD.defaultConfig
83+chromeConfig fp = WD.useBrowser (WD.chrome { WD.chromeBinary = Just $ T.unpack fp, WD.chromeOptions = ["--headless"] }) WD.defaultConfig
121keyMap :: DMap DKey Identity
85keyMap :: DMap DKey Identity
122keyMap = DMap.fromList
86keyMap = DMap.fromList
@@ -129,6 +93,14 @@ data DKey a where
129 Key_Char :: DKey Char
93 Key_Char :: DKey Char
130 Key_Bool :: DKey Bool
94 Key_Bool :: DKey Bool
96+instance ArgDict DKey where
97+ type ConstraintsFor DKey c = (c Int, c Char, c Bool)
98+ type ConstraintsFor' DKey c g = (c (g Int), c (g Char), c (g Bool))
103+ argDict' = undefined -- Missing constraints?
133textKey :: DKey a -> Text
105textKey :: DKey a -> Text
134textKey = \case
106textKey = \case
@@ -136,43 +108,34 @@ textKey = \case
136 Key_Char -> "Key_Char"
108 Key_Char -> "Key_Char"
137 Key_Bool -> "Key_Bool"
109 Key_Bool -> "Key_Bool"
140deriveGEq ''DKey
111deriveGEq ''DKey
141deriveGCompare ''DKey
112deriveGCompare ''DKey
142deriveGShow ''DKey
113deriveGShow ''DKey
144−deriving instance MonadFail WD
115+instance ShowTag DKey Identity where
116+ showTaggedPrec = \case
117+ Key_Int -> showsPrec
118+ Key_Char -> showsPrec
119+ Key_Bool -> showsPrec
121+instance EqTag DKey Identity where
122+ eqTagged Key_Int Key_Int = (==)
123+ eqTagged Key_Char Key_Char = (==)
124+ eqTagged Key_Bool Key_Bool = (==)
146main :: IO ()
126main :: IO ()
149− isHeadless <- (== Nothing) <$> lookupEnv "NO_HEADLESS"
150− withSandboxedChromeFlags isHeadless $ \chromeFlags -> do
151− withSeleniumServer $ \selenium -> do
127+main = withSeleniumServer $ \selenium -> do
152− let browserPath = T.strip $ T.pack chromium
128+ browserPath <- liftIO $ T.strip . T.pack <$> readProcess "which" [ "chromium" ] ""
153− when (T.null browserPath) $ fail "No browser found"
129+ when (T.null browserPath) $ fail "No browser found"
154− withDebugging <- isNothing <$> lookupEnv "NO_DEBUG"
155− let wdConfig = WD.defaultConfig { WD.wdPort = fromIntegral $ _selenium_portNumber selenium }
130+ let wdConfig = WD.defaultConfig { WD.wdPort = fromIntegral $ _selenium_portNumber selenium }
156− chromeCaps' = WD.getCaps $ chromeConfig browserPath chromeFlags
131+ chromeCaps' = WD.getCaps $ chromeConfig browserPath
157− hspec (tests withDebugging wdConfig [(chromeCaps', "chrome")] selenium) `finally` _selenium_stopServer selenium
132+ hspec (tests wdConfig [chromeCaps'] selenium) `finally` _selenium_stopServer selenium
159−tests :: Bool -> WD.WDConfig -> [(Capabilities, String)] -> Selenium -> Spec
134+tests :: WD.WDConfig -> [Capabilities] -> Selenium -> Spec
160−tests withDebugging wdConfig caps _selenium = do
135+tests wdConfig caps _selenium = do
161− let putStrLnDebug :: MonadIO m => Text -> m ()
162− putStrLnDebug m = when withDebugging $ liftIO $ putStrLn $ T.unpack m
163− session' t = sessionWith wdConfig t . using caps
136+ let session' = sessionWith wdConfig "" . using (map (,"") caps)
164− runWD m = runWDOptions (WdOptions False) $ do
137+ runWD = runWDOptions (WdOptions False)
165− putStrLnDebug "before"
138+ describe "text" $ session' $ do
167− putStrLnDebug "after"
169− testWidgetStatic :: WD b -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ()) -> WD b
170− testWidgetStatic = testWidgetStaticDebug withDebugging
171− testWidget :: WD () -> WD b -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ()) -> WD b
172− testWidget = testWidgetDebug True withDebugging
173− testWidget' :: WD a -> (a -> WD b) -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ()) -> WD b
174− testWidget' = testWidgetDebug' True withDebugging
175− session' "text" $ do
176 it "works" $ runWD $ do
139 it "works" $ runWD $ do
177 testWidgetStatic (checkBodyText "hello world") $ do
140 testWidgetStatic (checkBodyText "hello world") $ do
178 text "hello world"
141 text "hello world"
@@ -227,25 +190,27 @@ tests withDebugging wdConfig caps _selenium = do
227 it "updates in immediate mode" $ runWD $ do
190 it "updates in immediate mode" $ runWD $ do
228 let checkUpdated = do
191 let checkUpdated = do
229 checkBodyText "initial"
192 checkBodyText "initial"
230− WD.click =<< findElemWithRetry (WD.ByTag "button")
193+ WD.click =<< WD.findElem (WD.ByTag "button")
194+ liftIO $ threadDelay 100000 -- wait for update
231 checkBodyText "after"
195 checkBodyText "after"
232 testWidget (pure ()) checkUpdated $ prerender_ (pure ()) $ do
196 testWidget (pure ()) checkUpdated $ prerender_ (pure ()) $ do
233 click <- button ""
197 click <- button ""
234 void $ textNode $ TextNodeConfig "initial" $ Just $ "after" <$ click
198 void $ textNode $ TextNodeConfig "initial" $ Just $ "after" <$ click
236− session' "element" $ do
200+ describe "element" $ session' $ do
237 it "works with domEvent Click" $ runWD $ do
201 it "works with domEvent Click" $ runWD $ do
238 clickedRef <- liftIO $ newRef False
202 clickedRef <- liftIO $ newRef False
239− testWidget' (findElemWithRetry $ WD.ByTag "div") WD.click $ do
203+ testWidget' (WD.findElem $ WD.ByTag "div") WD.click $ do
240 (e, _) <- el' "div" $ text "hello world"
204 (e, _) <- el' "div" $ text "hello world"
241 performEvent_ $ liftIO (writeRef clickedRef True) <$ domEvent Click e
205 performEvent_ $ liftIO (writeRef clickedRef True) <$ domEvent Click e
242− readRef clickedRef `shouldBeWithRetryM` True
206+ clicked <- liftIO $ readRef clickedRef
207+ liftIO $ assertEqual "Not clicked" True clicked
243 it "works with eventFlags stopPropagation" $ runWD $ do
208 it "works with eventFlags stopPropagation" $ runWD $ do
244 firstClickedRef <- newRef False
209 firstClickedRef <- newRef False
245 secondClickedRef <- newRef False
210 secondClickedRef <- newRef False
246 let clickBoth = do
211 let clickBoth = do
247− findElemWithRetry (WD.ById "first") >>= WD.click
212+ WD.findElem (WD.ById "first") >>= WD.click
248− findElemWithRetry (WD.ById "second") >>= WD.click
213+ WD.findElem (WD.ById "second") >>= WD.click
249 testWidget (pure ()) clickBoth $ do
214 testWidget (pure ()) clickBoth $ do
250 (firstDivEl, _) <- el' "div" $ prerender_ (pure ()) $ do
215 (firstDivEl, _) <- el' "div" $ prerender_ (pure ()) $ do
251 void $ elAttr "span" ("id" =: "first") $ text "hello world"
216 void $ elAttr "span" ("id" =: "first") $ text "hello world"
@@ -262,7 +227,7 @@ tests withDebugging wdConfig caps _selenium = do
262 assertEqual "Click propagated when it should have stopped" (True, False) (firstClicked, secondClicked)
227 assertEqual "Click propagated when it should have stopped" (True, False) (firstClicked, secondClicked)
263 it "works with eventFlags preventDefault" $ runWD $ do
228 it "works with eventFlags preventDefault" $ runWD $ do
264 let click = do
229 let click = do
265− e <- findElemWithRetry $ WD.ByTag "input"
230+ e <- WD.findElem $ WD.ByTag "input"
266 s0 <- WD.isSelected e
231 s0 <- WD.isSelected e
267 WD.click e
232 WD.click e
268 s1 <- WD.isSelected e
233 s1 <- WD.isSelected e
@@ -276,7 +241,7 @@ tests withDebugging wdConfig caps _selenium = do
276 assertEqual "Click not prevented" (False, False) clicked
241 assertEqual "Click not prevented" (False, False) clicked
277 it "can add/update/remove attributes" $ runWD $ do
242 it "can add/update/remove attributes" $ runWD $ do
278 let checkInitialAttrs = do
243 let checkInitialAttrs = do
279− e <- findElemWithRetry $ WD.ByTag "div"
244+ e <- WD.findElem $ WD.ByTag "div"
280 assertAttr e "const" (Just "const")
245 assertAttr e "const" (Just "const")
281 assertAttr e "delete" (Just "delete")
246 assertAttr e "delete" (Just "delete")
282 assertAttr e "init" (Just "init")
247 assertAttr e "init" (Just "init")
@@ -284,11 +249,11 @@ tests withDebugging wdConfig caps _selenium = do
285 checkModifyAttrs e = do
250 checkModifyAttrs e = do
286 WD.click e
251 WD.click e
287− withRetry $ do
252+ liftIO $ threadDelay 100000
288− assertAttr e "const" (Just "const")
253+ assertAttr e "const" (Just "const")
289− assertAttr e "delete" Nothing
254+ assertAttr e "delete" Nothing
290− assertAttr e "init" (Just "click")
255+ assertAttr e "init" (Just "click")
291− assertAttr e "click" (Just "click")
256+ assertAttr e "click" (Just "click")
292 testWidget' checkInitialAttrs checkModifyAttrs $ mdo
257 testWidget' checkInitialAttrs checkModifyAttrs $ mdo
293 let conf = def
258 let conf = def
294 & initialAttributes .~ "const" =: "const" <> "delete" =: "delete" <> "init" =: "init"
259 & initialAttributes .~ "const" =: "const" <> "delete" =: "delete" <> "init" =: "init"
@@ -296,87 +261,40 @@ tests withDebugging wdConfig caps _selenium = do
296 (e, ()) <- element "div" conf $ text "hello world"
261 (e, ()) <- element "div" conf $ text "hello world"
297 let click = domEvent Click e
262 let click = domEvent Click e
298 return ()
263 return ()
264+ -- TODO check this is the correct solution
265+ it "has ssr attribute, removes ssr attribute" $ runWD $ do
266+ let checkSSRAttr = do
267+ e <- WD.findElem $ WD.ByTag "div"
268+ assertAttr e "data-ssr" (Just "")
270+ testWidget' checkSSRAttr (\e -> assertAttr e "data-ssr" Nothing) $ el "div" $ text "hello world"
300− session' "inputElement" $ do
272+ describe "inputElement" $ do
301− describe "static renderer" $ do
273+ describe "hydration" $ session' $ do
302− it "sets value attribute" $ runWD $ do
303− let checkStatic = do
304− e <- findElemWithRetry $ WD.ByTag "input"
305− WD.attr e "value" `shouldBeWithRetryM` Just "test"
307− checkHydrated e = do
308− WD.attr e "value" `shouldBeWithRetryM` Just "test"
309− testWidget' checkStatic checkHydrated $ void $ inputElement $ def
310− & inputElementConfig_initialValue .~ "test"
311− it "updates value attribute at postBuild" $ runWD $ do
312− let checkStatic = do
313− e <- findElemWithRetry $ WD.ByTag "input"
314− WD.attr e "value" `shouldBeWithRetryM` Just "test-updated"
316− checkHydrated e = do
317− WD.attr e "value" `shouldBeWithRetryM` Just "test-updated"
318− testWidget' checkStatic checkHydrated $ do
320− _ <- inputElement $ def
321− & inputElementConfig_initialValue .~ "test"
322− & inputElementConfig_setValue .~ ("test-updated" <$ pb)
324− it "sets checked attr appropriately" $ runWD $ do
325− setCheckedChan <- liftIO newChan
326− let checkStatic = do
327− e <- findElemWithRetry $ WD.ByTag "input"
328− WD.attr e "checked" `shouldBeWithRetryM` Just "true"
331− WD.attr e "checked" `shouldBeWithRetryM` Just "true"
333− WD.click e -- Click to uncheck
334− WD.attr e "checked" `shouldBeWithRetryM` Nothing
335− liftIO $ writeChan setCheckedChan True -- Programatically check the checkbox
336− WD.attr e "checked" `shouldBeWithRetryM` Just "true"
337− testWidget' checkStatic checkValue $ do
338− setChecked <- triggerEventWithChan setCheckedChan
339− _ <- inputElement $ def
340− & initialAttributes .~ "type" =: "checkbox"
341− & inputElementConfig_initialChecked .~ True
342− & inputElementConfig_setChecked .~ setChecked
344− it "sets checked attr appropriately at postbuild" $ runWD $ do
345− let checkStatic = do
346− e <- findElemWithRetry $ WD.ByTag "input"
347− WD.attr e "checked" `shouldBeWithRetryM` Just "true"
350− WD.attr e "checked" `shouldBeWithRetryM` Just "true"
351− testWidget' checkStatic checkValue $ do
353− _ <- inputElement $ def
354− & initialAttributes .~ "type" =: "checkbox"
355− & inputElementConfig_initialChecked .~ False
356− & inputElementConfig_setChecked .~ (True <$ pb)
358− describe "hydration" $ do
359 it "doesn't wipe user input when switching over" $ runWD $ do
274 it "doesn't wipe user input when switching over" $ runWD $ do
360− inputRef <- newRef ("hello " :: Text)
275+ inputRef <- newRef ("" :: Text)
361 testWidget'
276 testWidget'
363− e <- findElemWithRetry $ WD.ByTag "input"
278+ e <- WD.findElem $ WD.ByTag "input"
364− WD.sendKeys "world" e
279+ WD.sendKeys "hello world" e
366 (\e -> do
281 (\e -> do
367− WD.attr e "value" `shouldBeWithRetryM` Just "hello world"
282+ t <- WD.attr e "value"
283+ t `shouldBe` Just "hello world"
368− WD.click =<< findElemWithRetry (WD.ByTag "button")
284+ WD.click <=< WD.findElem $ WD.ByTag "button"
369− readRef inputRef `shouldBeWithRetryM` "hello world"
285+ input <- liftIO $ readRef inputRef
286+ input `shouldBe` "hello world"
371− e <- inputElement $ def & inputElementConfig_initialValue .~ "hello "
288+ e <- inputElement def
372 click <- button "save"
289 click <- button "save"
373 performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
290 performEvent_ $ liftIO . writeRef inputRef <$> tag (current (value e)) click
374 it "captures user input after switchover" $ runWD $ do
291 it "captures user input after switchover" $ runWD $ do
375 inputRef <- newRef ("" :: Text)
292 inputRef <- newRef ("" :: Text)
376 let checkValue = do
293 let checkValue = do
377− WD.sendKeys "hello world" =<< findElemWithRetry (WD.ByTag "input")
294+ WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "input"
378− WD.click =<< findElemWithRetry (WD.ByTag "button")
295+ WD.click <=< WD.findElem $ WD.ByTag "button"
379− readRef inputRef `shouldBeWithRetryM` "hello world"
296+ input <- liftIO $ readRef inputRef
297+ input `shouldBe` "hello world"
380 testWidget (pure ()) checkValue $ do
298 testWidget (pure ()) checkValue $ do
381 e <- inputElement def
299 e <- inputElement def
382 click <- button "save"
300 click <- button "save"
@@ -384,21 +302,23 @@ tests withDebugging wdConfig caps _selenium = do
384 it "sets focus appropriately" $ runWD $ do
302 it "sets focus appropriately" $ runWD $ do
385 focusRef <- newRef False
303 focusRef <- newRef False
386 let checkValue = do
304 let checkValue = do
387− readRef focusRef `shouldBeWithRetryM` False
305+ readRef focusRef >>= flip shouldBe False
388− e <- findElemWithRetry $ WD.ByTag "input"
306+ e <- WD.findElem $ WD.ByTag "input"
389 WD.click e
307 WD.click e
308+ liftIO $ threadDelay 100000
390− readRef focusRef `shouldBeWithRetryM` True
309+ readRef focusRef >>= flip shouldBe True
391 testWidget (pure ()) checkValue $ do
310 testWidget (pure ()) checkValue $ do
392 e <- inputElement def
311 e <- inputElement def
393 performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
312 performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
394 it "sets focus when focus occurs before hydration" $ runWD $ do
313 it "sets focus when focus occurs before hydration" $ runWD $ do
395 focusRef <- newRef False
314 focusRef <- newRef False
396 let setup = do
315 let setup = do
397− e <- findElemWithRetry $ WD.ByTag "input"
316+ e <- WD.findElem $ WD.ByTag "input"
398 WD.click e
317 WD.click e
399− ((== e) <$> WD.activeElem) `shouldBeWithRetryM` True
318+ hasFocus <- (== e) <$> WD.activeElem
319+ hasFocus `shouldBe` True
400− readRef focusRef `shouldBeWithRetryM` False
320+ readRef focusRef >>= flip shouldBe False
401− check = readRef focusRef `shouldBeWithRetryM` True
321+ check = readRef focusRef >>= flip shouldBe True
402 testWidget setup check $ do
322 testWidget setup check $ do
403 e <- inputElement def
323 e <- inputElement def
404 performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
324 performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
@@ -407,15 +327,17 @@ tests withDebugging wdConfig caps _selenium = do
407 valueRef <- newRef ("" :: Text)
327 valueRef <- newRef ("" :: Text)
408 setValueChan :: Chan Text <- liftIO newChan
328 setValueChan :: Chan Text <- liftIO newChan
409 let checkValue = do
329 let checkValue = do
410− readRef valueByUIRef `shouldBeWithRetryM` ""
330+ readRef valueByUIRef >>= flip shouldBe ""
411− readRef valueRef `shouldBeWithRetryM` ""
331+ readRef valueRef >>= flip shouldBe ""
412− e <- findElemWithRetry $ WD.ByTag "input"
332+ e <- WD.findElem $ WD.ByTag "input"
413 WD.sendKeys "hello" e
333 WD.sendKeys "hello" e
334+ liftIO $ threadDelay 100000
414− readRef valueByUIRef `shouldBeWithRetryM` "hello"
335+ readRef valueByUIRef >>= flip shouldBe "hello"
415− readRef valueRef `shouldBeWithRetryM` "hello"
336+ readRef valueRef >>= flip shouldBe "hello"
416 liftIO $ writeChan setValueChan "world"
337 liftIO $ writeChan setValueChan "world"
338+ liftIO $ threadDelay 100000
417− readRef valueByUIRef `shouldBeWithRetryM` "hello"
339+ readRef valueByUIRef >>= flip shouldBe "hello"
418− readRef valueRef `shouldBeWithRetryM` "world"
340+ readRef valueRef >>= flip shouldBe "world"
419 testWidget (pure ()) checkValue $ do
341 testWidget (pure ()) checkValue $ do
420 update <- triggerEventWithChan setValueChan
342 update <- triggerEventWithChan setValueChan
421 e <- inputElement $ def & inputElementConfig_setValue .~ update
343 e <- inputElement $ def & inputElementConfig_setValue .~ update
@@ -425,181 +347,51 @@ tests withDebugging wdConfig caps _selenium = do
425 checkedByUIRef <- newRef False
347 checkedByUIRef <- newRef False
426 checkedRef <- newRef False
348 checkedRef <- newRef False
427 setCheckedChan <- liftIO newChan
349 setCheckedChan <- liftIO newChan
428− let checkStatic = do
350+ let checkValue = do
351+ readRef checkedByUIRef >>= flip shouldBe False
352+ readRef checkedRef >>= flip shouldBe False
429− e <- findElemWithRetry $ WD.ByTag "input"
353+ e <- WD.findElem $ WD.ByTag "input"
430− WD.attr e "checked" `shouldBeWithRetryM` Nothing
433− readRef checkedByUIRef `shouldBeWithRetryM` False
434− readRef checkedRef `shouldBeWithRetryM` False
435− WD.attr e "checked" `shouldBeWithRetryM` Nothing
436 WD.moveToCenter e
354 WD.moveToCenter e
437 WD.click e
355 WD.click e
356+ liftIO $ threadDelay 100000
438− readRef checkedByUIRef `shouldBeWithRetryM` True
357+ readRef checkedByUIRef >>= flip shouldBe True
439− readRef checkedRef `shouldBeWithRetryM` True
358+ readRef checkedRef >>= flip shouldBe True
440− WD.attr e "checked" `shouldBeWithRetryM` Just "true"
441 liftIO $ writeChan setCheckedChan False
359 liftIO $ writeChan setCheckedChan False
360+ liftIO $ threadDelay 100000
442− readRef checkedByUIRef `shouldBeWithRetryM` True
361+ readRef checkedByUIRef >>= flip shouldBe True
443− readRef checkedRef `shouldBeWithRetryM` False
362+ readRef checkedRef >>= flip shouldBe False
444− WD.attr e "checked" `shouldBeWithRetryM` Nothing
445− testWidget' checkStatic checkValue $ do
363+ testWidget (pure ()) checkValue $ do
446 setChecked <- triggerEventWithChan setCheckedChan
364 setChecked <- triggerEventWithChan setCheckedChan
447 e <- inputElement $ def
365 e <- inputElement $ def
448 & initialAttributes .~ "type" =: "checkbox"
366 & initialAttributes .~ "type" =: "checkbox"
449 & inputElementConfig_setChecked .~ setChecked
367 & inputElementConfig_setChecked .~ setChecked
450 performEvent_ $ liftIO . writeRef checkedByUIRef <$> _inputElement_checkedChange e
368 performEvent_ $ liftIO . writeRef checkedByUIRef <$> _inputElement_checkedChange e
451 performEvent_ $ liftIO . writeRef checkedRef <$> updated (_inputElement_checked e)
369 performEvent_ $ liftIO . writeRef checkedRef <$> updated (_inputElement_checked e)
452− it "respects user updates to checked which happen before hydration" $ runWD $ do
453− checkedByUIRef <- newRef False
454− checkedRef <- newRef False
455− let checkStatic = do
456− e <- findElemWithRetry $ WD.ByTag "input"
457− WD.attr e "checked" `shouldBeWithRetryM` Nothing
460− WD.attr e "checked" `shouldBeWithRetryM` Just "true"
463− WD.attr e "checked" `shouldBeWithRetryM` Just "true"
464− readRef checkedByUIRef `shouldBeWithRetryM` True
465− readRef checkedRef `shouldBeWithRetryM` True
466− testWidget' checkStatic checkValue $ do
467− e <- inputElement $ def
468− & initialAttributes .~ "type" =: "checkbox"
469− performEvent_ $ liftIO . writeRef checkedByUIRef <$> _inputElement_checkedChange e
470− performEvent_ $ liftIO . writeRef checkedRef <$> updated (_inputElement_checked e)
471 it "captures file uploads" $ runWD $ do
370 it "captures file uploads" $ runWD $ do
472 filesRef :: IORef [Text] <- newRef []
371 filesRef :: IORef [Text] <- newRef []
473 let uploadFile = do
372 let uploadFile = do
474− e <- findElemWithRetry $ WD.ByTag "input"
373+ e <- WD.findElem $ WD.ByTag "input"
475 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
374 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
476 WD.sendKeys (T.pack path) e
375 WD.sendKeys (T.pack path) e
477− WD.click =<< findElemWithRetry (WD.ByTag "button")
376+ WD.click <=< WD.findElem $ WD.ByTag "button"
478 liftIO $ removeFile path
377 liftIO $ removeFile path
378+ input <- readRef filesRef
479− readRef filesRef `shouldBeWithRetryM` [T.pack $ FilePath.takeFileName path]
379+ input `shouldBe` [T.pack $ FilePath.takeFileName path]
480 testWidget (pure ()) uploadFile $ do
380 testWidget (pure ()) uploadFile $ do
481 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
381 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
482 click <- button "save"
382 click <- button "save"
483 prerender_ (pure ()) $ performEvent_ $ ffor (tag (current (_inputElement_files e)) click) $ \fs -> do
383 prerender_ (pure ()) $ performEvent_ $ ffor (tag (current (_inputElement_files e)) click) $ \fs -> do
484 names <- liftJSM $ traverse File.getName fs
384 names <- liftJSM $ traverse File.getName fs
485 liftIO $ writeRef filesRef names
385 liftIO $ writeRef filesRef names
486− it "fires _input event if the user altered the value before hydration" $ runWD $ do
386+
487− input <- newRef ("" :: Text)
488− update <- newRef ("" :: Text)
489− let checkStatic = do
490− e <- findElemWithRetry $ WD.ByTag "input"
491− WD.attr e "value" `shouldBeWithRetryM` Just ""
492− WD.sendKeys "test" e
493− WD.attr e "value" `shouldBeWithRetryM` Just "test"
495− checkHydrated e = do
496− WD.attr e "value" `shouldBeWithRetryM` Just "test"
497− readRef input `shouldBeWithRetryM` "test"
498− readRef update `shouldBeWithRetryM` "test"
499− testWidget' checkStatic checkHydrated $ do
500− e <- inputElement def
501− performEvent_ $ liftIO . writeRef input <$> _inputElement_input e
502− performEvent_ $ liftIO . writeRef update <$> updated (_inputElement_value e)
503− it "does not fire _input event when the value is updated at postBuild" $ runWD $ do
504− input <- newRef (Nothing :: Maybe Text)
505− let checkStatic = do
506− e <- findElemWithRetry $ WD.ByTag "input"
507− WD.attr e "value" `shouldBeWithRetryM` Just "pb"
509− checkHydrated e = do
510− WD.attr e "value" `shouldBeWithRetryM` Just "pb"
511− readRef input `shouldBeWithRetryM` Nothing
512− testWidget' checkStatic checkHydrated $ do
514− e <- inputElement $ def & inputElementConfig_setValue .~ ("pb" <$ pb)
515− performEvent_ $ liftIO . writeRef input . Just <$> _inputElement_input e
516− it "SSR produces correct DOM based on inputElement values when setValue happens at postBuild" $ runWD $ do
518− input <- findElemWithRetry $ WD.ByTag "input"
519− WD.attr input "value" `shouldBeWithRetryM` Just "pb"
520− p <- findElemWithRetry (WD.ByTag "p")
521− shouldContainText "pb" p
522− testWidget checkBoth checkBoth $ do
524− e <- inputElement $ def & inputElementConfig_setValue .~ ("pb" <$ pb)
525− el "p" $ dynText $ _inputElement_value e
526− it "does not fail when both setValue AND user updated value happen before switchover" $ runWD $ do
527− let checkStatic = do
528− input <- findElemWithRetry $ WD.ByTag "input"
529− h2_value <- findElemWithRetry (WD.ByTag "h2")
530− h3_input <- findElemWithRetry (WD.ByTag "h3")
531− WD.attr input "value" `shouldBeWithRetryM` Just "pb"
532− shouldContainText "pb" h2_value
533− shouldContainText "" h3_input
534− WD.sendKeys "abc" input
535− WD.attr input "value" `shouldBeWithRetryM` Just "pbabc"
536− shouldContainText "pb" h2_value
537− shouldContainText "" h3_input
538− pure (input, h2_value, h3_input)
539− checkHydrated (input, h2_value, h3_input) = do
540− WD.attr input "value" `shouldBeWithRetryM` Just "pbabc"
541− shouldContainText "pbabc" h3_input
542− shouldContainText "pbabc pb" h2_value
544− testWidget' checkStatic checkHydrated $ do
546− e <- inputElement $ def & inputElementConfig_setValue .~ ("pb" <$ pb)
547− el "h1" $ dynText $ _inputElement_value e
548− el "h2" $ dynText . fmap T.unwords <=< foldDyn (:) [] $ updated $ _inputElement_value e
549− el "h3" $ dynText . fmap T.unwords <=< foldDyn (:) [] $ _inputElement_input e
550− it "value is correct when both setValue AND user updated value happen before switchover" $ runWD $ do
551− let checkStatic = do
552− input <- findElemWithRetry $ WD.ByTag "input"
553− p <- findElemWithRetry (WD.ByTag "p")
554− WD.attr input "value" `shouldBeWithRetryM` Just "pb"
555− shouldContainText "pb" p
556− WD.sendKeys "abc" input
557− WD.attr input "value" `shouldBeWithRetryM` Just "pbabc"
558− shouldContainText "pb" p -- It won't be updated yet
560− checkHydrated (input, p) = do
561− WD.attr input "value" `shouldBeWithRetryM` Just "pbabc"
562− shouldContainText "pbabc" p
564− testWidget' checkStatic checkHydrated $ do
566− e <- inputElement $ def & inputElementConfig_setValue .~ ("pb" <$ pb)
567− el "p" $ dynText $ _inputElement_value e
568− it "input event and (updated value) fire correctly when both setValue AND user updated value happen before switchover" $ runWD $ do
569− valRef <- newRef ([] :: [Text])
570− inputRef <- newRef ([] :: [Text])
571− let consRef ref a = liftIO $ atomicModifyRef ref $ \as -> (a:as, ())
573− input <- findElemWithRetry $ WD.ByTag "input"
574− p <- findElemWithRetry (WD.ByTag "p")
575− WD.attr input "value" `shouldBeWithRetryM` Just "pb"
576− shouldContainText "pb" p
577− WD.sendKeys "abc" input
578− WD.attr input "value" `shouldBeWithRetryM` Just "pbabc"
579− shouldContainText "pb" p -- It won't be updated yet
580− readRef inputRef `shouldBeWithRetryM` [] -- Should never fire input ref during SSR
581− readRef valRef `shouldBeWithRetryM` ["pb"]
583− checkHydrated (input, p) = do
584− readRef inputRef `shouldBeWithRetryM` ["pbabc"]
585− readRef valRef `shouldBeWithRetryM` ["pbabc", "pb"]
586− WD.attr input "value" `shouldBeWithRetryM` Just "pbabc"
587− shouldContainText "pbabc" p
589− testWidget' checkStatic checkHydrated $ do
590− liftIO $ writeRef valRef []
592− e <- inputElement $ def & inputElementConfig_setValue .~ ("pb" <$ pb)
593− el "p" $ dynText $ _inputElement_value e
594− performEvent_ $ consRef valRef <$> updated (_inputElement_value e)
595− performEvent_ $ consRef inputRef <$> _inputElement_input e
596− describe "hydration/immediate" $ do
387+ describe "hydration/immediate" $ session' $ do
597 it "captures user input after switchover" $ runWD $ do
388 it "captures user input after switchover" $ runWD $ do
598 inputRef :: IORef Text <- newRef ""
389 inputRef :: IORef Text <- newRef ""
599 let checkValue = do
390 let checkValue = do
600− WD.sendKeys "hello world" =<< findElemWithRetry (WD.ByTag "input")
391+ WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "input"
601− WD.click =<< findElemWithRetry (WD.ByTag "button")
392+ WD.click <=< WD.findElem $ WD.ByTag "button"
602− readRef inputRef `shouldBeWithRetryM` "hello world"
393+ input <- readRef inputRef
394+ input `shouldBe` "hello world"
603 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
395 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
604 e <- inputElement def
396 e <- inputElement def
605 click <- button "save"
397 click <- button "save"
@@ -607,10 +399,11 @@ tests withDebugging wdConfig caps _selenium = do
607 it "sets focus appropriately" $ runWD $ do
399 it "sets focus appropriately" $ runWD $ do
608 focusRef <- newRef False
400 focusRef <- newRef False
609 let checkValue = do
401 let checkValue = do
610− readRef focusRef `shouldBeWithRetryM` False
402+ readRef focusRef >>= flip shouldBe False
611− e <- findElemWithRetry $ WD.ByTag "input"
403+ e <- WD.findElem $ WD.ByTag "input"
612 WD.click e
404 WD.click e
405+ liftIO $ threadDelay 100000
613− readRef focusRef `shouldBeWithRetryM` True
406+ readRef focusRef >>= flip shouldBe True
614 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
407 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
615 e <- inputElement def
408 e <- inputElement def
616 performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
409 performEvent_ $ liftIO . writeRef focusRef <$> updated (_inputElement_hasFocus e)
@@ -619,15 +412,17 @@ tests withDebugging wdConfig caps _selenium = do
619 valueRef :: IORef Text <- newRef ""
412 valueRef :: IORef Text <- newRef ""
620 setValueChan :: Chan Text <- liftIO newChan
413 setValueChan :: Chan Text <- liftIO newChan
621 let checkValue = do
414 let checkValue = do
622− readRef valueByUIRef `shouldBeWithRetryM` ""
415+ readRef valueByUIRef >>= flip shouldBe ""
623− readRef valueRef `shouldBeWithRetryM` ""
416+ readRef valueRef >>= flip shouldBe ""
624− e <- findElemWithRetry $ WD.ByTag "input"
417+ e <- WD.findElem $ WD.ByTag "input"
625 WD.sendKeys "hello" e
418 WD.sendKeys "hello" e
419+ liftIO $ threadDelay 100000
626− readRef valueByUIRef `shouldBeWithRetryM` "hello"
420+ readRef valueByUIRef >>= flip shouldBe "hello"
627− readRef valueRef `shouldBeWithRetryM` "hello"
421+ readRef valueRef >>= flip shouldBe "hello"
628 liftIO $ writeChan setValueChan "world"
422 liftIO $ writeChan setValueChan "world"
423+ liftIO $ threadDelay 100000
629− readRef valueByUIRef `shouldBeWithRetryM` "hello"
424+ readRef valueByUIRef >>= flip shouldBe "hello"
630− readRef valueRef `shouldBeWithRetryM` "world"
425+ readRef valueRef >>= flip shouldBe "world"
631 testWidget (pure ()) checkValue $ do
426 testWidget (pure ()) checkValue $ do
632 update <- triggerEventWithChan setValueChan
427 update <- triggerEventWithChan setValueChan
633 prerender_ (pure ()) $ do
428 prerender_ (pure ()) $ do
@@ -639,16 +434,18 @@ tests withDebugging wdConfig caps _selenium = do
639 checkedRef <- newRef False
434 checkedRef <- newRef False
640 setCheckedChan <- liftIO newChan
435 setCheckedChan <- liftIO newChan
641 let checkValue = do
436 let checkValue = do
642− readRef checkedByUIRef `shouldBeWithRetryM` False
437+ readRef checkedByUIRef >>= flip shouldBe False
643− readRef checkedRef `shouldBeWithRetryM` False
438+ readRef checkedRef >>= flip shouldBe False
644− e <- findElemWithRetry $ WD.ByTag "input"
439+ e <- WD.findElem $ WD.ByTag "input"
645 WD.moveToCenter e
440 WD.moveToCenter e
646 WD.click e
441 WD.click e
442+ liftIO $ threadDelay 100000
647− readRef checkedByUIRef `shouldBeWithRetryM` True
443+ readRef checkedByUIRef >>= flip shouldBe True
648− readRef checkedRef `shouldBeWithRetryM` True
444+ readRef checkedRef >>= flip shouldBe True
649 liftIO $ writeChan setCheckedChan False
445 liftIO $ writeChan setCheckedChan False
446+ liftIO $ threadDelay 100000
650− readRef checkedByUIRef `shouldBeWithRetryM` True
447+ readRef checkedByUIRef >>= flip shouldBe True
651− readRef checkedRef `shouldBeWithRetryM` False
448+ readRef checkedRef >>= flip shouldBe False
652 testWidget (pure ()) checkValue $ do
449 testWidget (pure ()) checkValue $ do
653 setChecked <- triggerEventWithChan setCheckedChan
450 setChecked <- triggerEventWithChan setCheckedChan
654 prerender_ (pure ()) $ do
451 prerender_ (pure ()) $ do
@@ -660,12 +457,13 @@ tests withDebugging wdConfig caps _selenium = do
660 it "captures file uploads" $ runWD $ do
457 it "captures file uploads" $ runWD $ do
661 filesRef :: IORef [Text] <- newRef []
458 filesRef :: IORef [Text] <- newRef []
662 let uploadFile = do
459 let uploadFile = do
663− e <- findElemWithRetry $ WD.ByTag "input"
460+ e <- WD.findElem $ WD.ByTag "input"
664 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
461 path <- liftIO $ writeSystemTempFile "testFile" "file contents"
665 WD.sendKeys (T.pack path) e
462 WD.sendKeys (T.pack path) e
666− WD.click =<< findElemWithRetry (WD.ByTag "button")
463+ WD.click <=< WD.findElem $ WD.ByTag "button"
667 liftIO $ removeFile path
464 liftIO $ removeFile path
465+ input <- liftIO $ readRef filesRef
668− readRef filesRef `shouldBeWithRetryM` [T.pack $ FilePath.takeFileName path]
466+ input `shouldBe` [T.pack $ FilePath.takeFileName path]
669 testWidget (pure ()) uploadFile $ prerender_ (pure ()) $ do
467 testWidget (pure ()) uploadFile $ prerender_ (pure ()) $ do
670 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
468 e <- inputElement $ def & initialAttributes .~ "type" =: "file"
671 click <- button "save"
469 click <- button "save"
@@ -673,42 +471,21 @@ tests withDebugging wdConfig caps _selenium = do
673 names <- liftJSM $ traverse File.getName fs
471 names <- liftJSM $ traverse File.getName fs
674 liftIO $ writeRef filesRef names
472 liftIO $ writeRef filesRef names
676− session' "textAreaElement" $ do
474+ describe "textAreaElement" $ do
677− describe "static renderer" $ do
678− it "sets value attribute" $ runWD $ do
679− let checkStatic = do
680− e <- findElemWithRetry $ WD.ByTag "textarea"
681− WD.attr e "value" `shouldBeWithRetryM` Just "test"
683− checkHydrated e = do
684− WD.attr e "value" `shouldBeWithRetryM` Just "test"
685− testWidget' checkStatic checkHydrated $ void $ textAreaElement $ def
686− & textAreaElementConfig_initialValue .~ "test"
687− it "updates value attribute at postBuild" $ runWD $ do
688− let checkStatic = do
689− e <- findElemWithRetry $ WD.ByTag "textarea"
690− WD.attr e "value" `shouldBeWithRetryM` Just "test-updated"
692− checkHydrated e = do
693− WD.attr e "value" `shouldBeWithRetryM` Just "test-updated"
694− testWidget' checkStatic checkHydrated $ do
696− _ <- textAreaElement $ def
697− & textAreaElementConfig_initialValue .~ "test"
698− & textAreaElementConfig_setValue .~ ("test-updated" <$ pb)
700− describe "hydration" $ do
475+ describe "hydration" $ session' $ do
701 it "doesn't wipe user input when switching over" $ runWD $ do
476 it "doesn't wipe user input when switching over" $ runWD $ do
702 inputRef <- newRef ("" :: Text)
477 inputRef <- newRef ("" :: Text)
703 testWidget'
478 testWidget'
705− e <- findElemWithRetry $ WD.ByTag "textarea"
480+ e <- WD.findElem $ WD.ByTag "textarea"
706 WD.sendKeys "hello world" e
481 WD.sendKeys "hello world" e
708 (\e -> do
483 (\e -> do
709− WD.attr e "value" `shouldBeWithRetryM` Just "hello world"
484+ t <- WD.attr e "value"
485+ t `shouldBe` Just "hello world"
710− WD.click <=< findElemWithRetry $ WD.ByTag "button"
486+ WD.click <=< WD.findElem $ WD.ByTag "button"
711− readRef inputRef `shouldBeWithRetryM` "hello world"
487+ input <- readRef inputRef
488+ input `shouldBe` "hello world"
713 e <- textAreaElement def
490 e <- textAreaElement def
714 click <- button "save"
491 click <- button "save"
@@ -716,9 +493,10 @@ tests withDebugging wdConfig caps _selenium = do
716 it "captures user input after switchover" $ runWD $ do
493 it "captures user input after switchover" $ runWD $ do
717 inputRef <- newRef ("" :: Text)
494 inputRef <- newRef ("" :: Text)
718 let checkValue = do
495 let checkValue = do
719− WD.sendKeys "hello world" =<< findElemWithRetry (WD.ByTag "textarea")
496+ WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "textarea"
720− WD.click =<< findElemWithRetry (WD.ByTag "button")
497+ WD.click <=< WD.findElem $ WD.ByTag "button"
721− readRef inputRef `shouldBeWithRetryM` "hello world"
498+ input <- readRef inputRef
499+ input `shouldBe` "hello world"
722 testWidget (pure ()) checkValue $ do
500 testWidget (pure ()) checkValue $ do
723 e <- textAreaElement def
501 e <- textAreaElement def
724 click <- button "save"
502 click <- button "save"
@@ -726,21 +504,23 @@ tests withDebugging wdConfig caps _selenium = do
726 it "sets focus appropriately" $ runWD $ do
504 it "sets focus appropriately" $ runWD $ do
727 focusRef <- newRef False
505 focusRef <- newRef False
728 let checkValue = do
506 let checkValue = do
729− readRef focusRef `shouldBeWithRetryM` False
507+ readRef focusRef >>= flip shouldBe False
730− e <- findElemWithRetry $ WD.ByTag "textarea"
508+ e <- WD.findElem $ WD.ByTag "textarea"
731 WD.click e
509 WD.click e
510+ liftIO $ threadDelay 100000
732− readRef focusRef `shouldBeWithRetryM` True
511+ readRef focusRef >>= flip shouldBe True
733 testWidget (pure ()) checkValue $ do
512 testWidget (pure ()) checkValue $ do
734 e <- textAreaElement def
513 e <- textAreaElement def
735 performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
514 performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
736 it "sets focus when focus occurs before hydration" $ runWD $ do
515 it "sets focus when focus occurs before hydration" $ runWD $ do
737 focusRef <- newRef False
516 focusRef <- newRef False
738 let setup = do
517 let setup = do
739− e <- findElemWithRetry $ WD.ByTag "textarea"
518+ e <- WD.findElem $ WD.ByTag "textarea"
740 WD.click e
519 WD.click e
741− ((== e) <$> WD.activeElem) `shouldBeWithRetryM` True
520+ hasFocus <- (== e) <$> WD.activeElem
521+ hasFocus `shouldBe` True
742− readRef focusRef `shouldBeWithRetryM` False
522+ readRef focusRef >>= flip shouldBe False
743− check = readRef focusRef `shouldBeWithRetryM` True
523+ check = readRef focusRef >>= flip shouldBe True
744 testWidget setup check $ do
524 testWidget setup check $ do
745 e <- textAreaElement def
525 e <- textAreaElement def
746 performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
526 performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
@@ -749,110 +529,31 @@ tests withDebugging wdConfig caps _selenium = do
749 valueRef <- newRef ("" :: Text)
529 valueRef <- newRef ("" :: Text)
750 setValueChan :: Chan Text <- liftIO newChan
530 setValueChan :: Chan Text <- liftIO newChan
751 let checkValue = do
531 let checkValue = do
752− readRef valueByUIRef `shouldBeWithRetryM` ""
532+ readRef valueByUIRef >>= flip shouldBe ""
753− readRef valueRef `shouldBeWithRetryM` ""
533+ readRef valueRef >>= flip shouldBe ""
754− e <- findElemWithRetry $ WD.ByTag "textarea"
534+ e <- WD.findElem $ WD.ByTag "textarea"
755 WD.sendKeys "hello" e
535 WD.sendKeys "hello" e
536+ liftIO $ threadDelay 100000
756− readRef valueByUIRef `shouldBeWithRetryM` "hello"
537+ readRef valueByUIRef >>= flip shouldBe "hello"
757− readRef valueRef `shouldBeWithRetryM` "hello"
538+ readRef valueRef >>= flip shouldBe "hello"
758 liftIO $ writeChan setValueChan "world"
539 liftIO $ writeChan setValueChan "world"
540+ liftIO $ threadDelay 100000
759− readRef valueByUIRef `shouldBeWithRetryM` "hello"
541+ readRef valueByUIRef >>= flip shouldBe "hello"
760− readRef valueRef `shouldBeWithRetryM` "world"
542+ readRef valueRef >>= flip shouldBe "world"
761 testWidget (pure ()) checkValue $ do
543 testWidget (pure ()) checkValue $ do
762 setValue' <- triggerEventWithChan setValueChan
544 setValue' <- triggerEventWithChan setValueChan
763 e <- textAreaElement $ def { _textAreaElementConfig_setValue = Just setValue' }
545 e <- textAreaElement $ def { _textAreaElementConfig_setValue = Just setValue' }
764 performEvent_ $ liftIO . writeRef valueByUIRef <$> _textAreaElement_input e
546 performEvent_ $ liftIO . writeRef valueByUIRef <$> _textAreaElement_input e
765 performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
547 performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
766− it "fires _input event if the user altered the value before hydration" $ runWD $ do
767− textarea <- newRef ("" :: Text)
768− update <- newRef ("" :: Text)
769− let checkStatic = do
770− e <- findElemWithRetry $ WD.ByTag "textarea"
771− WD.attr e "value" `shouldBeWithRetryM` Just ""
772− WD.sendKeys "test" e
773− WD.attr e "value" `shouldBeWithRetryM` Just "test"
775− checkHydrated e = do
776− WD.attr e "value" `shouldBeWithRetryM` Just "test"
777− readRef textarea `shouldBeWithRetryM` "test"
778− readRef update `shouldBeWithRetryM` "test"
779− testWidget' checkStatic checkHydrated $ do
780− e <- textAreaElement def
781− performEvent_ $ liftIO . writeRef textarea <$> _textAreaElement_input e
782− performEvent_ $ liftIO . writeRef update <$> updated (_textAreaElement_value e)
783− it "does not fire _input event when the value is updated at postBuild" $ runWD $ do
784− textarea <- newRef (Nothing :: Maybe Text)
785− let checkStatic = do
786− e <- findElemWithRetry $ WD.ByTag "textarea"
787− WD.attr e "value" `shouldBeWithRetryM` Just "pb"
789− checkHydrated e = do
790− WD.attr e "value" `shouldBeWithRetryM` Just "pb"
791− readRef textarea `shouldBeWithRetryM` Nothing
792− testWidget' checkStatic checkHydrated $ do
794− e <- textAreaElement $ def & textAreaElementConfig_setValue .~ ("pb" <$ pb)
795− performEvent_ $ liftIO . writeRef textarea . Just <$> _textAreaElement_input e
796− it "SSR produces correct DOM based on textAreaElement values when setValue happens at postBuild" $ runWD $ do
798− textarea <- findElemWithRetry $ WD.ByTag "textarea"
799− WD.attr textarea "value" `shouldBeWithRetryM` Just "pb"
800− p <- findElemWithRetry (WD.ByTag "p")
801− shouldContainText "pb" p
802− testWidget checkBoth checkBoth $ do
804− e <- textAreaElement $ def & textAreaElementConfig_setValue .~ ("pb" <$ pb)
805− el "p" $ dynText $ _textAreaElement_value e
806− it "does not fail when both setValue AND user updated value happen before switchover" $ runWD $ do
807− let checkStatic = do
808− textarea <- findElemWithRetry $ WD.ByTag "textarea"
809− h2_value <- findElemWithRetry (WD.ByTag "h2")
810− h3_input <- findElemWithRetry (WD.ByTag "h3")
811− WD.attr textarea "value" `shouldBeWithRetryM` Just "pb"
812− shouldContainText "pb" h2_value
813− shouldContainText "" h3_input
814− WD.sendKeys "abc" textarea
815− WD.attr textarea "value" `shouldBeWithRetryM` Just "pbabc"
816− shouldContainText "pb" h2_value
817− shouldContainText "" h3_input
818− pure (textarea, h2_value, h3_input)
819− checkHydrated (textarea, h2_value, h3_input) = do
820− WD.attr textarea "value" `shouldBeWithRetryM` Just "pbabc"
821− shouldContainText "pbabc" h3_input
822− shouldContainText "pbabc pb" h2_value
824− testWidget' checkStatic checkHydrated $ do
826− e <- textAreaElement $ def & textAreaElementConfig_setValue .~ ("pb" <$ pb)
827− el "h1" $ dynText $ _textAreaElement_value e
828− el "h2" $ dynText . fmap T.unwords <=< foldDyn (:) [] $ updated $ _textAreaElement_value e
829− el "h3" $ dynText . fmap T.unwords <=< foldDyn (:) [] $ _textAreaElement_input e
830− it "value is correct when both setValue AND user updated value happen before switchover" $ runWD $ do
831− let checkStatic = do
832− textarea <- findElemWithRetry $ WD.ByTag "textarea"
833− p <- findElemWithRetry (WD.ByTag "p")
834− WD.attr textarea "value" `shouldBeWithRetryM` Just "pb"
835− shouldContainText "pb" p
836− WD.sendKeys "abc" textarea
837− WD.attr textarea "value" `shouldBeWithRetryM` Just "pbabc"
838− shouldContainText "pb" p -- It won't be updated yet
840− checkHydrated (textarea, p) = do
841− WD.attr textarea "value" `shouldBeWithRetryM` Just "pbabc"
842− shouldContainText "pbabc" p
844− testWidget' checkStatic checkHydrated $ do
846− e <- textAreaElement $ def & textAreaElementConfig_setValue .~ ("pb" <$ pb)
847− el "p" $ dynText $ _textAreaElement_value e
849− describe "hydration/immediate" $ do
549+ describe "hydration/immediate" $ session' $ do
850 it "captures user input after switchover" $ runWD $ do
550 it "captures user input after switchover" $ runWD $ do
851 inputRef :: IORef Text <- newRef ""
551 inputRef :: IORef Text <- newRef ""
852 let checkValue = do
552 let checkValue = do
853− WD.sendKeys "hello world" <=< findElemWithRetry $ WD.ByTag "textarea"
553+ WD.sendKeys "hello world" <=< WD.findElem $ WD.ByTag "textarea"
854− WD.click <=< findElemWithRetry $ WD.ByTag "button"
554+ WD.click <=< WD.findElem $ WD.ByTag "button"
855− readRef inputRef `shouldBeWithRetryM` "hello world"
555+ input <- liftIO $ readRef inputRef
556+ input `shouldBe` "hello world"
856 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
557 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
857 e <- textAreaElement def
558 e <- textAreaElement def
858 click <- button "save"
559 click <- button "save"
@@ -860,10 +561,11 @@ tests withDebugging wdConfig caps _selenium = do
860 it "sets focus appropriately" $ runWD $ do
561 it "sets focus appropriately" $ runWD $ do
861 focusRef <- newRef False
562 focusRef <- newRef False
862 let checkValue = do
563 let checkValue = do
863− readRef focusRef `shouldBeWithRetryM` False
564+ readRef focusRef >>= flip shouldBe False
864− e <- findElemWithRetry $ WD.ByTag "textarea"
565+ e <- WD.findElem $ WD.ByTag "textarea"
865 WD.click e
566 WD.click e
567+ liftIO $ threadDelay 100000
866− readRef focusRef `shouldBeWithRetryM` True
568+ readRef focusRef >>= flip shouldBe True
867 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
569 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
868 e <- textAreaElement def
570 e <- textAreaElement def
869 performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
571 performEvent_ $ liftIO . writeRef focusRef <$> updated (_textAreaElement_hasFocus e)
@@ -872,15 +574,17 @@ tests withDebugging wdConfig caps _selenium = do
872 valueRef :: IORef Text <- newRef ""
574 valueRef :: IORef Text <- newRef ""
873 setValueChan :: Chan Text <- liftIO newChan
575 setValueChan :: Chan Text <- liftIO newChan
874 let checkValue = do
576 let checkValue = do
875− readRef valueByUIRef `shouldBeWithRetryM` ""
577+ readRef valueByUIRef >>= flip shouldBe ""
876− readRef valueRef `shouldBeWithRetryM` ""
578+ readRef valueRef >>= flip shouldBe ""
877− e <- findElemWithRetry $ WD.ByTag "textarea"
579+ e <- WD.findElem $ WD.ByTag "textarea"
878 WD.sendKeys "hello" e
580 WD.sendKeys "hello" e
581+ liftIO $ threadDelay 100000
879− readRef valueByUIRef `shouldBeWithRetryM` "hello"
582+ readRef valueByUIRef >>= flip shouldBe "hello"
880− readRef valueRef `shouldBeWithRetryM` "hello"
583+ readRef valueRef >>= flip shouldBe "hello"
881 liftIO $ writeChan setValueChan "world"
584 liftIO $ writeChan setValueChan "world"
585+ liftIO $ threadDelay 100000
882− readRef valueByUIRef `shouldBeWithRetryM` "hello"
586+ readRef valueByUIRef >>= flip shouldBe "hello"
883− readRef valueRef `shouldBeWithRetryM` "world"
587+ readRef valueRef >>= flip shouldBe "world"
884 testWidget (pure ()) checkValue $ do
588 testWidget (pure ()) checkValue $ do
885 setValue' <- triggerEventWithChan setValueChan
589 setValue' <- triggerEventWithChan setValueChan
886 prerender_ (pure ()) $ do
590 prerender_ (pure ()) $ do
@@ -888,26 +592,26 @@ tests withDebugging wdConfig caps _selenium = do
888 performEvent_ $ liftIO . writeRef valueByUIRef <$> _textAreaElement_input e
592 performEvent_ $ liftIO . writeRef valueByUIRef <$> _textAreaElement_input e
889 performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
593 performEvent_ $ liftIO . writeRef valueRef <$> updated (value e)
891− session' "selectElement" $ do
595+ describe "selectElement" $ do
892 let options :: DomBuilder t m => m ()
596 let options :: DomBuilder t m => m ()
893 options = do
597 options = do
894 elAttr "option" ("value" =: "one" <> "id" =: "one") $ text "one"
598 elAttr "option" ("value" =: "one" <> "id" =: "one") $ text "one"
895 elAttr "option" ("value" =: "two" <> "id" =: "two") $ text "two"
599 elAttr "option" ("value" =: "two" <> "id" =: "two") $ text "two"
896 elAttr "option" ("value" =: "three" <> "id" =: "three") $ text "three"
600 elAttr "option" ("value" =: "three" <> "id" =: "three") $ text "three"
897− describe "hydration" $ do
601+ describe "hydration" $ session' $ do
898 it "sets initial value correctly" $ runWD $ do
602 it "sets initial value correctly" $ runWD $ do
899 inputRef <- newRef ("" :: Text)
603 inputRef <- newRef ("" :: Text)
900 let setup = do
604 let setup = do
901− e <- findElemWithRetry $ WD.ByTag "select"
605+ e <- WD.findElem $ WD.ByTag "select"
902 assertAttr e "value" (Just "three")
606 assertAttr e "value" (Just "three")
903− WD.click =<< findElemWithRetry (WD.ById "two")
607+ WD.click <=< WD.findElem $ WD.ById "two"
905 check e = do
609 check e = do
906 assertAttr e "value" (Just "two")
610 assertAttr e "value" (Just "two")
907− readRef inputRef `shouldBeWithRetryM` "three"
611+ readRef inputRef >>= (`shouldBe` "three")
908− WD.click =<< findElemWithRetry (WD.ByTag "button")
612+ WD.click <=< WD.findElem $ WD.ByTag "button"
909 assertAttr e "value" (Just "two")
613 assertAttr e "value" (Just "two")
910− readRef inputRef `shouldBeWithRetryM` "two"
614+ readRef inputRef >>= (`shouldBe` "two")
911 testWidget' setup check $ do
615 testWidget' setup check $ do
912 (e, ()) <- selectElement (def { _selectElementConfig_initialValue = "three" }) options
616 (e, ()) <- selectElement (def { _selectElementConfig_initialValue = "three" }) options
913 click <- button "save"
617 click <- button "save"
@@ -916,12 +620,12 @@ tests withDebugging wdConfig caps _selenium = do
916 it "captures user input after switchover" $ runWD $ do
620 it "captures user input after switchover" $ runWD $ do
917 inputRef <- newRef ("" :: Text)
621 inputRef <- newRef ("" :: Text)
918 let checkValue = do
622 let checkValue = do
919− e <- findElemWithRetry $ WD.ByTag "select"
623+ e <- WD.findElem $ WD.ByTag "select"
920 assertAttr e "value" (Just "one")
624 assertAttr e "value" (Just "one")
921− WD.click =<< findElemWithRetry (WD.ById "two")
625+ WD.click <=< WD.findElem $ WD.ById "two"
922 assertAttr e "value" (Just "two")
626 assertAttr e "value" (Just "two")
923− WD.click =<< findElemWithRetry (WD.ByTag "button")
627+ WD.click <=< WD.findElem $ WD.ByTag "button"
924− readRef inputRef `shouldBeWithRetryM` "two"
628+ readRef inputRef >>= (`shouldBe` "two")
925 testWidget (pure ()) checkValue $ do
629 testWidget (pure ()) checkValue $ do
926 (e, ()) <- selectElement def options
630 (e, ()) <- selectElement def options
927 click <- button "save"
631 click <- button "save"
@@ -929,21 +633,23 @@ tests withDebugging wdConfig caps _selenium = do
929 it "sets focus appropriately" $ runWD $ do
633 it "sets focus appropriately" $ runWD $ do
930 focusRef <- newRef False
634 focusRef <- newRef False
931 let checkValue = do
635 let checkValue = do
932− readRef focusRef `shouldBeWithRetryM` False
636+ readRef focusRef >>= flip shouldBe False
933− e <- findElemWithRetry $ WD.ByTag "select"
637+ e <- WD.findElem $ WD.ByTag "select"
934 WD.click e
638 WD.click e
639+ liftIO $ threadDelay 100000
935− readRef focusRef `shouldBeWithRetryM` True
640+ readRef focusRef >>= flip shouldBe True
936 testWidget (pure ()) checkValue $ do
641 testWidget (pure ()) checkValue $ do
937 (e, ()) <- selectElement def options
642 (e, ()) <- selectElement def options
938 performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
643 performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
939 it "sets focus when focus occurs before hydration" $ runWD $ do
644 it "sets focus when focus occurs before hydration" $ runWD $ do
940 focusRef <- newRef False
645 focusRef <- newRef False
941 let setup = do
646 let setup = do
942− e <- findElemWithRetry $ WD.ByTag "select"
647+ e <- WD.findElem $ WD.ByTag "select"
943 WD.click e
648 WD.click e
944− ((== e) <$> WD.activeElem) `shouldBeWithRetryM` True
649+ hasFocus <- (== e) <$> WD.activeElem
650+ hasFocus `shouldBe` True
945− readRef focusRef `shouldBeWithRetryM` False
651+ readRef focusRef >>= flip shouldBe False
946− check = readRef focusRef `shouldBeWithRetryM` True
652+ check = readRef focusRef >>= flip shouldBe True
947 testWidget setup check $ do
653 testWidget setup check $ do
948 (e, ()) <- selectElement def options
654 (e, ()) <- selectElement def options
949 performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
655 performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
@@ -952,29 +658,31 @@ tests withDebugging wdConfig caps _selenium = do
952 valueRef <- newRef ("" :: Text)
658 valueRef <- newRef ("" :: Text)
953 setValueChan :: Chan Text <- liftIO newChan
659 setValueChan :: Chan Text <- liftIO newChan
954 let checkValue = do
660 let checkValue = do
955− e <- findElemWithRetry $ WD.ByTag "select"
661+ e <- WD.findElem $ WD.ByTag "select"
956 assertAttr e "value" (Just "one")
662 assertAttr e "value" (Just "one")
957− readRef valueByUIRef `shouldBeWithRetryM` "one"
663+ readRef valueByUIRef >>= flip shouldBe "one"
958− readRef valueRef `shouldBeWithRetryM` "one"
664+ readRef valueRef >>= flip shouldBe "one"
959− WD.click <=< findElemWithRetry $ WD.ById "two"
665+ WD.click <=< WD.findElem $ WD.ById "two"
666+ liftIO $ threadDelay 100000
960− readRef valueByUIRef `shouldBeWithRetryM` "two"
667+ readRef valueByUIRef >>= flip shouldBe "two"
961− readRef valueRef `shouldBeWithRetryM` "two"
668+ readRef valueRef >>= flip shouldBe "two"
962 liftIO $ writeChan setValueChan "three"
669 liftIO $ writeChan setValueChan "three"
670+ liftIO $ threadDelay 100000
963− readRef valueByUIRef `shouldBeWithRetryM` "two"
671+ readRef valueByUIRef >>= flip shouldBe "two"
964− readRef valueRef `shouldBeWithRetryM` "three"
672+ readRef valueRef >>= flip shouldBe "three"
965 testWidget (pure ()) checkValue $ do
673 testWidget (pure ()) checkValue $ do
966 setValue' <- triggerEventWithChan setValueChan
674 setValue' <- triggerEventWithChan setValueChan
967 (e, ()) <- selectElement def { _selectElementConfig_setValue = Just setValue' } options
675 (e, ()) <- selectElement def { _selectElementConfig_setValue = Just setValue' } options
968 performEvent_ $ liftIO . writeRef valueByUIRef <$> _selectElement_change e
676 performEvent_ $ liftIO . writeRef valueByUIRef <$> _selectElement_change e
969 performEvent_ $ liftIO . writeRef valueRef <$> updated (_selectElement_value e)
677 performEvent_ $ liftIO . writeRef valueRef <$> updated (_selectElement_value e)
971− describe "hydration/immediate" $ do
679+ describe "hydration/immediate" $ session' $ do
972 it "captures user input after switchover" $ runWD $ do
680 it "captures user input after switchover" $ runWD $ do
973 inputRef :: IORef Text <- newRef ""
681 inputRef :: IORef Text <- newRef ""
974 let checkValue = do
682 let checkValue = do
975− WD.click <=< findElemWithRetry $ WD.ById "two"
683+ WD.click <=< WD.findElem $ WD.ById "two"
976− WD.click <=< findElemWithRetry $ WD.ByTag "button"
684+ WD.click <=< WD.findElem $ WD.ByTag "button"
977− readRef inputRef `shouldBeWithRetryM` "two"
685+ readRef inputRef >>= flip shouldBe "two"
978 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
686 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
979 (e, ()) <- selectElement def options
687 (e, ()) <- selectElement def options
980 click <- button "save"
688 click <- button "save"
@@ -982,16 +690,17 @@ tests withDebugging wdConfig caps _selenium = do
982 it "sets focus appropriately" $ runWD $ do
690 it "sets focus appropriately" $ runWD $ do
983 focusRef <- newRef False
691 focusRef <- newRef False
984 let checkValue = do
692 let checkValue = do
985− readRef focusRef `shouldBeWithRetryM` False
693+ readRef focusRef >>= flip shouldBe False
986− e <- findElemWithRetry $ WD.ByTag "select"
694+ e <- WD.findElem $ WD.ByTag "select"
987 WD.click e
695 WD.click e
696+ liftIO $ threadDelay 100000
988− readRef focusRef `shouldBeWithRetryM` True
697+ readRef focusRef >>= flip shouldBe True
989 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
698 testWidget (pure ()) checkValue $ prerender_ (pure ()) $ do
990 (e, ()) <- selectElement def options
699 (e, ()) <- selectElement def options
991 performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
700 performEvent_ $ liftIO . writeRef focusRef <$> updated (_selectElement_hasFocus e)
992 it "has correct initial value" $ runWD $ do
701 it "has correct initial value" $ runWD $ do
993 valueRef :: IORef Text <- newRef ""
702 valueRef :: IORef Text <- newRef ""
994− let checkValue = readRef valueRef `shouldBeWithRetryM` "one"
703+ let checkValue = readRef valueRef >>= flip shouldBe "one"
995 testWidget (pure ()) checkValue $ do
704 testWidget (pure ()) checkValue $ do
996 prerender_ (pure ()) $ do
705 prerender_ (pure ()) $ do
997 (e, ()) <- selectElement def { _selectElementConfig_initialValue = "one" } options
706 (e, ()) <- selectElement def { _selectElementConfig_initialValue = "one" } options
@@ -1001,12 +710,14 @@ tests withDebugging wdConfig caps _selenium = do
1001 valueRef :: IORef Text <- newRef ""
710 valueRef :: IORef Text <- newRef ""
1002 setValueChan :: Chan Text <- liftIO newChan
711 setValueChan :: Chan Text <- liftIO newChan
1003 let checkValue = do
712 let checkValue = do
1004− WD.click =<< findElemWithRetry (WD.ById "two")
713+ WD.click <=< WD.findElem $ WD.ById "two"
714+ liftIO $ threadDelay 100000
1005− readRef valueByUIRef `shouldBeWithRetryM` "two"
715+ readRef valueByUIRef >>= flip shouldBe "two"
1006− readRef valueRef `shouldBeWithRetryM` "two"
716+ readRef valueRef >>= flip shouldBe "two"
1007 liftIO $ writeChan setValueChan "three"
717 liftIO $ writeChan setValueChan "three"
718+ liftIO $ threadDelay 100000
1008− readRef valueByUIRef `shouldBeWithRetryM` "two"
719+ readRef valueByUIRef >>= flip shouldBe "two"
1009− readRef valueRef `shouldBeWithRetryM` "three"
720+ readRef valueRef >>= flip shouldBe "three"
1010 testWidget (pure ()) checkValue $ do
721 testWidget (pure ()) checkValue $ do
1011 setValue' <- triggerEventWithChan setValueChan
722 setValue' <- triggerEventWithChan setValueChan
1012 prerender_ (pure ()) $ do
723 prerender_ (pure ()) $ do
@@ -1014,12 +725,12 @@ tests withDebugging wdConfig caps _selenium = do
1014 performEvent_ $ liftIO . writeRef valueByUIRef <$> _selectElement_change e
725 performEvent_ $ liftIO . writeRef valueByUIRef <$> _selectElement_change e
1015 performEvent_ $ liftIO . writeRef valueRef <$> updated (_selectElement_value e)
726 performEvent_ $ liftIO . writeRef valueRef <$> updated (_selectElement_value e)
1017− session' "prerender" $ do
728+ describe "prerender" $ session' $ do
1018 it "works in simple case" $ runWD $ do
729 it "works in simple case" $ runWD $ do
1019 testWidget (checkBodyText "One") (checkBodyText "Two") $ do
730 testWidget (checkBodyText "One") (checkBodyText "Two") $ do
1020 prerender_ (text "One") (text "Two")
731 prerender_ (text "One") (text "Two")
1021 it "removes element correctly" $ runWD $ do
732 it "removes element correctly" $ runWD $ do
1022− testWidget' (findElemWithRetry $ WD.ByTag "span") elementShouldBeRemoved $ do
733+ testWidget' (WD.findElem $ WD.ByTag "span") elementShouldBeRemoved $ do
1023 prerender_ (el "span" $ text "One") (text "Two")
734 prerender_ (el "span" $ text "One") (text "Two")
1024 it "can be nested in server widget" $ runWD $ do
735 it "can be nested in server widget" $ runWD $ do
1025 testWidget (checkBodyText "One") (checkBodyText "Three") $ do
736 testWidget (checkBodyText "One") (checkBodyText "Three") $ do
@@ -1059,9 +770,9 @@ tests withDebugging wdConfig caps _selenium = do
1059 pb <- getPostBuild
770 pb <- getPostBuild
1060 performEvent_ $ liftIO (putMVar lock ()) <$ pb
771 performEvent_ $ liftIO (putMVar lock ()) <$ pb
1061 it "result Dynamic is updated *after* switchover" $ runWD $ do
772 it "result Dynamic is updated *after* switchover" $ runWD $ do
1062− let preSwitchover = checkBodyText "PostBuild"
773+ let static = shouldContainText "PostBuild" =<< WD.findElem (WD.ByTag "body")
1063− check = checkBodyText "Client"
774+ check = shouldContainText "Client" =<< WD.findElem (WD.ByTag "body")
1064− testWidget preSwitchover check $ void $ do
775+ testWidget static check $ void $ do
1065 d <- prerender (pure "Initial") (pure "Client")
776 d <- prerender (pure "Initial") (pure "Client")
1066 pb <- getPostBuild
777 pb <- getPostBuild
1067 initial <- sample $ current d
778 initial <- sample $ current d
@@ -1069,39 +780,32 @@ tests withDebugging wdConfig caps _selenium = do
1069 -- This essentially checks that the client IO runs *after* switchover/postBuild,
780 -- This essentially checks that the client IO runs *after* switchover/postBuild,
1070 -- thus can't create conflicting DOM
781 -- thus can't create conflicting DOM
1071 it "can't exploit IO to break hydration" $ runWD $ do
782 it "can't exploit IO to break hydration" $ runWD $ do
1072− let preSwitchover = checkBodyText "Initial"
783+ let static = shouldContainText "Initial" =<< WD.findElem (WD.ByTag "body")
1073− testWidgetStatic preSwitchover $ void $ do
784+ testWidgetStatic static $ void $ do
1074 ref <- liftIO $ newRef "Initial"
785 ref <- liftIO $ newRef "Initial"
1075 prerender_ (pure ()) (liftIO $ writeRef ref "Client")
786 prerender_ (pure ()) (liftIO $ writeRef ref "Client")
1076 text <=< liftIO $ readRef ref
787 text <=< liftIO $ readRef ref
1077 -- As above, so below
788 -- As above, so below
1078 it "can't exploit triggerEvent to break hydration" $ runWD $ do
789 it "can't exploit triggerEvent to break hydration" $ runWD $ do
1079− let preSwitchover = checkBodyText "Initial"
790+ let static = shouldContainText "Initial" =<< WD.findElem (WD.ByTag "body")
1080− check = checkBodyText "Client"
791+ check = shouldContainText "Client" =<< WD.findElem (WD.ByTag "body")
1081− testWidget preSwitchover check $ void $ do
792+ testWidget static check $ void $ do
1082 (e, trigger) <- newTriggerEvent
793 (e, trigger) <- newTriggerEvent
1083 prerender_ (pure ()) (liftIO $ trigger "Client")
794 prerender_ (pure ()) (liftIO $ trigger "Client")
1084 textNode $ TextNodeConfig "Initial" $ Just e
795 textNode $ TextNodeConfig "Initial" $ Just e
1086− session' "namespaces" $ do
1087− it "dyn can be nested in namespaced widget" $ runWD $ do
1088− testWidget (pure ()) (checkTextInTag "svg" "one") $ do
1089− let svgRootCfg = def
1090− & (elementConfig_namespace ?~ "http://www.w3.org/2000/svg")
1091− & (elementConfig_initialAttributes .~ ("width" =: "100%" <> "height" =: "100%" <> "viewBox" =: "0 0 1536 2048"))
1092− void $ element "svg" svgRootCfg $ do
1093− dyn_ $ text "one" <$ pure ()
1095− session' "runWithReplace" $ do
797+ describe "runWithReplace" $ session' $ do
1096 it "works" $ runWD $ do
798 it "works" $ runWD $ do
1097 replaceChan :: Chan Text <- liftIO newChan
799 replaceChan :: Chan Text <- liftIO newChan
1098− let setup = findElemWithRetry $ WD.ByTag "div"
800+ let setup = WD.findElem $ WD.ByTag "div"
1099 check ssr = do
801 check ssr = do
1100 -- Check that the original element still exists and has the correct text
802 -- Check that the original element still exists and has the correct text
1101− shouldContainText "two" ssr
803+ WD.getText ssr >>= flip shouldBe "two"
1102− liftIO $ writeChan replaceChan "three"
805+ writeChan replaceChan "three"
1103 elementShouldBeRemoved ssr
807 elementShouldBeRemoved ssr
1104− shouldContainText "three" =<< findElemWithRetry (WD.ByTag "span")
808+ shouldContainText "three" =<< WD.findElem (WD.ByTag "span")
1105 testWidget' setup check $ do
809 testWidget' setup check $ do
1106 replace <- triggerEventWithChan replaceChan
810 replace <- triggerEventWithChan replaceChan
1107 pb <- getPostBuild
811 pb <- getPostBuild
@@ -1111,13 +815,15 @@ tests withDebugging wdConfig caps _selenium = do
1112 it "can be nested in initial widget" $ runWD $ do
816 it "can be nested in initial widget" $ runWD $ do
1113 replaceChan :: Chan Text <- liftIO newChan
817 replaceChan :: Chan Text <- liftIO newChan
1114− let setup = findElemWithRetry $ WD.ByTag "div"
818+ let setup = WD.findElem $ WD.ByTag "div"
1115 check ssr = do
819 check ssr = do
1116 -- Check that the original element still exists and has the correct text
820 -- Check that the original element still exists and has the correct text
1117− shouldContainText "two" ssr
821+ WD.getText ssr >>= flip shouldBe "two"
1118− liftIO $ writeChan replaceChan "three"
823+ writeChan replaceChan "three"
1119 elementShouldBeRemoved ssr
825 elementShouldBeRemoved ssr
1120− shouldContainText "three" =<< findElemWithRetry (WD.ByTag "span")
826+ shouldContainText "three" =<< WD.findElem (WD.ByTag "span")
1121 testWidget' setup check $ void $ flip runWithReplace never $ do
827 testWidget' setup check $ void $ flip runWithReplace never $ do
1122 replace <- triggerEventWithChan replaceChan
828 replace <- triggerEventWithChan replaceChan
1123 pb <- getPostBuild
829 pb <- getPostBuild
@@ -1126,14 +832,16 @@ tests withDebugging wdConfig caps _selenium = do
1126 , el "span" . text <$> replace
832 , el "span" . text <$> replace
1128 it "can be nested in postBuild widget" $ runWD $ do
834 it "can be nested in postBuild widget" $ runWD $ do
1129− replaceChan :: Chan Text <- liftIO newChan
835+ replaceChan <- liftIO newChan
1130− let setup = findElemWithRetry $ WD.ByTag "div"
836+ let setup = WD.findElem $ WD.ByTag "div"
1131 check ssr = do
837 check ssr = do
1132 -- Check that the original element still exists and has the correct text
838 -- Check that the original element still exists and has the correct text
1133− shouldContainText "two" ssr
839+ WD.getText ssr >>= flip shouldBe "two"
1134− liftIO $ writeChan replaceChan "three"
841+ writeChan replaceChan "three"
1135 elementShouldBeRemoved ssr
843 elementShouldBeRemoved ssr
1136− shouldContainText "three" =<< findElemWithRetry (WD.ByTag "span")
844+ shouldContainText "three" =<< WD.findElem (WD.ByTag "span")
1137 testWidget' setup check $ void $ do
845 testWidget' setup check $ void $ do
1138 pb <- getPostBuild
846 pb <- getPostBuild
1139 runWithReplace (pure ()) $ ffor pb $ \() -> do
847 runWithReplace (pure ()) $ ffor pb $ \() -> do
@@ -1159,15 +867,17 @@ tests withDebugging wdConfig caps _selenium = do
1159 replaceChan2 :: Chan Text <- liftIO newChan
867 replaceChan2 :: Chan Text <- liftIO newChan
1160 lock :: MVar () <- liftIO newEmptyMVar
868 lock :: MVar () <- liftIO newEmptyMVar
1161 let check = do
869 let check = do
1162− shouldContainText "" =<< findElemWithRetry (WD.ByTag "body")
870+ shouldContainText "" =<< WD.findElem (WD.ByTag "body")
1163 liftIO $ do
871 liftIO $ do
1164 writeChan replaceChan1 "one"
872 writeChan replaceChan1 "one"
1165 takeMVar lock
873 takeMVar lock
1166− one <- findElemWithRetry $ WD.ByTag "div"
874+ one <- WD.findElem $ WD.ByTag "div"
1167− shouldContainText "pb" one
875+ WD.getText one >>= flip shouldBe "pb"
1168− liftIO $ writeChan replaceChan2 "two"
877+ writeChan replaceChan2 "two"
1169 elementShouldBeRemoved one
879 elementShouldBeRemoved one
1170− shouldContainText "two" =<< findElemWithRetry (WD.ByTag "span")
880+ shouldContainText "two" =<< WD.findElem (WD.ByTag "span")
1171 testWidget (pure ()) check $ void $ do
881 testWidget (pure ()) check $ void $ do
1172 replace1 <- triggerEventWithChan replaceChan1
882 replace1 <- triggerEventWithChan replaceChan1
1173 runWithReplace (pure ()) $ ffor replace1 $ \r1 -> do
883 runWithReplace (pure ()) $ ffor replace1 $ \r1 -> do
@@ -1208,12 +918,14 @@ tests withDebugging wdConfig caps _selenium = do
1208 it "works in immediate mode (RHS of prerender)" $ runWD $ do
918 it "works in immediate mode (RHS of prerender)" $ runWD $ do
1209 replaceChan :: Chan Text <- liftIO newChan
919 replaceChan :: Chan Text <- liftIO newChan
1210 let check = do
920 let check = do
1211− checkBodyText "one"
1212− one <- findElemWithRetry $ WD.ByTag "div"
921+ one <- WD.findElem $ WD.ByTag "div"
1213− shouldContainText "one" one
922+ shouldContainText "one" =<< WD.findElem (WD.ByTag "body")
923+ WD.getText one >>= flip shouldBe "one"
1214− liftIO $ writeChan replaceChan "pb"
925+ writeChan replaceChan "pb"
1215 elementShouldBeRemoved one
927 elementShouldBeRemoved one
1216− shouldContainText "pb" =<< findElemWithRetry (WD.ByTag "span")
928+ shouldContainText "pb" =<< WD.findElem (WD.ByTag "span")
1217 testWidget (pure ()) check $ void $ do
929 testWidget (pure ()) check $ void $ do
1218 replace <- triggerEventWithChan replaceChan
930 replace <- triggerEventWithChan replaceChan
1219 prerender_ blank $ do
931 prerender_ blank $ do
@@ -1221,12 +933,14 @@ tests withDebugging wdConfig caps _selenium = do
1221 it "works with postBuild in immediate mode (RHS of prerender)" $ runWD $ do
933 it "works with postBuild in immediate mode (RHS of prerender)" $ runWD $ do
1222 replaceChan :: Chan Text <- liftIO newChan
934 replaceChan :: Chan Text <- liftIO newChan
1223 let check = do
935 let check = do
1224− checkBodyText "two"
1225− two <- findElemWithRetry $ WD.ByTag "div"
936+ two <- WD.findElem $ WD.ByTag "div"
1226− shouldContainText "two" two
937+ shouldContainText "two" =<< WD.findElem (WD.ByTag "body")
938+ WD.getText two >>= flip shouldBe "two"
1227− liftIO $ writeChan replaceChan "three"
940+ writeChan replaceChan "three"
1228 elementShouldBeRemoved two
942 elementShouldBeRemoved two
1229− shouldContainText "three" =<< findElemWithRetry (WD.ByTag "span")
943+ shouldContainText "three" =<< WD.findElem (WD.ByTag "span")
1230 testWidget (pure ()) check $ void $ do
944 testWidget (pure ()) check $ void $ do
1231 replace <- triggerEventWithChan replaceChan
945 replace <- triggerEventWithChan replaceChan
1232 prerender_ blank $ do
946 prerender_ blank $ do
@@ -1236,61 +950,7 @@ tests withDebugging wdConfig caps _selenium = do
1236 , el "span" . text <$> replace
950 , el "span" . text <$> replace
1239− let checkInnerHtml t x = findElemWithRetry (WD.ByTag t) >>= (`attr` "innerHTML") >>= (`shouldBe` Just x)
1240− it "removes bracketing comments" $ runWD $ do
1241− replaceChan :: Chan () <- liftIO newChan
1243− preSwitchover = checkInnerHtml "div" "before|<!--replace-start-0-->inner1<!--replace-end-0-->|after"
1245− liftIO $ writeChan replaceChan () -- trigger creation of p tag
1246− _ <- findElemWithRetry $ WD.ByTag "p" -- wait till p tag is created
1247− checkInnerHtml "div" "before|<p>inner2</p>|after"
1248− testWidget' preSwitchover check $ do
1249− replace <- triggerEventWithChan replaceChan
1252− _ <- runWithReplace (text "inner1") $ el "p" (text "inner2") <$ replace
1254− it "ignores extra ending bracketing comment" $ runWD $ do
1255− replaceChan :: Chan () <- liftIO newChan
1257− preSwitchover = checkInnerHtml "div" "before|<!--replace-start-0-->inner1<!--replace-end-0--><!--replace-end-0-->|after"
1259− liftIO $ writeChan replaceChan () -- trigger creation of p tag
1260− _ <- findElemWithRetry $ WD.ByTag "p" -- wait till p tag is created
1261− checkInnerHtml "div" "before|inner2|after"
1262− testWidget' preSwitchover check $ do
1263− replace <- triggerEventWithChan replaceChan
1266− _ <- runWithReplace (text "inner1" *> comment "replace-end-0") $ text "inner2" <$ replace
1268− void $ runWithReplace blank $ el "p" blank <$ replace -- Signal tag for end of test
1269− -- TODO This test actually causes a hydration failure, but it wasn't
1270− -- previously detected, so I've marked it pending
1271− xit "ignores missing ending bracketing comments" $ runWD $ do
1272− replaceChan :: Chan () <- liftIO newChan
1275− checkInnerHtml "div" "before|<!--replace-start-0-->inner1<!--replace-end-0-->|after"
1276− divEl <- findElemWithRetry (WD.ByTag "div")
1277− let wrongHtml = "<!--replace-start-0-->inner1"
1278− actualHtml :: String <- WD.executeJS
1279− [WD.JSArg divEl, WD.JSArg wrongHtml]
1280− "arguments[0].innerHTML = arguments[1]; return arguments[0].innerHTML"
1281− actualHtml `shouldBe` wrongHtml
1283− liftIO $ writeChan replaceChan () -- trigger creation of p tag
1284− _ <- findElemWithRetry $ WD.ByTag "p" -- wait till p tag is created
1285− checkInnerHtml "div" "before|<p>inner2</p>|after"
1286− testWidget' preSwitchover check $ do
1287− replace <- triggerEventWithChan replaceChan
1290− _ <- runWithReplace (text "inner1") $ el "p" (text "inner2") <$ replace
1293− session' "traverseDMapWithKeyWithAdjust" $ do
953+ describe "traverseDMapWithKeyWithAdjust" $ session' $ do
1294 let widget :: DomBuilder t m => DKey a -> Identity a -> m (Identity a)
954 let widget :: DomBuilder t m => DKey a -> Identity a -> m (Identity a)
1295 widget k (Identity v) = elAttr "li" ("id" =: textKey k) $ do
955 widget k (Identity v) = elAttr "li" ("id" =: textKey k) $ do
1296 elClass "span" "key" $ text $ textKey k
956 elClass "span" "key" $ text $ textKey k
@@ -1298,58 +958,58 @@ tests withDebugging wdConfig caps _selenium = do
1298 pure (Identity v)
958 pure (Identity v)
1299 checkItem :: WD.Element -> Text -> Text -> WD ()
959 checkItem :: WD.Element -> Text -> Text -> WD ()
1300 checkItem li k v = do
960 checkItem li k v = do
1301− putStrLnDebug "checkItem"
1302− shouldContainTextNoRetry k =<< WD.findElemFrom li (WD.ByClass "key")
961+ shouldContainText k =<< WD.findElemFrom li (WD.ByClass "key")
1303− shouldContainTextNoRetry v =<< WD.findElemFrom li (WD.ByClass "value")
962+ shouldContainText v =<< WD.findElemFrom li (WD.ByClass "value")
1304 checkInitialItems dm xs = do
963 checkInitialItems dm xs = do
1305− putStrLnDebug "checkInitialItems"
1306 liftIO $ assertEqual "Wrong amount of items in DOM" (DMap.size dm) (length xs)
964 liftIO $ assertEqual "Wrong amount of items in DOM" (DMap.size dm) (length xs)
1307 forM_ (zip xs (DMap.toList dm)) $ \(e, k :=> Identity v) -> checkItem e (textKey k) (T.pack $ has @Show k $ show v)
965 forM_ (zip xs (DMap.toList dm)) $ \(e, k :=> Identity v) -> checkItem e (textKey k) (T.pack $ has @Show k $ show v)
1308− getAndCheckInitialItems dm = withRetry $ do
966+ getAndCheckInitialItems dm = do
1309− putStrLnDebug "getAndCheckInitialItems"
1310 xs <- WD.findElems (WD.ByTag "li")
967 xs <- WD.findElems (WD.ByTag "li")
1311 checkInitialItems dm xs
968 checkInitialItems dm xs
1313 checkRemoval chan k = do
970 checkRemoval chan k = do
1314− putStrLnDebug "checkRemoval"
1315− e <- findElemWithRetry (WD.ById $ textKey k)
971+ e <- WD.findElem (WD.ById $ textKey k)
1316− liftIO $ writeChan chan $ PatchDMap $ DMap.singleton k (ComposeMaybe Nothing)
973+ writeChan chan $ PatchDMap $ DMap.singleton k (ComposeMaybe Nothing)
1317 elementShouldBeRemoved e
975 elementShouldBeRemoved e
1318 checkReplace chan k v = do
976 checkReplace chan k v = do
1319− putStrLnDebug "checkReplace"
1320− e <- findElemWithRetry (WD.ById $ textKey k)
977+ e <- WD.findElem (WD.ById $ textKey k)
1321− liftIO $ writeChan chan $ PatchDMap $ DMap.singleton k (ComposeMaybe $ Just $ Identity v)
979+ writeChan chan $ PatchDMap $ DMap.singleton k (ComposeMaybe $ Just $ Identity v)
1322 elementShouldBeRemoved e
981 elementShouldBeRemoved e
1323− e' <- findElemWithRetry $ WD.ById $ textKey k
982+ e' <- WD.findElem (WD.ById $ textKey k)
1324 checkItem e' (textKey k) (T.pack $ show v)
983 checkItem e' (textKey k) (T.pack $ show v)
1325 checkInsert chan k v = do
984 checkInsert chan k v = do
1326− putStrLnDebug "checkInsert"
985+ liftIO $ do
1327− liftIO $ writeChan chan $ PatchDMap $ DMap.singleton k (ComposeMaybe $ Just $ Identity v)
986+ writeChan chan $ PatchDMap $ DMap.singleton k (ComposeMaybe $ Just $ Identity v)
1328− e <- findElemWithRetry (WD.ById $ textKey k)
988+ e <- WD.findElem (WD.ById $ textKey k)
1329 checkItem e (textKey k) (T.pack $ show v)
989 checkItem e (textKey k) (T.pack $ show v)
1330 postBuildPatch = PatchDMap $ DMap.fromList [Key_Char :=> ComposeMaybe Nothing, Key_Bool :=> ComposeMaybe (Just $ Identity True)]
990 postBuildPatch = PatchDMap $ DMap.fromList [Key_Char :=> ComposeMaybe Nothing, Key_Bool :=> ComposeMaybe (Just $ Identity True)]
1331 it "doesn't replace elements at switchover, can delete/update/insert" $ runWD $ do
991 it "doesn't replace elements at switchover, can delete/update/insert" $ runWD $ do
1332 chan <- liftIO newChan
992 chan <- liftIO newChan
1333− let preSwitchover :: WD [WD.Element]
993+ let static :: WD [WD.Element]
1334− preSwitchover = getAndCheckInitialItems keyMap
994+ static = getAndCheckInitialItems keyMap
1335 check :: [WD.Element] -> WD ()
995 check :: [WD.Element] -> WD ()
1336 check xs = do
996 check xs = do
1337 checkInitialItems keyMap xs
997 checkInitialItems keyMap xs
1338 checkRemoval chan Key_Int
998 checkRemoval chan Key_Int
1339 checkReplace chan Key_Char 'B'
999 checkReplace chan Key_Char 'B'
1340 checkInsert chan Key_Bool True
1000 checkInsert chan Key_Bool True
1341− testWidget' preSwitchover check $ do
1001+ testWidget' static check $ do
1342 (dmap, _evt) <- traverseDMapWithKeyWithAdjust widget keyMap =<< triggerEventWithChan chan
1002 (dmap, _evt) <- traverseDMapWithKeyWithAdjust widget keyMap =<< triggerEventWithChan chan
1343 liftIO $ dmap `H.shouldBe` keyMap
1003 liftIO $ dmap `H.shouldBe` keyMap
1344 it "handles postBuild correctly" $ runWD $ do
1004 it "handles postBuild correctly" $ runWD $ do
1345 chan <- liftIO newChan
1005 chan <- liftIO newChan
1346− let preSwitchover = getAndCheckInitialItems $ applyAlways postBuildPatch keyMap
1006+ let static = getAndCheckInitialItems (fromJust $ apply postBuildPatch keyMap)
1347 check xs = do
1007 check xs = do
1348− withRetry $ checkInitialItems (applyAlways postBuildPatch keyMap) xs
1008+ checkInitialItems (fromMaybe undefined $ apply postBuildPatch keyMap) xs
1349 checkRemoval chan Key_Int
1009 checkRemoval chan Key_Int
1350 checkInsert chan Key_Char 'B'
1010 checkInsert chan Key_Char 'B'
1351 checkReplace chan Key_Bool True
1011 checkReplace chan Key_Bool True
1352− testWidget' preSwitchover check $ void $ do
1012+ testWidget' static check $ void $ do
1353 pb <- getPostBuild
1013 pb <- getPostBuild
1354 replace <- triggerEventWithChan chan
1014 replace <- triggerEventWithChan chan
1355 (dmap, _evt) <- traverseDMapWithKeyWithAdjust widget keyMap $ leftmost [postBuildPatch <$ pb, replace]
1015 (dmap, _evt) <- traverseDMapWithKeyWithAdjust widget keyMap $ leftmost [postBuildPatch <$ pb, replace]
@@ -1382,7 +1042,7 @@ tests withDebugging wdConfig caps _selenium = do
1382 it "handles postBuild correctly in prerender" $ runWD $ do
1042 it "handles postBuild correctly in prerender" $ runWD $ do
1383 chan <- liftIO newChan
1043 chan <- liftIO newChan
1384 let check = do
1044 let check = do
1385− _ <- getAndCheckInitialItems $ applyAlways postBuildPatch keyMap
1045+ _ <- getAndCheckInitialItems (fromJust $ apply postBuildPatch keyMap)
1386 checkRemoval chan Key_Int
1046 checkRemoval chan Key_Int
1387 checkInsert chan Key_Char 'B'
1047 checkInsert chan Key_Char 'B'
1388 checkReplace chan Key_Bool True
1048 checkReplace chan Key_Bool True
@@ -1393,7 +1053,7 @@ tests withDebugging wdConfig caps _selenium = do
1393 (dmap, _evt) <- traverseDMapWithKeyWithAdjust widget keyMap $ leftmost [postBuildPatch <$ pb, replace]
1053 (dmap, _evt) <- traverseDMapWithKeyWithAdjust widget keyMap $ leftmost [postBuildPatch <$ pb, replace]
1394 liftIO $ dmap `H.shouldBe` keyMap
1054 liftIO $ dmap `H.shouldBe` keyMap
1396− session' "traverseIntMapWithKeyWithAdjust" $ do
1056+ describe "traverseIntMapWithKeyWithAdjust" $ session' $ do
1397 let textKeyInt k = "key" <> T.pack (show k)
1057 let textKeyInt k = "key" <> T.pack (show k)
1398 intMap = IntMap.fromList
1058 intMap = IntMap.fromList
1399 [ (1, "one")
1059 [ (1, "one")
@@ -1407,89 +1067,89 @@ tests withDebugging wdConfig caps _selenium = do
1408 checkItem :: WD.Element -> Text -> Text -> WD ()
1068 checkItem :: WD.Element -> Text -> Text -> WD ()
1409 checkItem li k v = do
1069 checkItem li k v = do
1410− putStrLnDebug "checkItem"
1411− shouldContainTextNoRetry k =<< WD.findElemFrom li (WD.ByClass "key")
1070+ shouldContainText k =<< WD.findElemFrom li (WD.ByClass "key")
1412− shouldContainTextNoRetry v =<< WD.findElemFrom li (WD.ByClass "value")
1071+ shouldContainText v =<< WD.findElemFrom li (WD.ByClass "value")
1413 checkInitialItems dm xs = do
1072 checkInitialItems dm xs = do
1414− putStrLnDebug "checkInitialItems"
1415 liftIO $ assertEqual "Wrong amount of items in DOM" (IntMap.size dm) (length xs)
1073 liftIO $ assertEqual "Wrong amount of items in DOM" (IntMap.size dm) (length xs)
1416 forM_ (zip xs (IntMap.toList dm)) $ \(e, (k, v)) -> checkItem e (textKeyInt k) v
1074 forM_ (zip xs (IntMap.toList dm)) $ \(e, (k, v)) -> checkItem e (textKeyInt k) v
1417− getAndCheckInitialItems dm = withRetry $ do
1075+ getAndCheckInitialItems dm = do
1418− putStrLnDebug "getAndCheckInitialItems"
1419 xs <- WD.findElems (WD.ByTag "li")
1076 xs <- WD.findElems (WD.ByTag "li")
1420 checkInitialItems dm xs
1077 checkInitialItems dm xs
1422 checkRemoval chan k = do
1079 checkRemoval chan k = do
1423− putStrLnDebug "checkRemoval"
1424− e <- findElemWithRetry (WD.ById $ textKeyInt k)
1080+ e <- WD.findElem (WD.ById $ textKeyInt k)
1425− liftIO $ writeChan chan $ PatchIntMap $ IntMap.singleton k Nothing
1082+ writeChan chan $ PatchIntMap $ IntMap.singleton k Nothing
1426 elementShouldBeRemoved e
1084 elementShouldBeRemoved e
1427 checkReplace chan k v = do
1085 checkReplace chan k v = do
1428− putStrLnDebug "checkReplace"
1429− e <- findElemWithRetry (WD.ById $ textKeyInt k)
1086+ e <- WD.findElem (WD.ById $ textKeyInt k)
1430− liftIO $ writeChan chan $ PatchIntMap $ IntMap.singleton k $ Just v
1088+ writeChan chan $ PatchIntMap $ IntMap.singleton k $ Just v
1431 elementShouldBeRemoved e
1090 elementShouldBeRemoved e
1432− e' <- findElemWithRetry (WD.ById $ textKeyInt k)
1091+ e' <- WD.findElem (WD.ById $ textKeyInt k)
1433− withRetry $ checkItem e' (textKeyInt k) v
1092+ checkItem e' (textKeyInt k) v
1434 checkInsert chan k v = do
1093 checkInsert chan k v = do
1435− putStrLnDebug "checkInsert"
1094+ liftIO $ do
1436− liftIO $ writeChan chan $ PatchIntMap $ IntMap.singleton k $ Just v
1095+ writeChan chan $ PatchIntMap $ IntMap.singleton k $ Just v
1437− e <- findElemWithRetry (WD.ById $ textKeyInt k)
1097+ e <- WD.findElem (WD.ById $ textKeyInt k)
1438 checkItem e (textKeyInt k) v
1098 checkItem e (textKeyInt k) v
1439 postBuildPatch = PatchIntMap $ IntMap.fromList [(2, Nothing), (3, Just "trois"), (4, Just "four")]
1099 postBuildPatch = PatchIntMap $ IntMap.fromList [(2, Nothing), (3, Just "trois"), (4, Just "four")]
1440− xit "doesn't replace elements at switchover, can delete/update/insert" $ runWD $ do
1100+ it "doesn't replace elements at switchover, can delete/update/insert" $ runWD $ do
1441 chan <- liftIO newChan
1101 chan <- liftIO newChan
1442− let preSwitchover = getAndCheckInitialItems intMap
1102+ let static = getAndCheckInitialItems intMap
1443 check xs = do
1103 check xs = do
1444 checkInitialItems intMap xs
1104 checkInitialItems intMap xs
1445 checkRemoval chan 1
1105 checkRemoval chan 1
1446 checkReplace chan 2 "deux"
1106 checkReplace chan 2 "deux"
1447 checkInsert chan 4 "four"
1107 checkInsert chan 4 "four"
1448− testWidget' preSwitchover check $ void $ do
1108+ testWidget' static check $ void $ do
1449 (im, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap =<< triggerEventWithChan chan
1109 (im, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap =<< triggerEventWithChan chan
1450 liftIO $ im `H.shouldBe` intMap
1110 liftIO $ im `H.shouldBe` intMap
1451− xit "handles postBuild correctly" $ runWD $ do
1111+ it "handles postBuild correctly" $ runWD $ do
1452 chan <- liftIO newChan
1112 chan <- liftIO newChan
1453− let preSwitchover = getAndCheckInitialItems $ applyAlways postBuildPatch intMap
1113+ let static = getAndCheckInitialItems (fromJust $ apply postBuildPatch intMap)
1454 check xs = do
1114 check xs = do
1455− withRetry $ checkInitialItems (applyAlways postBuildPatch intMap) xs
1115+ checkInitialItems (fromMaybe undefined $ apply postBuildPatch intMap) xs
1456 checkRemoval chan 1
1116 checkRemoval chan 1
1457 checkInsert chan 2 "deux"
1117 checkInsert chan 2 "deux"
1458 checkReplace chan 3 "trois"
1118 checkReplace chan 3 "trois"
1459− testWidget' preSwitchover check $ void $ do
1119+ testWidget' static check $ void $ do
1460 pb <- getPostBuild
1120 pb <- getPostBuild
1461 replace <- triggerEventWithChan chan
1121 replace <- triggerEventWithChan chan
1462 (dmap, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap $ leftmost [postBuildPatch <$ pb, replace]
1122 (dmap, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap $ leftmost [postBuildPatch <$ pb, replace]
1463 liftIO $ dmap `H.shouldBe` intMap
1123 liftIO $ dmap `H.shouldBe` intMap
1464− xit "can delete/update/insert when built in prerender" $ runWD $ do
1124+ it "can delete/update/insert when built in prerender" $ runWD $ do
1465 chan <- liftIO newChan
1125 chan <- liftIO newChan
1466 let check = do
1126 let check = do
1467 _ <- getAndCheckInitialItems intMap
1127 _ <- getAndCheckInitialItems intMap
1468 checkRemoval chan 1
1128 checkRemoval chan 1
1469 checkReplace chan 2 "deux"
1129 checkReplace chan 2 "deux"
1470− checkInsert chan 4 "quatre"
1130+ checkInsert chan 3 "trois"
1471 testWidget (pure ()) check $ do
1131 testWidget (pure ()) check $ do
1472 replace <- triggerEventWithChan chan
1132 replace <- triggerEventWithChan chan
1473 prerender_ (pure ()) $ do
1133 prerender_ (pure ()) $ do
1474 (dmap, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap replace
1134 (dmap, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap replace
1475 liftIO $ dmap `H.shouldBe` intMap
1135 liftIO $ dmap `H.shouldBe` intMap
1476− xit "can delete/update/insert when built in immediate mode" $ runWD $ do
1136+ it "can delete/update/insert when built in immediate mode" $ runWD $ do
1477 chan <- liftIO newChan
1137 chan <- liftIO newChan
1478 let check = do
1138 let check = do
1479 _ <- getAndCheckInitialItems intMap
1139 _ <- getAndCheckInitialItems intMap
1480 checkRemoval chan 1
1140 checkRemoval chan 1
1481 checkReplace chan 2 "deux"
1141 checkReplace chan 2 "deux"
1482− checkInsert chan 4 "quatre"
1142+ checkInsert chan 3 "trois"
1483 testWidget (pure ()) check $ void $ do
1143 testWidget (pure ()) check $ void $ do
1484 pb <- getPostBuild
1144 pb <- getPostBuild
1485 runWithReplace (pure ()) $ ffor pb $ \() -> void $ do
1145 runWithReplace (pure ()) $ ffor pb $ \() -> void $ do
1486 (dmap, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap =<< triggerEventWithChan chan
1146 (dmap, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap =<< triggerEventWithChan chan
1487 liftIO $ dmap `H.shouldBe` intMap
1147 liftIO $ dmap `H.shouldBe` intMap
1488 -- Should be fixed by prerender changes!
1148 -- Should be fixed by prerender changes!
1489− xit "handles postBuild correctly in prerender" $ runWD $ do
1149+ it "handles postBuild correctly in prerender" $ runWD $ do
1490 chan <- liftIO newChan
1150 chan <- liftIO newChan
1491 let check = do
1151 let check = do
1492− _ <- getAndCheckInitialItems $ applyAlways postBuildPatch intMap
1152+ _ <- getAndCheckInitialItems (fromJust $ apply postBuildPatch intMap)
1493 checkRemoval chan 1
1153 checkRemoval chan 1
1494 checkInsert chan 2 "deux"
1154 checkInsert chan 2 "deux"
1495 checkReplace chan 3 "trois"
1155 checkReplace chan 3 "trois"
@@ -1500,30 +1160,47 @@ tests withDebugging wdConfig caps _selenium = do
1500 (dmap, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap $ leftmost [postBuildPatch <$ pb, replace]
1160 (dmap, _evt) <- traverseIntMapWithKeyWithAdjust widget intMap $ leftmost [postBuildPatch <$ pb, replace]
1501 liftIO $ dmap `H.shouldBe` intMap
1161 liftIO $ dmap `H.shouldBe` intMap
1503− session' "traverseDMapWithKeyWithAdjustWithMove" $ do
1163+ describe "traverseDMapWithKeyWithAdjustWithMove" $ session' $ do
1504 let widget :: DomBuilder t m => Key2 a -> Identity a -> m (Identity a)
1164 let widget :: DomBuilder t m => Key2 a -> Identity a -> m (Identity a)
1505− widget k (Identity v) = elAttr "li" ("id" =: textKey2 k) $ do
1165+ widget k (Identity v) = elAttr "li" ("id" =: textKey k) $ do
1506− elClass "span" "key" $ text $ textKey2 k
1166+ elClass "span" "key" $ text $ textKey k
1507 elClass "span" "value" $ text $ T.pack $ has @Show k $ show v
1167 elClass "span" "value" $ text $ T.pack $ has @Show k $ show v
1508 pure (Identity v)
1168 pure (Identity v)
1509− textKey2 :: Key2 a -> Text
1169+ textKey :: Key2 a -> Text
1510− textKey2 = \case
1170+ textKey = \case
1511 Key2_Int i -> "i" <> T.pack (show i)
1171 Key2_Int i -> "i" <> T.pack (show i)
1512 Key2_Char c -> "c" <> T.pack [c]
1172 Key2_Char c -> "c" <> T.pack [c]
1513 checkItem :: WD.Element -> Text -> Text -> WD ()
1173 checkItem :: WD.Element -> Text -> Text -> WD ()
1514 checkItem li k v = do
1174 checkItem li k v = do
1515− shouldContainTextNoRetry k =<< WD.findElemFrom li (WD.ByClass "key")
1175+ shouldContainText k =<< WD.findElemFrom li (WD.ByClass "key")
1516− shouldContainTextNoRetry v =<< WD.findElemFrom li (WD.ByClass "value")
1176+ shouldContainText v =<< WD.findElemFrom li (WD.ByClass "value")
1517 checkInitialItems dm xs = do
1177 checkInitialItems dm xs = do
1518 liftIO $ assertEqual "Wrong amount of items in DOM" (DMap.size dm) (length xs)
1178 liftIO $ assertEqual "Wrong amount of items in DOM" (DMap.size dm) (length xs)
1519− forM_ (zip xs (DMap.toList dm)) $ \(e, k :=> Identity v) -> checkItem e (textKey2 k) (T.pack $ has @Show k $ show v)
1179+ forM_ (zip xs (DMap.toList dm)) $ \(e, k :=> Identity v) -> checkItem e (textKey k) (T.pack $ has @Show k $ show v)
1520− getAndCheckInitialItems dm = withRetry $ do
1180+ getAndCheckInitialItems dm = do
1521 xs <- WD.findElems (WD.ByTag "li")
1181 xs <- WD.findElems (WD.ByTag "li")
1522 checkInitialItems dm xs
1182 checkInitialItems dm xs
1524− moveSpec
1184+ checkRemoval chan k = do
1525− :: (DMap Key2 Identity -> (WD.Element -> Chan (PatchDMapWithMove Key2 Identity) -> WD ()) -> WD ())
1185+ e <- WD.findElem (WD.ById $ textKey k)
1526− -> H.SpecM (WdTestSession ()) ()
1186+ liftIO $ do
1187+ writeChan chan $ deleteDMapKey k
1189+ elementShouldBeRemoved e
1190+ checkReplace chan k v = do
1191+ e <- WD.findElem (WD.ById $ textKey k)
1193+ writeChan chan $ insertDMapKey k (Identity v)
1195+ elementShouldBeRemoved e
1196+ e' <- WD.findElem (WD.ById $ textKey k)
1197+ checkItem e' (textKey k) (T.pack $ show v)
1198+ checkInsert chan k v = do
1200+ writeChan chan $ insertDMapKey k (Identity v)
1202+ e <- WD.findElem (WD.ById $ textKey k)
1203+ checkItem e (textKey k) (T.pack $ show v)
1527 moveSpec testMove = do
1204 moveSpec testMove = do
1528 it "can insert an item" $ runWD $ testMove (DMap.fromList [Key2_Int 1 ==> 1, Key2_Int 3 ==> 3]) $ \body chan -> do
1205 it "can insert an item" $ runWD $ testMove (DMap.fromList [Key2_Int 1 ==> 1, Key2_Int 3 ==> 3]) $ \body chan -> do
1529 shouldContainText (T.strip $ T.unlines ["i11","i33"]) body
1206 shouldContainText (T.strip $ T.unlines ["i11","i33"]) body
@@ -1551,26 +1228,26 @@ tests withDebugging wdConfig caps _selenium = do
1552 describe "hydration" $ moveSpec $ \initMap test -> do
1229 describe "hydration" $ moveSpec $ \initMap test -> do
1553 chan <- liftIO newChan
1230 chan <- liftIO newChan
1554− let preSwitchover = getAndCheckInitialItems initMap
1231+ let static = getAndCheckInitialItems initMap
1555 check xs = do
1232 check xs = do
1556 checkInitialItems initMap xs
1233 checkInitialItems initMap xs
1557− body <- getBody
1234+ body <- WD.findElem (WD.ByTag "body")
1558 test body chan
1235 test body chan
1559− testWidget' preSwitchover check $ void $ do
1236+ testWidget' static check $ void $ do
1560 (dmap, _evt) <- traverseDMapWithKeyWithAdjustWithMove widget initMap =<< triggerEventWithChan chan
1237 (dmap, _evt) <- traverseDMapWithKeyWithAdjustWithMove widget initMap =<< triggerEventWithChan chan
1561 liftIO $ assertEqual "DMap" initMap dmap
1238 liftIO $ assertEqual "DMap" initMap dmap
1563 describe "hydration/immediate" $ moveSpec $ \initMap test -> do
1240 describe "hydration/immediate" $ moveSpec $ \initMap test -> do
1564 chan <- liftIO newChan
1241 chan <- liftIO newChan
1565 replace <- liftIO newChan
1242 replace <- liftIO newChan
1566− lock :: MVar () <- liftIO newEmptyMVar
1243+ lock <- liftIO newEmptyMVar
1567 let check = do
1244 let check = do
1568 liftIO $ do
1245 liftIO $ do
1569 writeChan replace ()
1246 writeChan replace ()
1570 takeMVar lock
1247 takeMVar lock
1571 xs <- getAndCheckInitialItems initMap
1248 xs <- getAndCheckInitialItems initMap
1572 checkInitialItems initMap xs
1249 checkInitialItems initMap xs
1573− body <- getBody
1250+ body <- WD.findElem (WD.ByTag "body")
1574 test body chan
1251 test body chan
1575 testWidget (pure ()) check $ void $ do
1252 testWidget (pure ()) check $ void $ do
1576 e <- triggerEventWithChan replace
1253 e <- triggerEventWithChan replace
@@ -1580,26 +1257,24 @@ tests withDebugging wdConfig caps _selenium = do
1580 (dmap, _evt) <- traverseDMapWithKeyWithAdjustWithMove widget initMap =<< triggerEventWithChan chan
1257 (dmap, _evt) <- traverseDMapWithKeyWithAdjustWithMove widget initMap =<< triggerEventWithChan chan
1581 liftIO $ assertEqual "DMap" initMap dmap
1258 liftIO $ assertEqual "DMap" initMap dmap
1583− session' "hydrating invalid HTML" $ do
1260+ describe "hydrating invalid HTML" $ session' $ do
1584− xit "can hydrate list in paragraph" $ runWD $ do
1261+ it "can hydrate list in paragraph" $ runWD $ do
1585− let preSwitchover = do
1262+ let static = do
1263+ body <- WD.findElem (WD.ByTag "body")
1586− checkBodyText "before\ninner\nafter"
1264+ shouldContainText "before\ninner\nafter" body
1587 -- Two <p> tags should be present
1265 -- Two <p> tags should be present
1588− (p1, p2) <- WD.findElems (WD.ByTag "p") >>= \case
1266+ [p1, p2] <- WD.findElems (WD.ByTag "p")
1589− [p1, p2] -> pure (p1, p2)
1590− _ -> error "Unexpected number of `p` tags (expected 2)"
1591− ol <- findElemWithRetry (WD.ByTag "ol")
1267+ ol <- WD.findElem (WD.ByTag "ol")
1592 shouldContainText "before" p1
1268 shouldContainText "before" p1
1593 shouldContainText "inner" ol
1269 shouldContainText "inner" ol
1594 shouldContainText "" p2
1270 shouldContainText "" p2
1595− pure (p1, ol, p2)
1271+ pure (body, p1, ol, p2)
1596− check (p1, ol, p2) = do
1272+ check (body, p1, ol, p2) = do
1597− checkBodyText "before\ninner\nafter"
1273+ shouldContainText "before\ninner\nafter" body
1598 shouldContainText "before\ninner\nafter" p1
1274 shouldContainText "before\ninner\nafter" p1
1599 elementShouldBeRemoved ol
1275 elementShouldBeRemoved ol
1600 elementShouldBeRemoved p2
1276 elementShouldBeRemoved p2
1601− -- Don't fail fatally when hydration encounters the invalid DOM
1277+ testWidget' static check $ do
1602− testWidgetDebug' False withDebugging preSwitchover check $ do
1603 -- This is deliberately invalid HTML, the browser will interpret it as
1278 -- This is deliberately invalid HTML, the browser will interpret it as
1604 -- <p>before</p><ol>inner</ol>after<p></p>
1279 -- <p>before</p><ol>inner</ol>after<p></p>
1605 el "p" $ do
1280 el "p" $ do
@@ -1607,29 +1282,6 @@ tests withDebugging wdConfig caps _selenium = do
1607 el "ol" $ text "inner"
1282 el "ol" $ text "inner"
1608 text "after"
1283 text "after"
1610− -- TODO: This test presupposes the exact set of labels that "dropdown" places in the "value" fields to distinguish options.
1611− -- This dependence on internal implementation details is undesirable in a test case, but seems fairly tricky to avoid.
1612− -- It seems expedient for the time being to expect this test case to be updated, should those implementation details ever change.
1613− session' "dropdown" $ do
1614− let doTest expectedOpts (initialValue :: Text) = do
1616− es <- findElemsWithRetry $ WD.ByTag "option"
1617− opts <- mapM fetchElement es
1618− assertEqual "missing/extra/incorrect option element(s)" expectedOpts (sort opts)
1619− testWidget doCheck doCheck $ do
1620− void $ dropdown initialValue (constDyn (("aa" :: Text) =: "aaa" <> "bb" =: "bbb")) def
1621− fetchElement e = do
1622− val <- WD.attr e "value"
1623− sel <- WD.attr e "selected"
1624− return (fromMaybe "" val, isJust sel)
1625− -- The "aa" test case is important, but a good test implementation probably needs to avoid selenium, because HTML parsers will insert a "selected" attribute on the first "option" tag if no selected attributes are present; thus as written, this erroneously succeeds on the old implementation (but properly implemented, should fail)
1626− -- Thus, it would appear that we do actually need a HTML5 or maybe XML parser for this test suite.
1627− xit "statically renders initial values (on aa)" $ runWD $ do
1628− doTest [("0",True),("1",False)] "aa"
1629− -- These tests are currently marked "pending" (by using "xit" instead of "it") because this test has a high chance of non-deterministically failing, which is a problem elsewhere in this test suite as well
1630− xit "statically renders initial values (on bb)" $ runWD $ do
1631− doTest [("0",False),("1",True)] "bb"
1633data Selenium = Selenium
1285data Selenium = Selenium
1634 { _selenium_portNumber :: PortNumber
1286 { _selenium_portNumber :: PortNumber
1635 , _selenium_stopServer :: IO ()
1287 , _selenium_stopServer :: IO ()
@@ -1646,10 +1298,11 @@ startSeleniumServer port = do
1647withSeleniumServer :: (Selenium -> IO ()) -> IO ()
1299withSeleniumServer :: (Selenium -> IO ()) -> IO ()
1648withSeleniumServer f = do
1300withSeleniumServer f = do
1301+ port <- getFreePort
1649− stopServer <- startSeleniumServer seleniumPort
1302+ stopServer <- startSeleniumServer port
1650 threadDelay $ 1000 * 1000 * 2 -- TODO poll or wait on a a signal to block on
1303 threadDelay $ 1000 * 1000 * 2 -- TODO poll or wait on a a signal to block on
1651 f $ Selenium
1304 f $ Selenium
1652− { _selenium_portNumber = seleniumPort
1305+ { _selenium_portNumber = port
1653 , _selenium_stopServer = stopServer
1306 , _selenium_stopServer = stopServer
@@ -1660,163 +1313,121 @@ triggerEventWithChan chan = do
1660 prerender_ (pure ()) $ void $ liftIO $ forkIO $ forever $ trigger =<< readChan chan
1313 prerender_ (pure ()) $ void $ liftIO $ forkIO $ forever $ trigger =<< readChan chan
1663−shouldBeWithRetryM :: (Eq a, Show a) => WD a -> a -> WD ()
1664−shouldBeWithRetryM m expected = withRetry $ do
1666− got `shouldBe` expected
1668assertAttr :: WD.Element -> Text -> Maybe Text -> WD ()
1316assertAttr :: WD.Element -> Text -> Maybe Text -> WD ()
1669assertAttr e k v = liftIO . assertEqual "Incorrect attribute value" v =<< WD.attr e k
1317assertAttr e k v = liftIO . assertEqual "Incorrect attribute value" v =<< WD.attr e k
1671elementShouldBeRemoved :: WD.Element -> WD ()
1319elementShouldBeRemoved :: WD.Element -> WD ()
1672−elementShouldBeRemoved e = withRetry $ do
1320+elementShouldBeRemoved e = do
1673 try (WD.getText e) >>= \case
1321 try (WD.getText e) >>= \case
1674 Left (WD.FailedCommand WD.StaleElementReference _) -> return ()
1322 Left (WD.FailedCommand WD.StaleElementReference _) -> return ()
1675 Left err -> throwM err
1323 Left err -> throwM err
1676 Right !_ -> liftIO $ assertFailure "Expected element to be removed, but it still exists"
1324 Right !_ -> liftIO $ assertFailure "Expected element to be removed, but it still exists"
1678shouldContainText :: Text -> WD.Element -> WD ()
1326shouldContainText :: Text -> WD.Element -> WD ()
1679−shouldContainText t = withRetry . shouldContainTextNoRetry t
1681−shouldContainTextNoRetry :: Text -> WD.Element -> WD ()
1682−shouldContainTextNoRetry t = flip shouldBe t <=< WD.getText
1327+shouldContainText t = flip shouldBe t <=< WD.getText
1684checkBodyText :: Text -> WD ()
1329checkBodyText :: Text -> WD ()
1685checkBodyText = checkTextInTag "body"
1330checkBodyText = checkTextInTag "body"
1687checkTextInTag :: Text -> Text -> WD ()
1332checkTextInTag :: Text -> Text -> WD ()
1688−checkTextInTag t expected = do
1689− e <- findElemWithRetry (WD.ByTag t)
1690− shouldContainText expected e
1333+checkTextInTag t expected = WD.findElem (WD.ByTag t) >>= shouldContainText expected
1692checkTextInId :: Text -> Text -> WD ()
1335checkTextInId :: Text -> Text -> WD ()
1693−checkTextInId i expected = do
1336+checkTextInId i expected = WD.findElem (WD.ById i) >>= shouldContainText expected
1694− e <- findElemWithRetry (WD.ById i)
1695− shouldContainText expected e
1697−findElemWithRetry :: Selector -> WD WD.Element
1698−findElemWithRetry = withRetry . WD.findElem
1700−findElemsWithRetry :: Selector -> WD [WD.Element]
1701−findElemsWithRetry = withRetry . WD.findElems
1703−getBody :: WD WD.Element
1704−getBody = WD.findElem $ WD.ByTag "body"
1706−withRetry :: forall a. WD a -> WD a
1707−withRetry a = wait 300
1708− where wait :: Int -> WD a
1710− wait n = try a >>= \case
1711− Left (e :: SomeException) -> do
1712− liftIO $ putStrLn ("(retrying due to " <> show e <> ")") *> threadDelay 100000
1714− Right v -> return v
1716divId :: DomBuilder t m => Text -> m a -> m a
1338divId :: DomBuilder t m => Text -> m a -> m a
1717divId i = elAttr "div" ("id" =: i)
1339divId i = elAttr "div" ("id" =: i)
1719type TestWidget js t m = (DomBuilder t m, MonadHold t m, PostBuild t m, Prerender js t m, PerformEvent t m, TriggerEvent t m, MonadFix m, MonadIO (Performable m), MonadIO m)
1341type TestWidget js t m = (DomBuilder t m, MonadHold t m, PostBuild t m, Prerender js t m, PerformEvent t m, TriggerEvent t m, MonadFix m, MonadIO (Performable m), MonadIO m)
1721−testWidgetStaticDebug
1343+testWidgetStatic
1723− -> WD b
1344+ :: WD b
1724 -- ^ Webdriver commands to run before JS runs and after hydration switchover
1345 -- ^ Webdriver commands to run before JS runs and after hydration switchover
1725 -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ())
1346 -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ())
1726 -- ^ Widget we are testing
1347 -- ^ Widget we are testing
1728−testWidgetStaticDebug withDebugging w = testWidgetDebug True withDebugging (void w) w
1349+testWidgetStatic w = testWidget (void w) w
1730-- | TODO: do something about JSExceptions not causing tests to fail
1351-- | TODO: do something about JSExceptions not causing tests to fail
1731−testWidgetDebug
1352+testWidget
1734− -> WD ()
1353+ :: WD ()
1735 -- ^ Webdriver commands to run before the JS runs (i.e. on the statically rendered page)
1354 -- ^ Webdriver commands to run before the JS runs (i.e. on the statically rendered page)
1737 -- ^ Webdriver commands to run after hydration switchover
1356 -- ^ Webdriver commands to run after hydration switchover
1738 -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ())
1357 -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ())
1739 -- ^ Widget we are testing
1358 -- ^ Widget we are testing
1741−testWidgetDebug hardFailure withDebugging beforeJS afterSwitchover =
1742− testWidgetDebug' hardFailure withDebugging beforeJS (const afterSwitchover)
1360+testWidget beforeJS afterSwitchover = testWidget' beforeJS (const afterSwitchover)
1744−data HydrationFailedException = HydrationFailedException deriving Show
1745−instance Exception HydrationFailedException
1747-- | TODO: do something about JSExceptions not causing tests to fail
1362-- | TODO: do something about JSExceptions not causing tests to fail
1748−testWidgetDebug'
1363+testWidget'
1751− -> WD a
1364+ :: WD a
1752 -- ^ Webdriver commands to run before the JS runs (i.e. on the statically rendered page)
1365 -- ^ Webdriver commands to run before the JS runs (i.e. on the statically rendered page)
1753 -> (a -> WD b)
1366 -> (a -> WD b)
1754 -- ^ Webdriver commands to run after hydration switchover
1367 -- ^ Webdriver commands to run after hydration switchover
1755 -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ())
1368 -> (forall m js. TestWidget js (SpiderTimeline Global) m => m ())
1756 -- ^ Widget we are testing (contents of body)
1369 -- ^ Widget we are testing (contents of body)
1758−testWidgetDebug' hardFailure withDebugging beforeJS afterSwitchover bodyWidget = do
1371+testWidget' beforeJS afterSwitchover bodyWidget = maybe (error "test timed out") pure <=< timeout testTimeLimit $ do
1759− let putStrLnDebug :: MonadIO m => Text -> m ()
1760− putStrLnDebug m = when withDebugging $ liftIO $ putStrLn $ T.unpack m
1761− staticApp = do
1372+ let staticApp = do
1762 el "head" $ pure ()
1373 el "head" $ pure ()
1763 el "body" $ do
1374 el "body" $ do
1764 bodyWidget
1375 bodyWidget
1765 el "script" $ text $ TE.decodeUtf8 $ LBS.toStrict $ jsaddleJs False
1376 el "script" $ text $ TE.decodeUtf8 $ LBS.toStrict $ jsaddleJs False
1766− putStrLnDebug "rendering static"
1767− ((), html) <- liftIO $ renderStatic $ runHydratableT staticApp
1377+ ((), html) <- liftIO $ renderStatic staticApp
1768− putStrLnDebug "rendered static"
1769 waitBeforeJS <- liftIO newEmptyMVar -- Empty until JS should be run
1378 waitBeforeJS <- liftIO newEmptyMVar -- Empty until JS should be run
1770− onFailure <- if hardFailure then (`throwTo` HydrationFailedException) <$> liftIO myThreadId else pure $ pure ()
1771 waitUntilSwitchover <- liftIO newEmptyMVar -- Empty until switchover
1379 waitUntilSwitchover <- liftIO newEmptyMVar -- Empty until switchover
1772 let entryPoint = do
1380 let entryPoint = do
1773− putStrLnDebug "taking waitBeforeJS"
1774 liftIO $ takeMVar waitBeforeJS
1381 liftIO $ takeMVar waitBeforeJS
1775− let switchOverAction = do
1776− putStrLnDebug "switchover syncPoint"
1778− putStrLnDebug "putting waitUntilSwitchover"
1779− liftIO $ putMVar waitUntilSwitchover ()
1382+ mainHydrationWidgetWithSwitchoverAction (putMVar waitUntilSwitchover ()) (pure ()) bodyWidget
1780− putStrLnDebug "put waitUntilSwitchover"
1781− putStrLnDebug "running mainHydrationWidgetWithSwitchoverAction"
1782− mainHydrationWidgetWithSwitchoverActionWithFailure' onFailure switchOverAction blank bodyWidget
1783− putStrLnDebug "syncPoint after mainHydrationWidgetWithSwitchoverAction"
1784 syncPoint
1383 syncPoint
1785− application <- liftIO $ jsaddleOr defaultConnectionOptions entryPoint $ \_ sendResponse -> do
1384+ application <- liftIO $ jsaddleOr defaultConnectionOptions entryPoint $ \_ sendResponse ->
1786− putStrLnDebug "sending response"
1787− r <- sendResponse $ responseLBS status200 [] $ "<!doctype html>\n" <> LBS.fromStrict html
1385+ sendResponse $ responseLBS status200 [] $ "<!doctype html>\n" <> LBS.fromStrict html
1788− putStrLnDebug "sent response"
1386+ port <- getFreePort
1790 waitJSaddle <- liftIO newEmptyMVar
1387 waitJSaddle <- liftIO newEmptyMVar
1791 let settings = foldr ($) Warp.defaultSettings
1388 let settings = foldr ($) Warp.defaultSettings
1792− [ Warp.setPort $ fromIntegral $ toInteger jsaddlePort
1389+ [ Warp.setPort $ fromIntegral (toInteger port)
1793− , Warp.setBeforeMainLoop $ do
1390+ , Warp.setBeforeMainLoop $ putMVar waitJSaddle ()
1794− putStrLnDebug "putting waitJSaddle"
1795− putMVar waitJSaddle ()
1796− putStrLnDebug "put waitJSaddle"
1798 -- hSilence to get rid of ConnectionClosed logs
1392 -- hSilence to get rid of ConnectionClosed logs
1799− silenceIfDebug = if withDebugging then id else hSilence [stderr]
1800− jsaddleWarp = silenceIfDebug $ Warp.runSettings settings application
1393+ jsaddleWarp = forkIO $ hSilence [stderr] $ Warp.runSettings settings application
1801− withAsync' jsaddleWarp $ do
1394+ jsaddleTid <- liftIO jsaddleWarp
1802− putStrLnDebug "taking waitJSaddle"
1803− liftIO $ takeMVar waitJSaddle
1395+ liftIO $ takeMVar waitJSaddle
1804− putStrLnDebug "opening page"
1805− WD.openPage $ "http://localhost:" <> show jsaddlePort
1396+ WD.openPage $ "http://localhost:" <> show port
1806− putStrLnDebug "running beforeJS"
1807− a <- beforeJS
1397+ a <- beforeJS
1808− putStrLnDebug "putting waitBeforeJS"
1809− liftIO $ putMVar waitBeforeJS ()
1398+ liftIO $ putMVar waitBeforeJS ()
1810− putStrLnDebug "taking waitUntilSwitchover"
1399+ liftIO $ takeMVar waitUntilSwitchover
1811− liftIO $ takeMVar waitUntilSwitchover
1400+ liftIO $ threadDelay 100000 -- wait a bit
1812− putStrLnDebug "running afterSwitchover"
1401+ b <- afterSwitchover a
1813− afterSwitchover a
1402+ liftIO $ killThread jsaddleTid
1815−withAsync' :: (MonadIO m, MonadMask m) => IO a -> m b -> m b
1406+-- TODO: Should this be part of more widely used module?
1816−withAsync' f g = bracket
1407+-- TODO: Ensure port is not taken
1817− (liftIO $ Async.async f)
1408+getFreePort :: MonadIO m => m PortNumber
1818− (liftIO . Async.uninterruptibleCancel)
1409+getFreePort = liftIO $ withSocketsDo $ do
1819− (const g)
1410+ addr:_ <- getAddrInfo (Just defaultHints) (Just "127.0.0.1") (Just "0")
1411+ bracket (open addr) close socketPort
1414+ sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
1415+ bind sock (addrAddress addr)
1418+testWidgetDebug :: MonadIO n => (forall m js. TestWidget js (SpiderTimeline Global) m => m ()) -> n ()
1419+testWidgetDebug bodyWidget = liftIO $ do
1421+ el "head" $ pure ()
1424+ el "script" $ text $ TE.decodeUtf8 $ LBS.toStrict $ jsaddleJs False
1425+ ((), html) <- renderStatic staticApp
1426+ let entryPoint = do
1427+ mainHydrationWidgetWithSwitchoverAction (pure ()) (pure ()) bodyWidget
1429+ application <- jsaddleOr defaultConnectionOptions entryPoint $ \_ sendResponse -> sendResponse $ responseLBS status200 [] $ "<!doctype html>\n" <> LBS.fromStrict html
1430+ Warp.runSettings (Warp.setPort 3911 Warp.defaultSettings) application
1821data Key2 a where
1432data Key2 a where
1822 Key2_Int :: Int -> Key2 Int
1433 Key2_Int :: Int -> Key2 Int
@@ -1825,4 +1436,18 @@ data Key2 a where
1825deriveGEq ''Key2
1436deriveGEq ''Key2
1826deriveGCompare ''Key2
1437deriveGCompare ''Key2
1827deriveGShow ''Key2
1438deriveGShow ''Key2
1828−deriveArgDict ''Key2
1439+
1440+instance ShowTag Key2 Identity where
1441+ showTaggedPrec = \case
1442+ Key2_Int _ -> showsPrec
1443+ Key2_Char _ -> showsPrec
1445+instance EqTag Key2 Identity where
1446+ eqTagged (Key2_Int _) (Key2_Int _) = (==)
1447+ eqTagged (Key2_Char _) (Key2_Char _) = (==)
1449+instance ArgDict Key2 where
1450+ type ConstraintsFor Key2 c = (c Int, c Char)
1453+ Key2_Char _ -> Dict