packages feed

yesod-static-angular-0.1.0: example/tests/end2end/todo.hs

{-# LANGUAGE OverloadedStrings #-}

-- Requires hspec-webdriver 0.2.* and webdriver-angular 0.1.*
import Test.Hspec.WebDriver
import Test.WebDriver.Commands.Angular

main :: IO ()
main = hspec $ do
    session "Todo list" $ using Firefox $ do
        it "opens the page" $ runWD $ do
            openPage "http://localhost:3000"

            -- This will wait until angular has finished rendering the page.
            -- The CSS selector references the element which contains ng-app, in this
            -- example the div directly below body.
            waitForAngular "body > div" `shouldReturn` True

        it "should find the initial todo" $ runWD $ do
            -- Check the initial text
            binding <- findNg $ ByBinding "{{todos.length}}"
            binding `shouldHaveText` "1 of 2 remaining ["

        it "should add a todo" $ runWD $ do
            -- Add a new todo
            txt <- findNg $ ByModel "todoText"
            sendKeys "My todo" txt
            btn <- findElem $ ByCSS "input.btn-primary"
            click btn

            -- Check it updated things properly
            binding <- findNg $ ByBinding "{{todos.length}}"
            binding `shouldHaveText` "2 of 3 remaining ["

        it "should find the new todo by repeaters" $ runWD $ do
            new <- findRepeater $ ByRow "todo in todos" 2
            new `shouldBeTag` "li"
            new `shouldHaveText` "My todo"

            [r1, r2, r3] <- findRepeaters $ ByRows "todo in todos"
            r1 `shouldBeTag` "li"
            r2 `shouldBeTag` "li"
            r3 `shouldBeTag` "li"
            r1 `shouldHaveText` "learn angular"
            r2 `shouldHaveText` "integrate angular with your yesod app"
            r3 `shouldHaveText` "My todo"

            -- Note that if you try out the ByColumn repeaters it won't work because of
            -- https://github.com/angular/angular.js/issues/4383 (see also
            -- https://github.com/angular/protractor/issues/158) because the todo list uses
            -- bindings in the class element.  If you remove the class binding from the span,
            -- the ByColumn repeaters do start working.