Narabe.Test (Narabe v0.1.0)

Copy Markdown View Source

Helpers for Phoenix.LiveViewTest, to move, open, rename and pick in tests with no browser.

import Narabe.Test

test "moves a card to Done", %{conn: conn} do
  {:ok, view, _html} = live(conn, ~p"/boards/1")

  move(view, "board", card.id, parent: done.id, index: 0)
  assert_reply(view, %{ok: true})
  assert {"Done", ["Write the docs", "Ship"]} in columns(view, "board")
end

move/4 sends the list's on_move event with the move as the browser sends it (Narabe.Move.to_params/1), to the LiveView or the component of the list's phx-target; the reply is the LiveView's (assert_reply/2). The page shows what the server renders next: unlike a browser, the test does not move anything first.

Summary

Functions

A board's columns, in order: {label, card labels}.

Opens a tree item whose children are not loaded: sends on_expand.

The labels of a list's items (a board's cards, a tree's loaded items), in order.

Moves items (an id or a list of ids) of the list, tree or board with the id list_id, and returns the rendered LiveView.

A tree's loaded items, in order: {label, level}, the top level being 1.

Picks an item of a tree picker in a form, as a click does: the form's phx-change with the item's id. The form must have an id.

Renames a tree item: sends on_rename.

Selects items: sends on_select.

Functions

columns(view, board_id)

@spec columns(struct(), String.t()) :: [{String.t(), [String.t()]}]

A board's columns, in order: {label, card labels}.

expand(view, list_id, id)

@spec expand(struct(), String.t(), term()) :: String.t()

Opens a tree item whose children are not loaded: sends on_expand.

items(view, list_id)

@spec items(struct(), String.t()) :: [String.t()]

The labels of a list's items (a board's cards, a tree's loaded items), in order.

move(view, list_id, ids, opts \\ [])

@spec move(struct(), String.t(), term() | [term()], keyword()) :: String.t()

Moves items (an id or a list of ids) of the list, tree or board with the id list_id, and returns the rendered LiveView.

Options: :after, :before (a neighbour's id), :parent (a tree item's or a board column's id), :index (its place among its new siblings), and columns: true for a board's columns.

outline(view, list_id)

@spec outline(struct(), String.t()) :: [{String.t(), pos_integer()}]

A tree's loaded items, in order: {label, level}, the top level being 1.

pick(view, picker_id, id)

@spec pick(struct(), String.t(), term()) :: String.t()

Picks an item of a tree picker in a form, as a click does: the form's phx-change with the item's id. The form must have an id.

rename(view, list_id, id, name)

@spec rename(struct(), String.t(), term(), String.t()) :: String.t()

Renames a tree item: sends on_rename.

select(view, list_id, ids)

@spec select(struct(), String.t(), [term()]) :: String.t()

Selects items: sends on_select.