yesodyesod-forms

Getting "More than one input with id content" in yesod-test response


I'm following Esposito's Yesod tutorial and trying to put a test around the Mirror example.

My test is cribbed from the HomeTest.hs file included from yesod init:

{-# LANGUAGE OverloadedStrings #-}
module MirrorTest
    ( mirrorSpecs
    ) where

import TestImport
import qualified Data.List as L

mirrorSpecs :: Spec
mirrorSpecs =
    ydescribe "This tests the sample mirror feature" $ do

        yit "loads the mirror page and checks it has correct elements" $ do
            get MirrorR
            statusIs 200
            htmlAllContain "h1" "Mirror test"
            htmlAllContain "label" "Enter your text"

            request $ do
                setMethod "POST"
                setUrl MirrorR
                byLabel "Enter your text" "wooo"

            statusIs 200
            printBody
            htmlCount ".p" 1
            htmlAllContain ".h1" "You posted"
            htmlAllContain ".p" "woooooow"
            htmlAllContain ".p" "text/plain"

Meanwhile my mirror.hamlet file is:

<h1> Mirror test
<form method=post action=@{MirrorR}>
    <label for=content>Enter your text
    <input type=text name=content>
    <input type=submit>

But the test output I am getting is:

1) This tests the sample mirror feature loads the mirror page and checks it has correct elements
More than one input with id content

I'm confused: only one input has the name of content, while more than one element has that name, but as far as I recall names are not necessarily unique (different from actual ids). Am I going to need to use Yesod.Test.TransversingCSS just to accomplish what I want to do here, by giving the input an actual id?

My Haskell is still pretty weak, so I may be missing the obvious, and examples of how to implement tests in Yesod are greatly appreciated.


Solution

  • I don't get the same error message you do. Instead, the error message I see is:

    No input with id content

    This may be due to differing yesod-form versions. This error message is completely accurate, and indicates a real error. The for attribute of a label refers to a tag's id, not its name. Please try setting the id attribute on your input to content and see if that solves your problems.