diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 1d901feb73..759b7cc5ae 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -134,4 +134,20 @@ filterStreams stream streams = [] else - List.filter (String.contains stream) streams + List.filterMap (caseInsensitiveContains stream) streams + + +caseInsensitiveContains : Stream -> Stream -> Maybe Stream +caseInsensitiveContains needle haystack = + let + needleLower = + String.toLower needle + + haystackLower = + String.toLower haystack + in + if String.contains needleLower haystackLower then + Just haystack + + else + Nothing diff --git a/ruby_event_store-browser/elm/tests/SearchTest.elm b/ruby_event_store-browser/elm/tests/SearchTest.elm index 9d15d97d3a..19b53ddd74 100644 --- a/ruby_event_store-browser/elm/tests/SearchTest.elm +++ b/ruby_event_store-browser/elm/tests/SearchTest.elm @@ -1,7 +1,7 @@ module SearchTest exposing (suite) import Expect -import Search exposing (Stream, filterStreams) +import Search exposing (filterStreams) import Test exposing (..) @@ -29,5 +29,10 @@ suite = Expect.equal [ "DummyStream$78" ] (filterStreams "78" [ "DummyStream$78", "DummyStream$79" ]) + , test "filterStreams is case insensitive" <| + \_ -> + Expect.equal + [ "DummyStream$78", "DummyStream$79" ] + (filterStreams "stream" [ "DummyStream$78", "DummyStream$79" ]) ] ]