mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 04:43:03 +03:00
Add prototype of elm-program-test setup.
This commit is contained in:
parent
55ac3da02d
commit
ec33b62323
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
117
examples/hello/tests/Tests.elm
Normal file
117
examples/hello/tests/Tests.elm
Normal file
@ -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 }
|
Loading…
Reference in New Issue
Block a user