Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yesod test add select by label #1845

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code optimizations
ktak-007 committed Aug 26, 2024
commit bc0e80ef0b67232c8bd68ea449158854b6504404
23 changes: 11 additions & 12 deletions yesod-test/Yesod/Test.hs
Original file line number Diff line number Diff line change
@@ -909,12 +909,7 @@ genericNameFromLabel match label = do
-- This looks up the name of a field based on a CSS selector and the contents of the label pointing to it.
genericNameFromSelectorLabel :: HasCallStack => (T.Text -> T.Text -> Bool) -> T.Text -> T.Text -> RequestBuilder site T.Text
genericNameFromSelectorLabel match selector label = do
mres <- fmap rbdResponse getSIO
res <-
case mres of
Nothing -> failure "genericNameSelectorFromLabel: No response available"
Just res -> return res
let body = simpleBody res
body <- htmlBody "genericNameSelectorFromLabel"
html <-
case findBySelector body selector of
Left parseError -> failure $ "genericNameFromSelectorLabel: Parse error" <> T.pack parseError
@@ -1754,12 +1749,7 @@ checkByLabel label = do
-- This looks up the value of a field based on the contents of the label pointing to it.
genericValueFromLabel :: HasCallStack => (T.Text -> T.Text -> Bool) -> T.Text -> RequestBuilder site T.Text
genericValueFromLabel match label = do
mres <- fmap rbdResponse getSIO
res <-
case mres of
Nothing -> failure "genericValueFromLabel: No response available"
Just res -> return res
let body = simpleBody res
body <- htmlBody "genericValueFromLabel"
case genericValueFromHTML match label body of
Left e -> failure e
Right x -> pure x
@@ -1797,3 +1787,12 @@ genericValueFromHTML match label html =
[] -> Left $ "No label contained: " <> label
value:_ -> Right value
_ -> Left $ "More than one label contained " <> label

htmlBody :: String -> RequestBuilder site BSL8.ByteString
htmlBody funcName = do
mres <- fmap rbdResponse getSIO
res <-
case mres of
Nothing -> failure $ T.pack $ funcName ++ ": No response available"
Just res -> return res
return $ simpleBody res