@@ -248,16 +248,6 @@ defmodule PhoenixTest.Playwright do
248248 conn
249249 end
250250
251- def assert_has_value(conn, label, value, opts \\ []) do
252- opts = Keyword.validate!(opts, exact: true)
253-
254- assert_found(conn,
255- selector: Selector.label(label, opts),
256- expression: "to.have.value",
257- expectedText: [%{string: value}]
258- )
259- end
260-
261251 def assert_has_selected(conn, label, value, opts \\ []) do
262252 opts = Keyword.validate!(opts, exact: true)
263253
@@ -583,7 +573,7 @@ defmodule PhoenixTest.Playwright do
583573 end
584574
585575 def assert_has ( conn , selector , opts ) do
586- if ! found? ( conn , selector , opts ) do
576+ if not found? ( conn , selector , opts ) do
587577 flunk ( "Could not find element #{ selector } #{ inspect ( opts ) } " )
588578 end
589579
@@ -633,34 +623,55 @@ defmodule PhoenixTest.Playwright do
633623 conn
634624 |> maybe_within ( )
635625 |> Selector . concat ( Selector . css ( selector ) )
626+ |> Selector . and ( Selector . label ( opts [ :label ] , exact: true ) )
636627 |> Selector . concat ( "visible=true" )
637628 |> Selector . concat ( Selector . text ( opts [ :text ] , opts ) )
638629
639- if opts [ :count ] do
640- if opts [ :at ] ,
641- do: raise ( ArgumentError , message: "Options `count` and `at` can not be used together." )
642-
643- params =
644- % {
645- expression: "to.have.count" ,
646- expected_number: opts [ :count ] ,
647- selector: Selector . build ( selector ) ,
648- timeout: timeout ( opts )
649- }
650-
651- { :ok , found? } = Frame . expect ( conn . frame_id , params )
652- found?
653- else
654- params =
655- % {
656- selector: selector |> Selector . concat ( Selector . at ( opts [ :at ] ) ) |> Selector . build ( ) ,
657- timeout: timeout ( opts )
658- }
659-
660- case Frame . wait_for_selector ( conn . frame_id , params ) do
661- { :ok , _ } -> true
662- _ -> false
663- end
630+ cond do
631+ opts [ :value ] ->
632+ if opts [ :count ] ,
633+ do: raise ( ArgumentError , message: "Options `value` and `count` can not be used together." )
634+
635+ if opts [ :text ] ,
636+ do: raise ( ArgumentError , message: "Options `value` and `text` can not be used together." )
637+
638+ params =
639+ % {
640+ expression: "to.have.value" ,
641+ expected_text: [ % { string: opts [ :value ] } ] ,
642+ selector: selector |> Selector . concat ( Selector . at ( opts [ :at ] ) ) |> Selector . build ( ) ,
643+ timeout: timeout ( opts )
644+ }
645+
646+ { :ok , found? } = Frame . expect ( conn . frame_id , params )
647+ found?
648+
649+ opts [ :count ] ->
650+ if opts [ :at ] ,
651+ do: raise ( ArgumentError , message: "Options `count` and `at` can not be used together." )
652+
653+ params =
654+ % {
655+ expression: "to.have.count" ,
656+ expected_number: opts [ :count ] ,
657+ selector: Selector . build ( selector ) ,
658+ timeout: timeout ( opts )
659+ }
660+
661+ { :ok , found? } = Frame . expect ( conn . frame_id , params )
662+ found?
663+
664+ true ->
665+ params =
666+ % {
667+ selector: selector |> Selector . concat ( Selector . at ( opts [ :at ] ) ) |> Selector . build ( ) ,
668+ timeout: timeout ( opts )
669+ }
670+
671+ case Frame . wait_for_selector ( conn . frame_id , params ) do
672+ { :ok , _ } -> true
673+ _ -> false
674+ end
664675 end
665676 end
666677
0 commit comments