diff --git a/examples/hello/elm.json b/examples/hello/elm.json index 546b4839..582616a7 100644 --- a/examples/hello/elm.json +++ b/examples/hello/elm.json @@ -45,7 +45,15 @@ } }, "test-dependencies": { - "direct": {}, - "indirect": {} + "direct": { + "avh4/elm-program-test": "3.6.3", + "elm-explorations/test": "1.2.2" + }, + "indirect": { + "avh4/elm-fifo": "1.0.4", + "elm/random": "1.0.0", + "hecrj/html-parser": "2.4.0", + "mgold/elm-nonempty-list": "4.2.0" + } } } diff --git a/examples/hello/tests/Tests.elm b/examples/hello/tests/Tests.elm new file mode 100644 index 00000000..1c0ff9aa --- /dev/null +++ b/examples/hello/tests/Tests.elm @@ -0,0 +1,117 @@ +module Tests exposing (suite) + +import Browser +import Main +import Pages.Flags exposing (Flags(..)) +import Path +import ProgramTest +import Route +import Test exposing (Test, test) +import Test.Html.Selector exposing (text) + + +suite : Test +suite = + test "wire up hello" <| + \() -> + start + |> ProgramTest.clickButton "Open Menu" + |> ProgramTest.expectViewHas + [ text "elm-pages is up and running!" + , text "Close Menu" + ] + + +start = + ProgramTest.createApplication + { onUrlRequest = + \urlRequest -> + case urlRequest of + Browser.Internal url -> + Main.OnPageChange + { protocol = url.protocol + , host = url.host + , port_ = url.port_ + , path = url.path |> Path.fromString + , query = url.query + , fragment = url.fragment + , metadata = route + } + + Browser.External _ -> + Debug.todo "Unhandled" + , onUrlChange = + \url -> + Main.OnPageChange + { protocol = url.protocol + , host = url.host + , port_ = url.port_ + , path = url.path |> Path.fromString + , query = url.query + , fragment = url.fragment + , metadata = route + } + , init = + \flags initialUrl () -> + Main.init + sharedModel + flags + sharedData + pageData + -- navKey + Nothing + -- Path and stuff + (Just + { path = + { path = Path.join [] + , query = Nothing + , fragment = Nothing + } + , metadata = route + , pageUrl = Nothing -- TODO --Maybe PageUrl + } + ) + , update = + \msg model -> + Main.update + sharedData + pageData + Nothing + msg + model + , view = + \model -> + model + |> (Main.view + { path = path + , route = route + } + Nothing + sharedData + pageData + |> .view + ) + |> (\{ title, body } -> { title = title, body = [ body ] }) + } + |> ProgramTest.withBaseUrl "https://my-app.com/" + |> ProgramTest.start Pages.Flags.PreRenderFlags + + +path = + Path.join [] + + +sharedData = + () + + +pageData = + Main.DataIndex {} + + +route = + Just Route.Index + + +sharedModel = + Just { showMenu = False }