souplesse/frontend/tests/TrackTest.elm

58 lines
2.0 KiB
Elm

module TrackTest exposing (specs)
import Fixtures
import Track exposing (Track, Point)
import Test exposing (..)
import Expect exposing (Expectation)
import Time
specs: Test
specs =
describe "XML Parsing"
[ test "it parses points" <|
\_ ->
case Track.parse Fixtures.threepoints of
(Ok trk) -> Expect.equalLists Fixtures.threepoints_expected trk
_ -> Expect.fail "not ok"
, test "missing child ele node in track point" <|
\_ ->
let
xml = String.replace
"<ele>64.8</ele>"
""
Fixtures.threepoints
in
case Track.parse xml of
Ok (p::pts) ->
case p.loc of
(_, _, ele) -> Expect.equal ele Nothing
Ok _ -> Expect.fail "empty list"
(Err f) -> Expect.fail f
, test "heart rate" <|
\_ ->
let
xml = String.replace
"</gpxtpx:TrackPointExtension>"
"<gpxtpx:hr>97</gpxtpx:hr></gpxtpx:TrackPointExtension>"
Fixtures.threepoints
in
case Track.parse xml of
Ok (p::pts) ->
Expect.equal p.hr (Just 97)
Ok _ -> Expect.fail "no points"
(Err f) -> Expect.fail f
, test "multiple trksegs are coalesced" <|
\_ ->
let
xml = String.replace
"<!-- insert-segment -->"
"</trkseg><trkseg>"
Fixtures.threepoints
in
case Track.parse xml of
(Ok trk) -> Expect.equalLists Fixtures.threepoints_expected trk
_ -> Expect.fail "not ok"
]