-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We add a `within` helper to help us scope down filling out forms with the new `fill_in`, `select`, etc. form helpers. Since they do not take a CSS selector as their second argument (like most other helpers do), having a `within` helper seems more necessary to scope forms. Though it's possible the `within` helper works with other helpers (since we're really changing the `render_html` to only render the scoped HTML), we do not officially support it for all helpers.
- Loading branch information
Showing
6 changed files
with
109 additions
and
7 deletions.
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
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 |
---|---|---|
|
@@ -208,6 +208,38 @@ defmodule PhoenixTest.LiveTest do | |
end | ||
end | ||
|
||
describe "within/3" do | ||
test "scopes assertions within selector", %{conn: conn} do | ||
conn | ||
|> visit("/live/index") | ||
|> assert_has("button", text: "Reset") | ||
|> within("#email-form", fn session -> | ||
refute_has(session, "button", text: "Reset") | ||
end) | ||
end | ||
|
||
test "scopes further form actions within a selector", %{conn: conn} do | ||
conn | ||
|> visit("/live/index") | ||
|> within("#email-form", fn session -> | ||
session | ||
|> fill_in("Email", with: "[email protected]") | ||
end) | ||
|> assert_has(input(label: "Email", value: "[email protected]")) | ||
end | ||
|
||
test "raises when data is not in scoped HTML", %{conn: conn} do | ||
assert_raise ArgumentError, ~r/Could not find element with label "User Name"/, fn -> | ||
conn | ||
|> visit("/live/index") | ||
|> within("#email-form", fn session -> | ||
session | ||
|> fill_in("User Name", with: "Aragorn") | ||
end) | ||
end | ||
end | ||
end | ||
|
||
describe "fill_in/3" do | ||
test "fills in a single text field based on the label", %{conn: conn} do | ||
conn | ||
|
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 |
---|---|---|
|
@@ -284,6 +284,39 @@ defmodule PhoenixTest.StaticTest do | |
end | ||
end | ||
|
||
describe "within/3" do | ||
test "scopes assertions within selector", %{conn: conn} do | ||
conn | ||
|> visit("/page/index") | ||
|> assert_has("button", text: "Get record") | ||
|> within("#email-form", fn session -> | ||
refute_has(session, "button", text: "Get record") | ||
end) | ||
end | ||
|
||
test "scopes further form actions within a selector", %{conn: conn} do | ||
conn | ||
|> visit("/page/index") | ||
|> within("#email-form", fn session -> | ||
session | ||
|> fill_in("Email", with: "[email protected]") | ||
|> click_button("Save Email") | ||
end) | ||
|> assert_has("#form-data", text: "email: [email protected]") | ||
end | ||
|
||
test "raises when data is not in scoped HTML", %{conn: conn} do | ||
assert_raise ArgumentError, ~r/Could not find element with label "User Name"/, fn -> | ||
conn | ||
|> visit("/page/index") | ||
|> within("#email-form", fn session -> | ||
session | ||
|> fill_in("User Name", with: "Aragorn") | ||
end) | ||
end | ||
end | ||
end | ||
|
||
describe "fill_in/3" do | ||
test "fills in a single text field based on the label", %{conn: conn} do | ||
conn | ||
|