Helpers for testing charts with Phoenix.LiveViewTest: they read what a
chart shows, as the server made it for the browser.
import Fude.Test
test "shows the revenue of each region", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/sales")
assert kind(view, "revenue") == "bar"
assert series(view, "revenue") == ["Online", "Retail"]
assert [%{"Region" => "North", "Revenue" => 120, "Channel" => "Online"} | _] = data(view, "revenue")
endEach helper takes the view (or a render of it, a string) and the id of
the chart. They need lazy_html, which the tests of LiveView 1.1 use.
Summary
Types
A LiveView under test (a Phoenix.LiveViewTest.View), or a render of one.
Functions
What the server sent the browser for the chart: its kind, scales and layers.
What a screen reader says of the chart.
Why the chart does not draw (a field that is not in the data...), or nil when it draws.
The chart's kind: "bar", "line"...
The names of the chart's series (its colors), in order: [] for a chart of one.
The chart's title, or nil.
The single number of a Fude.number/2, Fude.trend/2 or Fude.progress/2.
Types
A LiveView under test (a Phoenix.LiveViewTest.View), or a render of one.
Functions
What the server sent the browser for the chart: its kind, scales and layers.
The data that the chart draws, as its table has it: a map for each mark,
by the titles of the columns ("Region", "Revenue"), with a category
by its name and a time as a Date or a DateTime.
What a screen reader says of the chart.
Why the chart does not draw (a field that is not in the data...), or nil when it draws.
The chart's kind: "bar", "line"...
The names of the chart's series (its colors), in order: [] for a chart of one.
The chart's title, or nil.
The single number of a Fude.number/2, Fude.trend/2 or Fude.progress/2.