2019-10-22 05:11:50 +03:00
|
|
|
|
module StaticHttpRequestsTests exposing (all)
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
2019-10-22 08:00:15 +03:00
|
|
|
|
import Codec
|
2019-10-22 04:49:46 +03:00
|
|
|
|
import Dict
|
2019-10-22 06:21:52 +03:00
|
|
|
|
import Expect
|
2019-10-22 04:49:46 +03:00
|
|
|
|
import Html
|
|
|
|
|
import Json.Decode as Decode
|
|
|
|
|
import Pages.ContentCache as ContentCache
|
|
|
|
|
import Pages.Document as Document
|
|
|
|
|
import Pages.ImagePath as ImagePath
|
2019-10-22 05:31:17 +03:00
|
|
|
|
import Pages.Internal.Platform.Cli as Main exposing (..)
|
2019-10-22 04:49:46 +03:00
|
|
|
|
import Pages.Manifest as Manifest
|
|
|
|
|
import Pages.PagePath as PagePath
|
|
|
|
|
import Pages.StaticHttp as StaticHttp
|
2019-10-22 05:31:17 +03:00
|
|
|
|
import Pages.StaticHttpRequest as StaticHttpRequest
|
2019-10-22 04:49:46 +03:00
|
|
|
|
import ProgramTest exposing (ProgramTest)
|
2019-10-22 05:31:17 +03:00
|
|
|
|
import SimulatedEffect.Cmd
|
|
|
|
|
import SimulatedEffect.Http
|
2019-10-22 06:21:52 +03:00
|
|
|
|
import SimulatedEffect.Ports
|
2019-10-22 05:11:50 +03:00
|
|
|
|
import Test exposing (Test, describe, test)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
all : Test
|
|
|
|
|
all =
|
|
|
|
|
describe "GrammarCheckingExample"
|
|
|
|
|
[ test "checking grammar" <|
|
|
|
|
|
\() ->
|
|
|
|
|
start
|
2019-10-22 05:56:48 +03:00
|
|
|
|
|> ProgramTest.simulateHttpOk
|
|
|
|
|
"GET"
|
|
|
|
|
"https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
|
"null"
|
2019-10-22 08:00:15 +03:00
|
|
|
|
|> ProgramTest.expectOutgoingPortValues
|
2019-10-22 06:21:52 +03:00
|
|
|
|
"toJsPort"
|
2019-10-22 08:00:15 +03:00
|
|
|
|
(Codec.decoder Main.toJsCodec)
|
|
|
|
|
(Expect.equal
|
|
|
|
|
[ Main.Success
|
|
|
|
|
{ pages =
|
|
|
|
|
Dict.fromList
|
|
|
|
|
[ ( "/"
|
|
|
|
|
, Dict.fromList
|
|
|
|
|
[ ( "https://api.github.com/repos/dillonkearns/elm-pages", "" )
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
]
|
2019-10-22 09:02:31 +03:00
|
|
|
|
, manifest = manifest
|
2019-10-22 08:00:15 +03:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
)
|
2019-10-22 05:11:50 +03:00
|
|
|
|
]
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
|
|
|
|
|
2019-10-22 09:02:31 +03:00
|
|
|
|
start : ProgramTest Main.Model Main.Msg (Main.Effect PathKey)
|
2019-10-22 04:49:46 +03:00
|
|
|
|
start =
|
|
|
|
|
let
|
|
|
|
|
document =
|
2019-10-22 05:56:48 +03:00
|
|
|
|
Document.fromList
|
|
|
|
|
[ Document.parser
|
|
|
|
|
{ extension = "md"
|
|
|
|
|
, metadata = Decode.succeed ()
|
|
|
|
|
, body = \_ -> Ok ()
|
|
|
|
|
}
|
|
|
|
|
]
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
|
|
|
|
content =
|
2019-10-22 05:56:48 +03:00
|
|
|
|
[ ( []
|
|
|
|
|
, { extension = "md"
|
|
|
|
|
, frontMatter = "null"
|
|
|
|
|
, body = Just ""
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
]
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|
|
|
|
|
contentCache =
|
|
|
|
|
ContentCache.init document content
|
|
|
|
|
|
|
|
|
|
siteMetadata =
|
|
|
|
|
contentCache
|
|
|
|
|
|> Result.map
|
|
|
|
|
(\cache -> cache |> ContentCache.extractMetadata PathKey)
|
|
|
|
|
|> Result.mapError
|
|
|
|
|
(\error ->
|
|
|
|
|
error
|
|
|
|
|
|> Dict.toList
|
|
|
|
|
|> List.map (\( path, errorString ) -> errorString)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
config =
|
|
|
|
|
{ toJsPort = toJsPort
|
|
|
|
|
, manifest = manifest
|
|
|
|
|
, view =
|
|
|
|
|
\allFrontmatter page ->
|
|
|
|
|
StaticHttp.withData "https://api.github.com/repos/dillonkearns/elm-pages"
|
|
|
|
|
(Decode.field "stargazers_count" Decode.int)
|
|
|
|
|
(\staticData ->
|
|
|
|
|
{ view =
|
|
|
|
|
\model viewForPage ->
|
|
|
|
|
{ title = "Title"
|
|
|
|
|
, body =
|
|
|
|
|
"elm-pages ⭐️'s: "
|
|
|
|
|
++ String.fromInt staticData
|
|
|
|
|
|> Html.text
|
|
|
|
|
}
|
|
|
|
|
, head = []
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
in
|
|
|
|
|
ProgramTest.createDocument
|
|
|
|
|
{ init = Main.init identity contentCache siteMetadata config identity
|
|
|
|
|
, update = Main.update siteMetadata config
|
|
|
|
|
, view = \_ -> { title = "", body = [ Html.text "" ] }
|
|
|
|
|
}
|
2019-10-22 05:31:17 +03:00
|
|
|
|
|> ProgramTest.withSimulatedEffects simulateEffects
|
2019-10-22 04:49:46 +03:00
|
|
|
|
|> ProgramTest.start ()
|
|
|
|
|
|
|
|
|
|
|
2019-10-22 09:02:31 +03:00
|
|
|
|
simulateEffects : Main.Effect PathKey -> ProgramTest.SimulatedEffect Main.Msg
|
2019-10-22 05:31:17 +03:00
|
|
|
|
simulateEffects effect =
|
|
|
|
|
case effect of
|
|
|
|
|
NoEffect ->
|
|
|
|
|
SimulatedEffect.Cmd.none
|
|
|
|
|
|
|
|
|
|
SendJsData value ->
|
2019-10-22 08:00:15 +03:00
|
|
|
|
SimulatedEffect.Ports.send "toJsPort" (value |> Codec.encoder Main.toJsCodec)
|
2019-10-22 05:31:17 +03:00
|
|
|
|
|
|
|
|
|
-- toJsPort value |> Cmd.map never
|
|
|
|
|
Batch list ->
|
|
|
|
|
list
|
|
|
|
|
|> List.map simulateEffects
|
|
|
|
|
|> SimulatedEffect.Cmd.batch
|
|
|
|
|
|
|
|
|
|
FetchHttp (StaticHttpRequest.Request { url }) ->
|
|
|
|
|
SimulatedEffect.Http.get
|
|
|
|
|
{ url = url
|
|
|
|
|
, expect =
|
|
|
|
|
SimulatedEffect.Http.expectString
|
|
|
|
|
(\response ->
|
|
|
|
|
Main.GotStaticHttpResponse
|
|
|
|
|
{ url = url
|
|
|
|
|
, response = response
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-10-22 04:49:46 +03:00
|
|
|
|
toJsPort foo =
|
|
|
|
|
Cmd.none
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type PathKey
|
|
|
|
|
= PathKey
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
manifest : Manifest.Config PathKey
|
|
|
|
|
manifest =
|
|
|
|
|
{ backgroundColor = Nothing
|
|
|
|
|
, categories = []
|
|
|
|
|
, displayMode = Manifest.Standalone
|
|
|
|
|
, orientation = Manifest.Portrait
|
|
|
|
|
, description = "elm-pages - A statically typed site generator."
|
|
|
|
|
, iarcRatingId = Nothing
|
|
|
|
|
, name = "elm-pages docs"
|
|
|
|
|
, themeColor = Nothing
|
2019-10-22 09:02:31 +03:00
|
|
|
|
, startUrl = PagePath.external ""
|
2019-10-22 04:49:46 +03:00
|
|
|
|
, shortName = Just "elm-pages"
|
2019-10-22 09:02:31 +03:00
|
|
|
|
, sourceIcon = ImagePath.external ""
|
2019-10-22 04:49:46 +03:00
|
|
|
|
}
|