Revise tests
Link to fuzz test docs and Fuzzer docs Move part9 to be part12 Update part11 Update 12, and some other Mains Rearrange things, drop 2 modules Add a new part12 Fix READMEs Move some things up a directory Update part11 Use ! [] Update parts7-9 Fix part12g Swap part11 and part12 Fix readmes for part11 and part12 Add HtmlRunner to part8 Update part8 and part9 READMEs rm part10/test
This commit is contained in:
@@ -7,16 +7,21 @@ import Auth
|
||||
import Json.Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (..)
|
||||
import Dict exposing (Dict)
|
||||
import Http
|
||||
import Task
|
||||
|
||||
|
||||
getQueryUrl : String -> String
|
||||
getQueryUrl query =
|
||||
-- See https://developer.github.com/v3/search/#example for how to customize!
|
||||
"https://api.github.com/search/repositories?access_token="
|
||||
++ Auth.token
|
||||
++ "&q="
|
||||
++ query
|
||||
++ "+language:elm&sort=stars&order=desc"
|
||||
searchFeed : String -> Cmd Msg
|
||||
searchFeed query =
|
||||
let
|
||||
url =
|
||||
"https://api.github.com/search/repositories?access_token="
|
||||
++ Auth.token
|
||||
++ "&q="
|
||||
++ query
|
||||
++ "+language:elm&sort=stars&order=desc"
|
||||
in
|
||||
Task.perform HandleSearchError HandleSearchResponse (Http.get responseDecoder url)
|
||||
|
||||
|
||||
responseDecoder : Decoder (List SearchResult)
|
||||
@@ -92,35 +97,40 @@ type Msg
|
||||
= Search
|
||||
| SetQuery String
|
||||
| DeleteById ResultId
|
||||
| SetResults (List SearchResult)
|
||||
| SetErrorMessage (Maybe String)
|
||||
| HandleSearchResponse (List SearchResult)
|
||||
| HandleSearchError Http.Error
|
||||
| DoNothing
|
||||
|
||||
|
||||
update : (String -> Cmd Msg) -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update searchFeed msg model =
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
Search ->
|
||||
( model, searchFeed (getQueryUrl model.query) )
|
||||
model ! [ searchFeed model.query ]
|
||||
|
||||
SetQuery query ->
|
||||
( { model | query = query }, Cmd.none )
|
||||
{ model | query = query } ! []
|
||||
|
||||
SetResults results ->
|
||||
HandleSearchError error ->
|
||||
case error of
|
||||
Http.UnexpectedPayload str ->
|
||||
{ model | errorMessage = Just str } ! []
|
||||
|
||||
_ ->
|
||||
{ model | errorMessage = Just "Error loading search results" } ! []
|
||||
|
||||
HandleSearchResponse results ->
|
||||
let
|
||||
resultsById : Dict ResultId SearchResult
|
||||
resultsById =
|
||||
-- TODO convert results list into a Dict
|
||||
Dict.empty
|
||||
in
|
||||
( { model | results = resultsById }, Cmd.none )
|
||||
{ model | results = resultsById } ! []
|
||||
|
||||
DeleteById id ->
|
||||
-- TODO delete the result with the given id
|
||||
( model, Cmd.none )
|
||||
|
||||
SetErrorMessage errorMessage ->
|
||||
( { model | errorMessage = errorMessage }, Cmd.none )
|
||||
model ! []
|
||||
|
||||
DoNothing ->
|
||||
( model, Cmd.none )
|
||||
model ! []
|
||||
|
||||
@@ -1,31 +1,14 @@
|
||||
port module Main exposing (..)
|
||||
module Main exposing (..)
|
||||
|
||||
import ElmHub exposing (..)
|
||||
import Html.App
|
||||
import Json.Decode exposing (Value)
|
||||
|
||||
|
||||
main : Program Never
|
||||
main =
|
||||
Html.App.program
|
||||
{ view = view
|
||||
, update = update githubSearch
|
||||
, init = ( initialModel, githubSearch (getQueryUrl initialModel.query) )
|
||||
, subscriptions = \_ -> githubResponse decodeResponse
|
||||
, update = update
|
||||
, init = ( initialModel, searchFeed initialModel.query )
|
||||
, subscriptions = \_ -> Sub.none
|
||||
}
|
||||
|
||||
|
||||
decodeResponse : Json.Decode.Value -> Msg
|
||||
decodeResponse json =
|
||||
case Json.Decode.decodeValue responseDecoder json of
|
||||
Err err ->
|
||||
SetErrorMessage (Just err)
|
||||
|
||||
Ok results ->
|
||||
SetResults results
|
||||
|
||||
|
||||
port githubSearch : String -> Cmd msg
|
||||
|
||||
|
||||
port githubResponse : (Json.Decode.Value -> msg) -> Sub msg
|
||||
|
||||
@@ -21,8 +21,25 @@ elm-live Main.elm --open --output=elm.js
|
||||
|
||||
## Running Tests
|
||||
|
||||
First do this:
|
||||
|
||||
```bash
|
||||
cd test
|
||||
elm-package install
|
||||
elm-test Test.elm
|
||||
```
|
||||
|
||||
Then do either (or both!) of the following:
|
||||
|
||||
#### Running tests on the command line
|
||||
|
||||
```bash
|
||||
elm-test NodeRunner.elm
|
||||
```
|
||||
|
||||
#### Running tests in a browser
|
||||
|
||||
```bash
|
||||
elm-reactor
|
||||
```
|
||||
|
||||
Then visit [localhost:8000](http://localhost:8000) and choose `Html.elm`.
|
||||
|
||||
Reference in New Issue
Block a user