Skip to content

Commit

Permalink
Add visible: any option to query (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
michallepicki authored and keathley committed Feb 5, 2019
1 parent b5c4fdf commit 4eb1561
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
11 changes: 8 additions & 3 deletions lib/wallaby/browser.ex
Expand Up @@ -857,9 +857,14 @@ defmodule Wallaby.Browser do
end

defp validate_visibility(query, elements) do
visible = Query.visible?(query)

{:ok, Enum.filter(elements, &(Element.visible?(&1) == visible))}
case Query.visible?(query) do
:any ->
{:ok, elements}
true ->
{:ok, Enum.filter(elements, &(Element.visible?(&1)))}
false ->
{:ok, Enum.reject(elements, &(Element.visible?(&1)))}
end
end

defp validate_selected(query, elements) do
Expand Down
4 changes: 2 additions & 2 deletions lib/wallaby/query.ex
Expand Up @@ -106,7 +106,7 @@ defmodule Wallaby.Query do
@type conditions :: [
count: non_neg_integer,
text: String.t,
visible: boolean(),
visible: boolean() | :any,
selected: boolean() | :any,
minimum: non_neg_integer,
at: pos_integer
Expand Down Expand Up @@ -395,7 +395,7 @@ defmodule Wallaby.Query do
cond do
query.conditions[:minimum] > query.conditions[:maximum] ->
{:error, :min_max}
!Query.visible?(query) && Query.inner_text(query) ->
(Query.visible?(query) != true) && Query.inner_text(query) ->
{:error, :cannot_set_text_with_invisible_elements}
true ->
{:ok, query}
Expand Down
8 changes: 4 additions & 4 deletions lib/wallaby/query/error_message.ex
Expand Up @@ -189,10 +189,10 @@ defmodule Wallaby.Query.ErrorMessage do
@spec visibility(Query.t) :: String.t

def visibility(query) do
if Query.visible?(query) do
"visible"
else
"invisible"
case Query.visible?(query) do
true -> "visible"
false -> "invisible"
:any -> "visible or invisible"
end
end

Expand Down

0 comments on commit 4eb1561

Please sign in to comment.