🎨 elm-format
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
port module ElmHub exposing (..)
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (class, target, href, defaultValue, type_, checked, placeholder, value)
|
||||
import Html.Events exposing (..)
|
||||
import Auth
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (checked, class, defaultValue, href, placeholder, target, type_, value)
|
||||
import Html.Events exposing (..)
|
||||
import Json.Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (..)
|
||||
import String
|
||||
@@ -116,7 +116,7 @@ update msg model =
|
||||
newModel =
|
||||
{ model | results = newResults }
|
||||
in
|
||||
( newModel, Cmd.none )
|
||||
( newModel, Cmd.none )
|
||||
|
||||
DoNothing ->
|
||||
( model, Cmd.none )
|
||||
@@ -270,16 +270,17 @@ getQueryString : Model -> String
|
||||
Try identifying patterns and writing helper functions which are responsible for
|
||||
handling those patterns. Then have this function call them. Things to consider:
|
||||
|
||||
* There's pattern of adding "+foo:bar" - could we write a helper function for this?
|
||||
* In one case, if the "bar" in "+foo:bar" is empty, we want to return "" instead
|
||||
of "+foo:" - is this always true? Should our helper function always do that?
|
||||
* We also join query parameters together with "=" and "&" a lot. Can we give
|
||||
that pattern a similar treatment? Should we also take "?" into account?
|
||||
- There's pattern of adding "+foo:bar" - could we write a helper function for this?
|
||||
- In one case, if the "bar" in "+foo:bar" is empty, we want to return "" instead
|
||||
of "+foo:" - is this always true? Should our helper function always do that?
|
||||
- We also join query parameters together with "=" and "&" a lot. Can we give
|
||||
that pattern a similar treatment? Should we also take "?" into account?
|
||||
|
||||
If you have time, give this refactor a shot and see how it turns out!
|
||||
|
||||
Writing something out the long way like this, and then refactoring to something
|
||||
nicer, is generally the preferred way to go about building things in Elm.
|
||||
|
||||
-}
|
||||
getQueryString : Model -> String
|
||||
getQueryString model =
|
||||
@@ -291,7 +292,7 @@ getQueryString model =
|
||||
++ "+in:"
|
||||
++ model.options.searchIn
|
||||
++ "+stars:>="
|
||||
++ (toString model.options.minStars)
|
||||
++ toString model.options.minStars
|
||||
++ "+language:elm"
|
||||
++ (if String.isEmpty model.options.userFilter then
|
||||
""
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
module Tests exposing (..)
|
||||
|
||||
import Test exposing (..)
|
||||
import Fuzz exposing (..)
|
||||
import Expect exposing (Expectation)
|
||||
import ElmHub exposing (responseDecoder)
|
||||
import Json.Decode exposing (decodeString, Value)
|
||||
import Expect exposing (Expectation)
|
||||
import Fuzz exposing (..)
|
||||
import Json.Decode exposing (Value, decodeString)
|
||||
import String
|
||||
import Test exposing (..)
|
||||
|
||||
|
||||
all : Test
|
||||
@@ -25,10 +25,10 @@ all =
|
||||
Ok _ ->
|
||||
False
|
||||
in
|
||||
json
|
||||
|> decodeString responseDecoder
|
||||
|> isErrorResult
|
||||
|> Expect.true "Expected decoding an invalid response to return an Err."
|
||||
json
|
||||
|> decodeString responseDecoder
|
||||
|> isErrorResult
|
||||
|> Expect.true "Expected decoding an invalid response to return an Err."
|
||||
, test "it successfully decodes a valid response" <|
|
||||
\() ->
|
||||
"""{ "items": [
|
||||
@@ -54,11 +54,11 @@ all =
|
||||
json =
|
||||
"""{ "items": [""" ++ jsonItems ++ """] }"""
|
||||
in
|
||||
case decodeString responseDecoder json of
|
||||
Ok results ->
|
||||
List.length results
|
||||
|> Expect.equal (List.length ids)
|
||||
case decodeString responseDecoder json of
|
||||
Ok results ->
|
||||
List.length results
|
||||
|> Expect.equal (List.length ids)
|
||||
|
||||
Err err ->
|
||||
Expect.fail ("JSON decoding failed unexpectedly: " ++ err)
|
||||
Err err ->
|
||||
Expect.fail ("JSON decoding failed unexpectedly: " ++ err)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user