analytics/test/support/html.ex
hq1 b9ec38038c
Add small build option (#3536)
* Update applications

* Clone community config

* Move modules to experimental dir

* Update runtime config

* Apply first set of compile-time conditionals

* Move funnel schemas to experimental

* Make funnel schema-less build compile

* Use experimental/lib for elixir code

* Move JS funnels to experimental

* Clean up conditional rendering

* Tidy up the pipeline

* Make two builds pass tests without warnings

* Reuse existing dotenvs

* Do a bunch of renames

* Clean up naming

* Run secondary CI

* Update router

* Remove RewriteFunnelDupes migration

Tests were disabled already and it was a one-off shot

* Fixup quota mixins

* Add moduledoc

* Change MIX_ENV for seconary test run

* Skip crm on small

* !fixup

* Exclude flags pipeline

* Update lib/plausible_web/controllers/stats_controller.ex

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2023-11-20 12:52:20 +01:00

66 lines
1.2 KiB
Elixir

defmodule Plausible.Test.Support.HTML do
Code.ensure_compiled!(Floki)
@moduledoc """
Floki wrappers to help make assertions about HTML/DOM structures
"""
def element_exists?(html, selector) do
html
|> find(selector)
|> Enum.empty?()
|> Kernel.not()
end
def find(html, value) do
html
|> Floki.parse_document!()
|> Floki.find(value)
end
def submit_button(html, form) do
find(html, "#{form} button[type=\"submit\"]")
end
def form_exists?(html, action_path) do
element_exists?(html, "form[action=\"" <> action_path <> "\"]")
end
def text_of_element(html, element) do
html
|> find(element)
|> Floki.text()
|> String.trim()
|> String.replace(~r/\s+/, " ")
end
def text(element) do
element
|> Floki.text()
|> String.trim()
end
def class_of_element(html, element) do
html
|> find(element)
|> text_of_attr("class")
end
def text_of_attr(html, element, attr) do
html
|> find(element)
|> text_of_attr(attr)
end
def text_of_attr(element, attr) do
element
|> Floki.attribute(attr)
|> Floki.text()
|> String.trim()
end
def name_of(element) do
List.first(Floki.attribute(element, "name"))
end
end