spec :: Spec
spec = withApp $ do
  it "tests the connection" $ do
    get ("http://localhost:3000" :: String)
    statusIs 303

  it "tests the form contents" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200
    htmlAllContain ".articleDetail .articleDetailHead .pageTitle"
      "Delimited continuations and nested transactions"

  it "tests the form structure" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200

    [form] <- htmlQuery "#blogLoginForm"

    let cursor = parseHTML form
        XML.NodeElement (XML.Element name attr _nodes)   = XMLCursor.node cursor
        Just action = Map.lookup "action" attr

    liftIO $ I.unpack action `shouldStartWith` "/blog/"

  it "tests the form submission" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200

    [form] <- htmlQuery "#blogLoginForm"

    let cursor = parseHTML form
        XML.NodeElement (XML.Element name attr _nodes)   = XMLCursor.node cursor
        Just action = Map.lookup "action" attr

    liftIO $ I.unpack action `shouldStartWith` "/blog/"

    let req = do setMethod methodPost
                 --setUrl $ "http://localhost:3000" ++ I.unpack action
                 setUrl $ "http://localhost:3000" ++ I.unpack action
                 byLabel "Enter the user name:" "root"
                 byLabel "Enter the password" "root"
                 addPostParam "_formid" "userForm"
                 addToken
    I.request req
    statusIs 200

    bodyContains "You are logged in as root."


  it "tests the login form" $ do
    login

  it "benchmarks the continuation" $ do
    let i = 250
        i' = 2
    putTime
    forM [1..i'] $ \_ -> do
      login
      logout
      login
      newArticle
      cancel
      newArticle
      submit
      newArticle
      preview
      cancelPreview
      newArticle
      preview
      submitPreview

    putTime




----------------------------  Login Page  ----------------------------
spec :: Spec
spec = withApp $ do
  it "tests the connection" $ do
    get ("http://localhost:3000" :: String)
    statusIs 303

  it "tests the form contents" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200
    htmlAllContain ".articleDetail .articleDetailHead .pageTitle"
      "Delimited continuations and nested transactions"

  it "tests the form structure" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200

    [form] <- htmlQuery "#blogLoginForm"

    let cursor = parseHTML form
        XML.NodeElement (XML.Element name attr _nodes)   = XMLCursor.node cursor
        Just action = Map.lookup "action" attr

    liftIO $ I.unpack action `shouldStartWith` "/blog/"

  it "tests the form submission" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200

    [form] <- htmlQuery "#blogLoginForm"

    let cursor = parseHTML form
        XML.NodeElement (XML.Element name attr _nodes)   = XMLCursor.node cursor
        Just action = Map.lookup "action" attr

    liftIO $ I.unpack action `shouldStartWith` "/blog/"

    let req = do setMethod methodPost
                 --setUrl $ "http://localhost:3000" ++ I.unpack action
                 setUrl $ "http://localhost:3000" ++ I.unpack action
                 byLabel "Enter the user name:" "root"
                 byLabel "Enter the password" "root"
                 addPostParam "_formid" "userForm"
                 addToken
    I.request req
    statusIs 200

    bodyContains "You are logged in as root."


  it "tests the login form" $ do
    login

  it "benchmarks the continuation" $ do
    let i = 250
        i' = 2
    putTime
    forM [1..i'] $ \_ -> do
      login
      logout
      login
      newArticle
      cancel
      newArticle
      submit
      newArticle
      preview
      cancelPreview
      newArticle
      preview
      submitPreview

    putTime




----------------------------  Login Page  ----------------------------
spec = withApp $ do
  it "tests the connection" $ do
    get ("http://localhost:3000" :: String)
    statusIs 303

  it "tests the form contents" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200
    htmlAllContain ".articleDetail .articleDetailHead .pageTitle"
      "Delimited continuations and nested transactions"

  it "tests the form structure" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200

    [form] <- htmlQuery "#blogLoginForm"

    let cursor = parseHTML form
        XML.NodeElement (XML.Element name attr _nodes)   = XMLCursor.node cursor
        Just action = Map.lookup "action" attr

    liftIO $ I.unpack action `shouldStartWith` "/blog/"

  it "tests the form submission" $ do
    get ("http://localhost:3000/blog" :: String)
    statusIs 200

    [form] <- htmlQuery "#blogLoginForm"

    let cursor = parseHTML form
        XML.NodeElement (XML.Element name attr _nodes)   = XMLCursor.node cursor
        Just action = Map.lookup "action" attr

    liftIO $ I.unpack action `shouldStartWith` "/blog/"

    let req = do setMethod methodPost
                 --setUrl $ "http://localhost:3000" ++ I.unpack action
                 setUrl $ "http://localhost:3000" ++ I.unpack action
                 byLabel "Enter the user name:" "root"
                 byLabel "Enter the password" "root"
                 addPostParam "_formid" "userForm"
                 addToken
    I.request req
    statusIs 200

    bodyContains "You are logged in as root."


  it "tests the login form" $ do
    login

  it "benchmarks the continuation" $ do
    let i = 250
        i' = 2
    putTime
    forM [1..i'] $ \_ -> do
      login
      logout
      login
      newArticle
      cancel
      newArticle
      submit
      newArticle
      preview
      cancelPreview
      newArticle
      preview
      submitPreview

    putTime




----------------------------  Login Page  ----------------------------