Alternera.Resource.UI.Test (alternera_resource_ui v0.9.0)

Copy Markdown View Source

The test kit for a package's own UI, run with no proxy around.

# test/test_helper.exs
Alternera.Resource.UI.Test.start!()

defmodule Finance.UITest do
  use Alternera.Resource.UI.Test

  resource_ui_contract Finance.Resources

  test "the converter converts", %{tenant: tenant} do
    ctx = ui_ctx(tenant, %{system: true}, resource: Finance.UnitOfMeasure)
    {:ok, view, _html} = live_ui(Finance.Converter, ctx)
    ...
  end
end

use imports Phoenix.LiveViewTest and this module's functions, and sets the endpoint. resource_ui_contract/1 generates a test that every declared UI module is the kind its declaration needs (Alternera.Resource.UI.Check).

live_ui/3 mounts a component in a harness that plays the host (Alternera.Resource.UI.Test.Harness): every request the component makes of the host arrives in the test as {:resource_ui, request}, and notifications are drawn in #harness-notifications. Records go through Alternera.Resource.UI.Test.Host, Ash with the context's tenant and actor.

Summary

Functions

Mounts module in the harness. A surface gets params (option :params) and arg (option :arg); any other component gets the option :assigns beside ctx. Returns live_isolated/3's result.

Generates a test that domain's UI declarations name modules of the right kind.

Runs a declared action as the host's runner would, without the dialog.

Configures and starts the test endpoint; call it once in test_helper.exs.

A context for a test: options :resource (a resource module), :package (default "test"), :can_write? (default true) and :timezone.

Functions

live_ui(module, ctx, opts \\ [])

(macro)

Mounts module in the harness. A surface gets params (option :params) and arg (option :arg); any other component gets the option :assigns beside ctx. Returns live_isolated/3's result.

resource_ui_contract(domain)

(macro)

Generates a test that domain's UI declarations name modules of the right kind.

run_ui_action(resource, action_id, target, input \\ %{}, ctx)

Runs a declared action as the host's runner would, without the dialog.

start!()

@spec start!() :: :ok

Configures and starts the test endpoint; call it once in test_helper.exs.

ui_ctx(tenant, actor, opts \\ [])

A context for a test: options :resource (a resource module), :package (default "test"), :can_write? (default true) and :timezone.