Updated site tests
Due to pages being generated to "/" instead of "pages/" some minor changes were required. Also some repeated code related to filtering and looking up html files was relocated to a function and improved. These tests still are not very comprehensive and there's definite room for improvement. One issue is when the tests are run they generate needless/useless analytics data. Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
This commit is contained in:
parent
5e9ff21813
commit
af5ab576fb
|
@ -110,5 +110,6 @@ Test-Suite test-site
|
||||||
webdriver >= 0.6,
|
webdriver >= 0.6,
|
||||||
process >= 1.2,
|
process >= 1.2,
|
||||||
directory >= 1.2,
|
directory >= 1.2,
|
||||||
text >= 1.2
|
text >= 1.2,
|
||||||
|
filepath >= 1.3
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
37
test/Main.hs
37
test/Main.hs
|
@ -25,7 +25,8 @@ import Control.Exception (bracket)
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import System.Process
|
import System.Process
|
||||||
import System.Directory (getDirectoryContents)
|
import System.FilePath (takeExtension)
|
||||||
|
import System.Directory (getDirectoryContents, doesFileExist)
|
||||||
import Test.Hspec.WebDriver
|
import Test.Hspec.WebDriver
|
||||||
import qualified Test.WebDriver.Commands.Wait as WDw
|
import qualified Test.WebDriver.Commands.Wait as WDw
|
||||||
import qualified Test.WebDriver.Session as WDs
|
import qualified Test.WebDriver.Session as WDs
|
||||||
|
@ -64,8 +65,9 @@ waitWhile = secsWhile waitTime
|
||||||
ensurePageLoaded :: WD ()
|
ensurePageLoaded :: WD ()
|
||||||
ensurePageLoaded = do
|
ensurePageLoaded = do
|
||||||
waitUntil $ findElem $ ById "page-content"
|
waitUntil $ findElem $ ById "page-content"
|
||||||
waitWhile $ findElem $ ByCSS "#page-content.loading"
|
-- TODO: add a few more element checks to replace the deprecated ones below
|
||||||
waitWhile $ findElem $ ByCSS "#status.error"
|
--waitWhile $ findElem $ ByCSS "#page-content.loading"
|
||||||
|
--waitWhile $ findElem $ ByCSS "#status.error"
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = runSiteServerWith $ hspec $ do
|
main = runSiteServerWith $ hspec $ do
|
||||||
|
@ -96,7 +98,7 @@ main = runSiteServerWith $ hspec $ do
|
||||||
|
|
||||||
describe "blog Page" $ do
|
describe "blog Page" $ do
|
||||||
it "is paginated" $ runWD $ do
|
it "is paginated" $ runWD $ do
|
||||||
openPage $ siteUrl ++ "/#/blog.html"
|
openPage $ siteUrl ++ "/blog1.html"
|
||||||
ensurePageLoaded
|
ensurePageLoaded
|
||||||
|
|
||||||
pagination <- findElem $ ById "pagination"
|
pagination <- findElem $ ById "pagination"
|
||||||
|
@ -107,14 +109,8 @@ main = runSiteServerWith $ hspec $ do
|
||||||
noFirstPage `shouldBeTag` "span"
|
noFirstPage `shouldBeTag` "span"
|
||||||
noPreviousPage `shouldBeTag` "span"
|
noPreviousPage `shouldBeTag` "span"
|
||||||
|
|
||||||
describe "invalid virtual URLS" $ do
|
describe "loads all pages (html files in site root)" $ do
|
||||||
context "when requested" $ do
|
pages <- runIO $ filterDir "_site"
|
||||||
it "show a error message dialog" $ runWD $ do
|
|
||||||
openPage $ siteUrl ++ "/#/thispagedoesnotexist.html"
|
|
||||||
waitUntil $ (findElem (ById "status") >>= isDisplayed)
|
|
||||||
|
|
||||||
describe "loads all pages (html files in pages/*)" $ do
|
|
||||||
pages <- runIO $ liftM (filter (flip notElem [".", ".."])) $ getDirectoryContents "_site/pages"
|
|
||||||
|
|
||||||
it "opens the app index page" $ runWD $ do
|
it "opens the app index page" $ runWD $ do
|
||||||
openPage siteUrl
|
openPage siteUrl
|
||||||
|
@ -122,20 +118,19 @@ main = runSiteServerWith $ hspec $ do
|
||||||
|
|
||||||
flip mapM_ pages $ \page -> do
|
flip mapM_ pages $ \page -> do
|
||||||
it ("opens the " ++ page ++ " page") $ runWD $ do
|
it ("opens the " ++ page ++ " page") $ runWD $ do
|
||||||
openPage $ siteUrl ++ "/#/" ++ page
|
openPage $ siteUrl ++ "/" ++ page
|
||||||
ensurePageLoaded
|
ensurePageLoaded
|
||||||
|
|
||||||
describe "Loads all posts (html files in posts/*)" $ do
|
describe "Loads all posts (html files in posts/*)" $ do
|
||||||
posts <- runIO $ liftM (filter (flip notElem [".", ".."])) $ getDirectoryContents "_site/posts"
|
posts <- runIO $ filterDir "_site/posts"
|
||||||
|
|
||||||
flip mapM_ posts $ \post -> do
|
flip mapM_ posts $ \post -> do
|
||||||
it ("opens post with filename " ++ post) $ runWD $ do
|
it ("opens post with filename " ++ post) $ runWD $ do
|
||||||
openPage $ siteUrl ++ "/#/posts/" ++ post
|
openPage $ siteUrl ++ "/posts/" ++ post
|
||||||
ensurePageLoaded
|
ensurePageLoaded
|
||||||
|
|
||||||
parallel $ session "Initialization tests" $ using [Firefox, Chrome] $ do
|
filterDir :: FilePath -> IO [FilePath]
|
||||||
it "shows a error message in page-content when an invalid url is accessed" $ runWD $ do
|
filterDir fp = do
|
||||||
openPage $ siteUrl ++ "/#/thisPageDoesNotExist.html"
|
dirList <- getDirectoryContents fp
|
||||||
|
filterM (\x -> doesFileExist x >>= \y ->
|
||||||
waitUntil $ findElem $ ById "page-content"
|
return (y && takeExtension x == ".html")) dirList
|
||||||
waitUntil $ findElem $ ByCSS "#page-content.init.loading-error"
|
|
||||||
|
|
Loading…
Reference in New Issue