Skip to content

Commit e3ec684

Browse files
committed
Add tests to document support for aria-label in form actions
1 parent 178404f commit e3ec684

4 files changed

Lines changed: 112 additions & 2 deletions

File tree

test/phoenix_test/live_test.exs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@ defmodule PhoenixTest.LiveTest do
395395
|> assert_has("input", label: "Email", value: "someone@example.com")
396396
end
397397

398+
test "fills in a field by aria label", %{conn: conn} do
399+
conn
400+
|> visit("/live/index")
401+
|> fill_in("Secret Name", with: "Aragorn")
402+
|> click_button("Save Full Form")
403+
|> assert_has("#form-data", text: "secret_name: Aragorn")
404+
end
405+
398406
test "can fill input with `nil` to override existing value", %{conn: conn} do
399407
conn
400408
|> visit("/live/index")
@@ -533,6 +541,14 @@ defmodule PhoenixTest.LiveTest do
533541
|> assert_has("#full-form option[value='elf']")
534542
end
535543

544+
test "selects an option by aria label", %{conn: conn} do
545+
conn
546+
|> visit("/live/index")
547+
|> select("Aria Choice", option: "Elf")
548+
|> click_button("Save Full Form")
549+
|> assert_has("#form-data", text: "aria_choice: elf")
550+
end
551+
536552
test "allows selecting option if a similar option exists", %{conn: conn} do
537553
conn
538554
|> visit("/live/index")
@@ -646,6 +662,14 @@ defmodule PhoenixTest.LiveTest do
646662
|> assert_has("#form-data", text: "admin: on")
647663
end
648664

665+
test "checks a checkbox by aria label", %{conn: conn} do
666+
conn
667+
|> visit("/live/index")
668+
|> check("Aria Enabled")
669+
|> click_button("Save Full Form")
670+
|> assert_has("#form-data", text: "aria_enabled: on")
671+
end
672+
649673
test "can check an unchecked checkbox", %{conn: conn} do
650674
conn
651675
|> visit("/live/index")
@@ -925,6 +949,14 @@ defmodule PhoenixTest.LiveTest do
925949
|> assert_has("#form-data", text: "contact: email")
926950
end
927951

952+
test "chooses a radio button by aria label", %{conn: conn} do
953+
conn
954+
|> visit("/live/index")
955+
|> choose("Aria Email")
956+
|> click_button("Save Full Form")
957+
|> assert_has("#form-data", text: "aria_contact: email")
958+
end
959+
928960
test "uses the default 'checked' if present", %{conn: conn} do
929961
conn
930962
|> visit("/live/index")
@@ -1007,6 +1039,17 @@ defmodule PhoenixTest.LiveTest do
10071039
|> assert_has("#form-data", text: "avatar: elixir.jpg")
10081040
end
10091041

1042+
test "uploads an image by aria label", %{conn: conn} do
1043+
conn
1044+
|> visit("/live/index")
1045+
|> within("#full-form", fn session ->
1046+
session
1047+
|> upload("Aria Avatar", "test/files/elixir.jpg")
1048+
|> click_button("Save Full Form")
1049+
end)
1050+
|> assert_has("#form-data", text: "avatar: elixir.jpg")
1051+
end
1052+
10101053
test "can target a label with exact: false", %{conn: conn} do
10111054
conn
10121055
|> visit("/live/index")

test/phoenix_test/static_test.exs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ defmodule PhoenixTest.StaticTest do
352352
|> assert_has("#form-data", text: "email: someone@example.com")
353353
end
354354

355+
test "fills in a field by aria label", %{conn: conn} do
356+
conn
357+
|> visit("/page/index")
358+
|> fill_in("Secret Name", with: "Aragorn")
359+
|> click_button("Save Full Form")
360+
|> assert_has("#form-data", text: "secret_name: Aragorn")
361+
end
362+
355363
test "can fill input with `nil` to override existing value", %{conn: conn} do
356364
conn
357365
|> visit("/page/index")
@@ -458,6 +466,14 @@ defmodule PhoenixTest.StaticTest do
458466
|> assert_has("#form-data", text: "race: human")
459467
end
460468

469+
test "selects an option by aria label", %{conn: conn} do
470+
conn
471+
|> visit("/page/index")
472+
|> select("Aria Choice", option: "Elf")
473+
|> click_button("Save Full Form")
474+
|> assert_has("#form-data", text: "aria_choice: elf")
475+
end
476+
461477
test "allows selecting option if a similar option exists", %{conn: conn} do
462478
conn
463479
|> visit("/page/index")
@@ -528,6 +544,14 @@ defmodule PhoenixTest.StaticTest do
528544
|> assert_has("#form-data", text: "admin_boolean: true")
529545
end
530546

547+
test "checks a checkbox by aria label", %{conn: conn} do
548+
conn
549+
|> visit("/page/index")
550+
|> check("Aria Enabled")
551+
|> click_button("Save Full Form")
552+
|> assert_has("#form-data", text: "aria_enabled: on")
553+
end
554+
531555
test "sets checkbox value as 'on' by default", %{conn: conn} do
532556
conn
533557
|> visit("/page/index")
@@ -691,6 +715,14 @@ defmodule PhoenixTest.StaticTest do
691715
|> assert_has("#form-data", text: "contact: email")
692716
end
693717

718+
test "chooses a radio button by aria label", %{conn: conn} do
719+
conn
720+
|> visit("/page/index")
721+
|> choose("Aria Email")
722+
|> click_button("Save Full Form")
723+
|> assert_has("#form-data", text: "aria_contact: email")
724+
end
725+
694726
test "uses the default 'checked' if present", %{conn: conn} do
695727
conn
696728
|> visit("/page/index")
@@ -732,6 +764,17 @@ defmodule PhoenixTest.StaticTest do
732764
|> assert_has("#form-data", text: "avatar: elixir.jpg")
733765
end
734766

767+
test "uploads an image by aria label", %{conn: conn} do
768+
conn
769+
|> visit("/page/index")
770+
|> within("#file-upload-form", fn session ->
771+
session
772+
|> upload("Aria Avatar", "test/files/elixir.jpg")
773+
|> click_button("Save File upload Form")
774+
end)
775+
|> assert_has("#form-data", text: "avatar: elixir.jpg")
776+
end
777+
735778
test "uploads image list", %{conn: conn} do
736779
conn
737780
|> visit("/page/index")

test/support/web_app/index_live.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ defmodule PhoenixTest.WebApp.IndexLive do
194194
<label for="level">Level (number)</label>
195195
<input id="level" type="number" name="level" value="7" />
196196
197+
<input name="secret_name" aria-label="Secret Name" />
198+
199+
<input type="hidden" name="aria_enabled" value="off" />
200+
<input type="checkbox" name="aria_enabled" value="on" aria-label="Aria Enabled" />
201+
202+
<select name="aria_choice" aria-label="Aria Choice">
203+
<option value="human">Human</option>
204+
<option value="elf">Elf</option>
205+
</select>
206+
207+
<input type="radio" name="aria_contact" value="email" aria-label="Aria Email" />
208+
197209
<label for="race">Race</label>
198210
<select id="race" name="race">
199211
<option value="human">Human</option>
@@ -253,7 +265,7 @@ defmodule PhoenixTest.WebApp.IndexLive do
253265
</label>
254266
255267
<label for={@uploads.avatar.ref}>Avatar</label>
256-
<.live_file_input upload={@uploads.avatar} />
268+
<.live_file_input upload={@uploads.avatar} aria-label="Aria Avatar" />
257269
258270
<button type="submit" name="full_form_button" value="save">Save Full Form</button>
259271
</form>

test/support/web_app/page_view.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ defmodule PhoenixTest.WebApp.PageView do
140140
<label for="level">Level (number)</label>
141141
<input id="level" type="number" name="level" value="7" />
142142
143+
<input name="secret_name" aria-label="Secret Name" />
144+
145+
<input type="hidden" name="aria_enabled" value="off" />
146+
<input type="checkbox" name="aria_enabled" value="on" aria-label="Aria Enabled" />
147+
148+
<select name="aria_choice" aria-label="Aria Choice">
149+
<option value="human">Human</option>
150+
<option value="elf">Elf</option>
151+
</select>
152+
153+
<input type="radio" name="aria_contact" value="email" aria-label="Aria Email" />
154+
143155
<label for="race">Race</label>
144156
<select id="race" name="race">
145157
<option value="human">Human</option>
@@ -194,7 +206,7 @@ defmodule PhoenixTest.WebApp.PageView do
194206
enctype="multipart/form-data"
195207
>
196208
<label for="avatar">Avatar</label>
197-
<input id="avatar" name="avatar" type="file" />
209+
<input id="avatar" name="avatar" type="file" aria-label="Aria Avatar" />
198210
199211
<label for="nested_avatar">Nested Avatar</label>
200212
<input id="nested_avatar" name="user[avatar]" type="file" />

0 commit comments

Comments
 (0)