Skip to content

Commit

Permalink
feat: Add "Service every 15 minutes or better" badge for frequent bus…
Browse files Browse the repository at this point in the history
… routes (#2253)
  • Loading branch information
joshlarson authored Dec 10, 2024
1 parent ff81b26 commit acb1cba
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dotcom_web/templates/schedule/_line_header.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<%= route_header_text(@route) %>
</h1>
<%= route_header_description(@route) %>
<%= frequent_bus_badge(@route) %>
<div class="schedule__header-tabs">
<%= route_header_tabs(@conn) %>
</div>
Expand Down
18 changes: 18 additions & 0 deletions lib/dotcom_web/views/schedule_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule DotcomWeb.ScheduleView do

import DotcomWeb.ScheduleView.StopList
import DotcomWeb.ScheduleView.Timetable
import DotcomWeb.ViewHelpers

require Routes.Route

Expand Down Expand Up @@ -411,4 +412,21 @@ defmodule DotcomWeb.ScheduleView do
def station?(stop) do
stop.station?
end

@spec frequent_bus_badge(Route.t()) :: Safe.t() | nil
def frequent_bus_badge(%Route{description: :frequent_bus_route}) do
content_tag :div,
class: "bg-white rounded-full h-8 w-fit flex gap-2 items-center py-1 pl-1 pr-3 mb-6" do
[
svg("icon-frequent-bus.svg"),
content_tag :span, class: "text-sm font-bold" do
"Service every 15 minutes or better"
end
]
end
end

def frequent_bus_badge(_route) do
nil
end
end
3 changes: 3 additions & 0 deletions lib/routes/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ defmodule Routes.Parser do
def parse_gtfs_desc("Ferry"), do: :ferry
def parse_gtfs_desc("Rail Replacement Bus"), do: :rail_replacement_bus
def parse_gtfs_desc("Key Bus"), do: :key_bus_route
def parse_gtfs_desc("Frequent Bus"), do: :frequent_bus_route
def parse_gtfs_desc("Supplemental Bus"), do: :supplemental_bus
def parse_gtfs_desc("Commuter Bus"), do: :commuter_bus
def parse_gtfs_desc("Community Bus"), do: :community_bus
def parse_gtfs_desc("Coverage Bus"), do: :coverage_bus
def parse_gtfs_desc("Regional Rail"), do: :regional_rail
def parse_gtfs_desc(_), do: :unknown

@spec parse_gtfs_fare_class(String.t()) :: Route.gtfs_fare_class()
Expand Down
21 changes: 21 additions & 0 deletions priv/static/icon-svg/icon-frequent-bus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions test/dotcom_web/views/schedule_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,18 @@ defmodule DotcomWeb.ScheduleViewTest do
assert station?(%Stop{id: "11257", station?: false}) == false
end
end

describe "frequent_bus_badge/1" do
test "returns a badge for frequent bus routes" do
refute frequent_bus_badge(%Route{type: 3, description: :frequent_bus_route}) == nil
end

test "does not return a badge for key bus routes" do
assert frequent_bus_badge(%Route{type: 3, description: :key_bus_route}) == nil
end

test "returns nothing otherwise" do
assert frequent_bus_badge(%Route{type: 3, description: :community_bus}) == nil
end
end
end
18 changes: 18 additions & 0 deletions test/routes/repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ defmodule Routes.RepoTest do
refute description == :key_bus_route
end

test "frequent bus routes are tagged" do
route_id = Faker.Internet.slug()
frequent_route_id = Faker.Internet.slug()

expect(MBTA.Api.Mock, :get_json, 2, fn "/routes/" <> id, _ ->
if id == frequent_route_id do
%JsonApi{data: [build(:route_item, %{attributes: %{"description" => "Frequent Bus"}})]}
else
%JsonApi{data: [build(:route_item)]}
end
end)

assert %Route{description: :frequent_bus_route} = get(frequent_route_id)

%Route{description: description} = get(route_id)
refute description == :frequent_bus_route
end

describe "by_stop/1" do
test "can specify type as param" do
stop_id = Faker.Internet.slug()
Expand Down

0 comments on commit acb1cba

Please sign in to comment.