mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 06:05:31 +03:00
Add setup for passing in different pages and requests in static http test harness.
This commit is contained in:
parent
789cc59d88
commit
dab2e4b32c
@ -1,7 +1,7 @@
|
|||||||
module StaticHttpRequestsTests exposing (all)
|
module StaticHttpRequestsTests exposing (all)
|
||||||
|
|
||||||
import Codec
|
import Codec
|
||||||
import Dict
|
import Dict exposing (Dict)
|
||||||
import Expect
|
import Expect
|
||||||
import Html
|
import Html
|
||||||
import Json.Decode as Decode
|
import Json.Decode as Decode
|
||||||
@ -22,10 +22,10 @@ import Test exposing (Test, describe, test)
|
|||||||
|
|
||||||
all : Test
|
all : Test
|
||||||
all =
|
all =
|
||||||
describe "GrammarCheckingExample"
|
describe "Static Http Requests"
|
||||||
[ test "checking grammar" <|
|
[ test "initial requests are sent out" <|
|
||||||
\() ->
|
\() ->
|
||||||
start
|
start [ ( [], "https://api.github.com/repos/dillonkearns/elm-pages" ) ]
|
||||||
|> ProgramTest.simulateHttpOk
|
|> ProgramTest.simulateHttpOk
|
||||||
"GET"
|
"GET"
|
||||||
"https://api.github.com/repos/dillonkearns/elm-pages"
|
"https://api.github.com/repos/dillonkearns/elm-pages"
|
||||||
@ -50,8 +50,8 @@ all =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
start : ProgramTest Main.Model Main.Msg (Main.Effect PathKey)
|
start : List ( List String, String ) -> ProgramTest Main.Model Main.Msg (Main.Effect PathKey)
|
||||||
start =
|
start pages =
|
||||||
let
|
let
|
||||||
document =
|
document =
|
||||||
Document.fromList
|
Document.fromList
|
||||||
@ -63,13 +63,11 @@ start =
|
|||||||
]
|
]
|
||||||
|
|
||||||
content =
|
content =
|
||||||
[ ( []
|
pages
|
||||||
, { extension = "md"
|
|> List.map
|
||||||
, frontMatter = "null"
|
(\( path, _ ) ->
|
||||||
, body = Just ""
|
( path, { extension = "md", frontMatter = "null", body = Just "" } )
|
||||||
}
|
)
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
contentCache =
|
contentCache =
|
||||||
ContentCache.init document content
|
ContentCache.init document content
|
||||||
@ -90,7 +88,23 @@ start =
|
|||||||
, manifest = manifest
|
, manifest = manifest
|
||||||
, view =
|
, view =
|
||||||
\allFrontmatter page ->
|
\allFrontmatter page ->
|
||||||
StaticHttp.withData "https://api.github.com/repos/dillonkearns/elm-pages"
|
let
|
||||||
|
requestUrl =
|
||||||
|
pages
|
||||||
|
|> Dict.fromList
|
||||||
|
-- |> Debug.log "dict"
|
||||||
|
|> Dict.get
|
||||||
|
(page.path
|
||||||
|
|> PagePath.toString
|
||||||
|
|> String.dropLeft 1
|
||||||
|
|> String.split "/"
|
||||||
|
|> List.filter (\pathPart -> pathPart /= "")
|
||||||
|
-- |> Debug.log "lookup"
|
||||||
|
)
|
||||||
|
|> Maybe.withDefault "Couldn't find request..."
|
||||||
|
in
|
||||||
|
StaticHttp.withData requestUrl
|
||||||
|
-- "https://api.github.com/repos/dillonkearns/elm-pages"
|
||||||
(Decode.field "stargazers_count" Decode.int)
|
(Decode.field "stargazers_count" Decode.int)
|
||||||
(\staticData ->
|
(\staticData ->
|
||||||
{ view =
|
{ view =
|
||||||
|
Loading…
Reference in New Issue
Block a user