github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/tests/PaginationTests.elm (about) 1 module PaginationTests exposing (all, responseWithHeaders) 2 3 import Ansi.Log 4 import Api.Pagination 5 import Array 6 import Concourse.Pagination exposing (Direction(..), Pagination) 7 import Dict exposing (Dict) 8 import Expect exposing (..) 9 import Http 10 import String 11 import Test exposing (..) 12 13 14 all : Test 15 all = 16 describe "Pagination" 17 [ describe "parsing Link headers" 18 [ test "with no headers present" <| 19 \_ -> 20 responseWithHeaders Dict.empty 21 |> Api.Pagination.parseLinks 22 |> Expect.equal 23 { previousPage = Nothing 24 , nextPage = Nothing 25 } 26 , test "with a Link rel=\"previous\" present" <| 27 \_ -> 28 responseWithHeaders withPreviousLink 29 |> Api.Pagination.parseLinks 30 |> Expect.equal 31 { previousPage = 32 Just { direction = From 1, limit = 2 } 33 , nextPage = Nothing 34 } 35 , test "with a Link rel=\"next\" present" <| 36 \_ -> 37 responseWithHeaders withNextLink 38 |> Api.Pagination.parseLinks 39 |> Expect.equal 40 { previousPage = Nothing 41 , nextPage = 42 Just { direction = To 1, limit = 2 } 43 } 44 , test "with a Link rel=\"previous\" and a Link rel=\"next\" present" <| 45 \_ -> 46 responseWithHeaders withPreviousAndNextLink 47 |> Api.Pagination.parseLinks 48 |> Expect.equal 49 { previousPage = 50 Just { direction = From 3, limit = 2 } 51 , nextPage = 52 Just { direction = To 1, limit = 4 } 53 } 54 , test "with malformed link header" <| 55 \_ -> 56 responseWithHeaders withMalformedLink 57 |> Api.Pagination.parseLinks 58 |> Expect.equal 59 { previousPage = Nothing 60 , nextPage = Nothing 61 } 62 ] 63 ] 64 65 66 responseWithHeaders : Dict String String -> Http.Response String 67 responseWithHeaders headers = 68 { status = { code = 200, message = "OK" } 69 , headers = headers 70 , url = "https://example.com" 71 , body = "" 72 } 73 74 75 withPreviousLink : Dict String String 76 withPreviousLink = 77 Dict.fromList 78 [ ( "Link" 79 , "<https://example.com/previous?from=1&limit=2>; rel=\"previous\"" 80 ) 81 ] 82 83 84 withNextLink : Dict String String 85 withNextLink = 86 Dict.fromList 87 [ ( "Link" 88 , "<https://example.com/next?to=1&limit=2>; rel=\"next\"" 89 ) 90 ] 91 92 93 withPreviousAndNextLink : Dict String String 94 withPreviousAndNextLink = 95 Dict.fromList 96 [ ( "link" 97 , "<https://example.com/previous?from=3&limit=2>; rel=\"previous\"" 98 ++ ", <https://example.com/next?to=1&limit=4>; rel=\"next\"" 99 ) 100 ] 101 102 103 withMalformedLink : Dict String String 104 withMalformedLink = 105 Dict.fromList [ ( "Link", "banana" ) ]