-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add navbar core component * Add navbar to existing v2 index pages * Add "switch to arrow v2" link to v1 homepage * Scaffold /disruptionsv2 page * "Cancel" link in disruption form now navigates to /disruptionsv2 * Test navbar component * Use Controller.current_path instead of manually entering current path * Guard against using navbar on a page without assigning a label for it * Use sentence case in link text * Use `for` instead of `:for` b/c it adds whitespace between generated elements 🥴 * Remove margin classes on links * Run the new tests synchronously, in case that caused the issues for unrelated ones * Fix casing of expected string in test * Fix a mistake in test case "arrange" step * Make "link" to current page in navbar unclickable to avoid accidental page reloads * Change styling of unclickable navbar links * Make template conditional logic a bit easier to follow? Hopefully?
- Loading branch information
1 parent
7a118f0
commit 516ccef
Showing
16 changed files
with
219 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.navbar-current-page { | ||
pointer-events: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule ArrowWeb.DisruptionV2Controller do | ||
use ArrowWeb, :controller | ||
|
||
alias ArrowWeb.Plug.Authorize | ||
alias Plug.Conn | ||
|
||
plug(Authorize, :view_disruption when action == :index) | ||
|
||
@spec index(Conn.t(), Conn.params()) :: Conn.t() | ||
def index(conn, _params) do | ||
render(conn, "index.html", user: conn.assigns.current_user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule ArrowWeb.DisruptionV2View do | ||
use ArrowWeb, :html | ||
|
||
alias Arrow.Permissions | ||
alias Phoenix.Controller | ||
|
||
embed_templates "disruption_v2_html/*" | ||
end |
15 changes: 15 additions & 0 deletions
15
lib/arrow_web/controllers/disruption_v2_html/index.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="row my-3"> | ||
<.navbar | ||
page={Controller.current_path(@conn)} | ||
create_disruption_permission?={Permissions.authorize?(:create_disruption, @user)} | ||
/> | ||
<%= form_tag(Controller.current_path(@conn), method: "get", class: "col-3") do %> | ||
<div class="input-group"> | ||
<input type="text" name="search" class="form-control" placeholder="search" /> | ||
|
||
<div class="input-group-append"> | ||
<button type="submit" class="btn btn-outline-secondary" title="search">🔎</button> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
defmodule ArrowWeb.ShuttleView do | ||
use ArrowWeb, :html | ||
|
||
alias Phoenix.Controller | ||
|
||
embed_templates "shuttle_html/*" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<div class="row my-3"> | ||
<.navbar page={Controller.current_path(@conn)} /> | ||
</div> | ||
|
||
<.header> | ||
shuttles | ||
<:actions> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
defmodule ArrowWeb.CoreComponentsTest do | ||
use ArrowWeb.ConnCase | ||
|
||
import ArrowWeb.CoreComponents | ||
import Phoenix.Component | ||
import Phoenix.LiveViewTest | ||
|
||
describe "navbar" do | ||
test "link corresponding to current page has .btn-secondary and no href" do | ||
assigns = %{page: "/shuttles"} | ||
|
||
current_page_links = | ||
~H""" | ||
<.navbar page={@page} /> | ||
""" | ||
|> rendered_to_string() | ||
|> Floki.find("a.btn-secondary") | ||
|
||
assert [current_page_link] = current_page_links | ||
|
||
assert Floki.text(current_page_link) =~ "Shuttle definitions" | ||
assert Floki.attribute(current_page_link, "href") == [] | ||
end | ||
|
||
test "other v2 page links have .btn-outline-secondary and href" do | ||
assigns = %{page: "/shuttles"} | ||
|
||
secondary_links = | ||
~H""" | ||
<.navbar page={@page} /> | ||
""" | ||
|> rendered_to_string() | ||
|> Floki.find("a.btn-outline-secondary") | ||
|
||
assert length(secondary_links) == 3 | ||
assert length(Floki.attribute(secondary_links, "href")) == 3 | ||
end | ||
|
||
test "first link is to /disruptionsv2 when not on Disruptions page" do | ||
assigns = %{page: "/shapes"} | ||
|
||
hrefs = | ||
~H""" | ||
<.navbar page={@page} /> | ||
""" | ||
|> rendered_to_string() | ||
|> Floki.attribute("a", "href") | ||
|
||
assert ["/disruptionsv2" | _] = hrefs | ||
end | ||
|
||
test "first link is to /disruptionsv2/new when on Disruptions page, with create permission" do | ||
assigns = %{page: "/disruptionsv2", create_disruption_permission?: true} | ||
|
||
hrefs = | ||
~H""" | ||
<.navbar page={@page} create_disruption_permission?={@create_disruption_permission?} /> | ||
""" | ||
|> rendered_to_string() | ||
|> Floki.attribute("a", "href") | ||
|
||
assert ["/disruptionsv2/new" | _] = hrefs | ||
end | ||
|
||
test "first link is to /disruptionsv2 when on Disruptions page, without create permission" do | ||
assigns = %{page: "/disruptionsv2"} | ||
|
||
hrefs = | ||
~H""" | ||
<.navbar page={@page} /> | ||
""" | ||
|> rendered_to_string() | ||
|> Floki.attribute("a", "href") | ||
|
||
assert ["/disruptionsv2" | _] = hrefs | ||
end | ||
|
||
test "renders link to v1 homepage with .btn-warning class" do | ||
assigns = %{page: "/stops"} | ||
|
||
warning_buttons = | ||
~H""" | ||
<.navbar page={@page} /> | ||
""" | ||
|> rendered_to_string() | ||
|> Floki.find(".btn-warning") | ||
|
||
assert [warning_button] = warning_buttons | ||
|
||
assert Floki.text(warning_button) == "Switch to Arrow v1" | ||
end | ||
|
||
test "raises an exception if @page is unrecognized" do | ||
assigns = %{page: "/unknown_page"} | ||
|
||
expect_msg = "navbar component used on an unrecognized page: /unknown_page" | ||
|
||
ExUnit.Assertions.assert_raise(RuntimeError, expect_msg, fn -> | ||
~H""" | ||
<.navbar page={@page} /> | ||
""" | ||
|> rendered_to_string() | ||
end) | ||
end | ||
end | ||
end |