Skip to content

Commit

Permalink
Remove choose/n in favor of click/2 + Query.radio_button
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Apr 14, 2017
1 parent b423b66 commit 6ad391a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 113 deletions.
35 changes: 0 additions & 35 deletions lib/wallaby/browser.ex
Expand Up @@ -172,41 +172,6 @@ defmodule Wallaby.Browser do
|> find(query, &(Element.fill_in(&1, with: value)))
end

@doc """
Chooses a radio button based on id, label text, or name.
"""
@spec choose(Element.t) :: Element.t
@spec choose(parent, Query.t) :: parent
@spec choose(parent, locator, opts) :: parent

def choose(parent, locator, opts) when is_binary(locator) do
IO.warn """
choose/3 has been deprecated. Please use: click(parent, Query.radio_button("#{locator}", #{inspect(opts)}))
"""

parent
|> find(Query.radio_button(locator, opts), &Element.click/1)
end
def choose(parent, locator) when is_binary(locator) do
IO.warn """
choose/2 has been deprecated. Please use: click(parent, Query.radio_button("#{locator}"))
"""

parent
|> find(Query.radio_button(locator, []), &Element.click/1)
end
def choose(parent, query) do
IO.warn "choose/2 has been deprecated. Please use click/2"

parent
|> find(query, &Element.click/1)
end
def choose(%Element{}=element) do
IO.warn "choose/1 has been deprecated. Please use Element.click/1"

Element.click(element)
end

@doc """
Checks a checkbox based on id, label text, or name.
"""
Expand Down
78 changes: 0 additions & 78 deletions test/wallaby/browser/choose_test.exs

This file was deleted.

50 changes: 50 additions & 0 deletions test/wallaby/browser/click_test.exs
Expand Up @@ -17,5 +17,55 @@ defmodule Wallaby.Browser.ClickTest do
assert page
|> click(Query.button("Invisible Button", visible: false))
end

test "can be chained/returns parent", %{page: page} do
page
|> click(Query.css("#option1"))
|> click(Query.css("#option2"))

assert selected?(page, Query.css("#option2"))
end
end

describe "click/2 with radio buttons (choose replacement)" do
test "choosing a radio button", %{page: page} do
refute selected?(page, Query.css("#option2"))

page
|> click(Query.radio_button("option2"))

assert selected?(page, Query.css("#option2"))
end

test "choosing a radio button unchecks other buttons in the group", %{page: page} do
page
|> click(Query.radio_button("Option 1"))
|> selected?(Query.css("#option1"))
|> assert

page
|> click(Query.radio_button("option2"))

refute selected?(page, Query.css("#option1"))
assert selected?(page, Query.css("#option2"))
end

test "throw an error if a label exists but does not have a for attribute", %{page: page} do
bad_form =
page
|> find(Query.css(".bad-form"))

assert_raise Wallaby.QueryError, fn ->
click(bad_form, Query.radio_button("Radio with bad label"))
end
end

test "waits until the radio button appears", %{page: page} do
assert click(page, Query.radio_button("Hidden Radio Button"))
end

test "escape quotes", %{page: page} do
assert click(page, Query.radio_button("I'm a radio button"))
end
end
end

0 comments on commit 6ad391a

Please sign in to comment.