1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-23 12:52:31 +03:00

[tests] Category properties → Pros/cons enabled

This commit is contained in:
Artyom 2016-08-29 23:38:17 +03:00
parent c54b1ee287
commit 7d6a760f63
2 changed files with 65 additions and 6 deletions

View File

@ -735,8 +735,8 @@ renderCategoryInfo category = cached (CacheCategoryInfo (category^.uid)) $ do
& checkedIf (category^.ecosystemEnabled) & checkedIf (category^.ecosystemEnabled)
"“Ecosystem” field enabled" "“Ecosystem” field enabled"
br_ [] br_ []
input_ [type_ "submit", value_ "Save"] input_ [type_ "submit", value_ "Save", class_ "save"]
button "Cancel" [] $ button "Cancel" [class_ "cancel"] $
JS.switchSection (this, "normal" :: Text) JS.switchSection (this, "normal" :: Text)
renderCategoryNotes :: MonadIO m => Category -> HtmlT m () renderCategoryNotes :: MonadIO m => Category -> HtmlT m ()
@ -778,6 +778,7 @@ renderCategory category = cached (CacheCategory (category^.uid)) $ do
mapM_ (renderItem category) (category^.items) mapM_ (renderItem category) (category^.items)
thisNode thisNode
textInput [ textInput [
class_ " add-item ",
placeholder_ "add an item", placeholder_ "add an item",
autocomplete_ "off", autocomplete_ "off",
onEnter $ JS.addItem (itemsNode, category^.uid, inputValue) <> onEnter $ JS.addItem (itemsNode, category^.uid, inputValue) <>

View File

@ -175,11 +175,29 @@ categoryTests = session "categories" $ using Firefox $ do
sel <- select (form :// "select[name=status]") sel <- select (form :// "select[name=status]")
opt <- select (sel :// HasText "Complete") opt <- select (sel :// HasText "Complete")
selectDropdown sel opt selectDropdown sel opt
click =<< select (form :// "[type=submit]") click =<< select (form :// ".save")
onAnotherPage "/" $ do onAnotherPage "/" $ do
catLink <- select (ByLinkText "Cat 2") catLink <- select (ByLinkText "Cat 2")
catLink `shouldHaveAttr` ("class", "status-finished") catLink `shouldHaveAttr` ("class", "status-finished")
-- Pros/cons enabled describe "pros/cons enabled" $ do
wd "checkbox enabled by default" $ do
form <- openCategoryEditForm
check <- select (form :// HasText "Pros/cons enabled" :// "input")
shouldBeSelected check
click =<< select (form :// ".cancel")
wd "section is shown in an item" $ do
createItem "some item"
shouldBeDisplayed =<< select ".item-traits"
wd "section isn't shown after unchecking the checkbox" $ do
form <- openCategoryEditForm
click =<< select (form :// HasText "Pros/cons enabled" :// "input")
click =<< select (form :// ".save")
waitUntil 2 (expect . not =<< isDisplayed =<< select ".item-traits")
wd "section is shown again after checking the checkbox" $ do
form <- openCategoryEditForm
click =<< select (form :// HasText "Pros/cons enabled" :// "input")
click =<< select (form :// ".save")
waitUntil 2 (expect =<< isDisplayed =<< select ".item-traits")
-- Ecosystem enabled -- Ecosystem enabled
-- Save works -- Save works
-- Cancel works -- Cancel works
@ -233,6 +251,19 @@ createCategory :: Text -> WD ()
createCategory t = createCategory t =
changesURL $ sendKeys (t <> _enter) =<< select ".add-category" changesURL $ sendKeys (t <> _enter) =<< select ".add-category"
-- Assumes that the category page is open
createItem :: Text -> WD Element
createItem t = do
let selectItems = selectAll ".item"
items <- selectItems
sendKeys (t <> _enter) =<< select ".add-item"
waitUntil 2 (expect . (\xs -> length xs > length items) =<< selectItems)
items2 <- selectItems
case items2 \\ items of
[] -> expectationFailure "an item wasn't created"
[x] -> return x
_ -> expectationFailure "more than one item was created"
categoryTitle :: Selector categoryTitle :: Selector
categoryTitle = ByCSS ".category-title" categoryTitle = ByCSS ".category-title"
@ -242,12 +273,19 @@ categoryGroup = ByCSS ".category .group"
openCategoryEditForm :: WD Element openCategoryEditForm :: WD Element
openCategoryEditForm = do openCategoryEditForm = do
click =<< select (".category h2" :// ByLinkText "edit") click =<< select (".category h2" :// ByLinkText "edit")
select ".category form" selectWait ".category-info form"
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Utilities for webdriver -- Utilities for webdriver
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
highlight :: Element -> WD ()
highlight e = do
html <- executeJS [JSArg e]
"arguments[0].style.border='thick solid #FF0000';\
\return arguments[0].outerHTML;"
liftIO $ putStrLn html
selectDropdown selectDropdown
:: Element -- ^ Dropdown :: Element -- ^ Dropdown
-> Element -- ^ Option to select -> Element -- ^ Option to select
@ -266,7 +304,7 @@ getChildren :: Element -> WD [Element]
getChildren e = findElemsFrom e (ByXPath "./*") getChildren e = findElemsFrom e (ByXPath "./*")
data ComplexSelector where data ComplexSelector where
-- | Descendants -- | Descendants (not including the element itself)
(://) :: (CanSelect a, CanSelect b) => a -> b -> ComplexSelector (://) :: (CanSelect a, CanSelect b) => a -> b -> ComplexSelector
-- | Children -- | Children
(:/) :: (CanSelect a, CanSelect b) => a -> b -> ComplexSelector (:/) :: (CanSelect a, CanSelect b) => a -> b -> ComplexSelector
@ -286,6 +324,8 @@ data ComplexSelector where
ContainsText :: Text -> ComplexSelector ContainsText :: Text -> ComplexSelector
-- | Only pick the first N selected elements -- | Only pick the first N selected elements
Take :: CanSelect a => Int -> a -> ComplexSelector Take :: CanSelect a => Int -> a -> ComplexSelector
-- | Displayed element
Displayed :: ComplexSelector
deriving instance Show ComplexSelector deriving instance Show ComplexSelector
@ -338,15 +378,18 @@ instance CanSelect ComplexSelector where
Not a -> defSelectAll (Not a) Not a -> defSelectAll (Not a)
HasText t -> defSelectAll (HasText t) HasText t -> defSelectAll (HasText t)
ContainsText t -> defSelectAll (ContainsText t) ContainsText t -> defSelectAll (ContainsText t)
Displayed -> defSelectAll Displayed
filterElems s es = case s of filterElems s es = case s of
Not a -> (es \\) <$> filterElems a es Not a -> (es \\) <$> filterElems a es
HasText t -> filterM (fmap (== t) . getText) es HasText t -> filterM (fmap (== t) . getText) es
ContainsText t -> filterM (fmap (t `T.isInfixOf`) . getText) es ContainsText t -> filterM (fmap (t `T.isInfixOf`) . getText) es
Displayed -> filterM isDisplayed es
_ -> defFilterElems s es _ -> defFilterElems s es
anyElem s es = case s of anyElem s es = case s of
Not a -> (== length es) . length <$> filterElems a es Not a -> (== length es) . length <$> filterElems a es
HasText t -> anyM (fmap (== t) . getText) es HasText t -> anyM (fmap (== t) . getText) es
ContainsText t -> anyM (fmap (t `T.isInfixOf`) . getText) es ContainsText t -> anyM (fmap (t `T.isInfixOf`) . getText) es
Displayed -> anyM isDisplayed es
_ -> defAnyElem s es _ -> defAnyElem s es
class ToSelector a where class ToSelector a where
@ -499,6 +542,21 @@ e `shouldHaveProp` (a, txt) = do
printf "expected property %s of %s to be %s, got %s" printf "expected property %s of %s to be %s, got %s"
a (show e) (show txt) (show t) a (show e) (show txt) (show t)
shouldBeSelected :: Element -> WD ()
shouldBeSelected a = do
x <- isSelected a
a `shouldSatisfy` ("be checked/selected", const x)
shouldBeDisplayed :: Element -> WD ()
shouldBeDisplayed a = do
x <- isDisplayed a
a `shouldSatisfy` ("be displayed", const x)
shouldBeHidden :: Element -> WD ()
shouldBeHidden a = do
x <- isDisplayed a
a `shouldSatisfy` ("be hidden", const (not x))
_backspace, _enter, _esc :: Text _backspace, _enter, _esc :: Text
(_backspace, _enter, _esc) = ("\xE003", "\xE007", "\xE00C") (_backspace, _enter, _esc) = ("\xE003", "\xE007", "\xE00C")
_shift, _ctrl, _alt, _command :: Text _shift, _ctrl, _alt, _command :: Text