# `Fude.Test`
[🔗](https://github.com/hattoriai/fude/blob/v0.1.0/lib/fude/test.ex#L1)

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")
    end

Each 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.

# `view`

```elixir
@type view() :: struct() | String.t()
```

A LiveView under test (a `Phoenix.LiveViewTest.View`), or a render of one.

# `chart`

```elixir
@spec chart(view(), String.t()) :: map()
```

What the server sent the browser for the chart: its kind, scales and layers.

# `data`

```elixir
@spec data(view(), String.t()) :: [map()]
```

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`.

# `description`

```elixir
@spec description(view(), String.t()) :: String.t() | nil
```

What a screen reader says of the chart.

# `error`

```elixir
@spec error(view(), String.t()) :: String.t() | nil
```

Why the chart does not draw (a field that is not in the data...), or `nil` when it draws.

# `kind`

```elixir
@spec kind(view(), String.t()) :: String.t()
```

The chart's kind: `"bar"`, `"line"`...

# `series`

```elixir
@spec series(view(), String.t()) :: [String.t()]
```

The names of the chart's series (its colors), in order: `[]` for a chart of one.

# `title`

```elixir
@spec title(view(), String.t()) :: String.t() | nil
```

The chart's title, or `nil`.

# `value`

```elixir
@spec value(view(), String.t()) :: number() | String.t() | nil
```

The single number of a `Fude.number/2`, `Fude.trend/2` or `Fude.progress/2`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
