Macaw.Frame.LayerKit (macaw_frame v0.1.0)

Copy Markdown View Source

The layer kit (spec/04 §3): the checks every layer kind passes, as every component passes Macaw.Component.Conformance, and shaped the same way.

It ships in lib/ so a package author runs it in their own CI. check(check, kind, opts) answers one check's findings, [] for a kind that passes; check(kind, opts) runs every check of checks/0; format/1 words a finding as one line; use Macaw.Frame.LayerKit, kind: … writes one test per check. A misuse of the kit (an unknown check, a module that is not a kind, bad fixtures) is a finding {:kit, {path, fault}}, never a raise. The kit renders through the scene and the SVG renderer (spec/10) and reads the SVG's tags and attributes itself (lazy_html is not a dependency). The canvas targets join :golden when they are registered (proposal #12); until then it compares the SVG alone.

Fixtures

A kind ships a fixture set (fixtures:, else the kind's fixtures/0 when it exports one): one fixture per distinct shape of its declarations, and at least one per model it draws in. A fixture is %{name, layer, model, rows, schema, size} (and optionally theme, served): the layer node; the frame node its model realizes from (%{kind: "cartesian", scales: …}); the rows, a Macaw.Data.Table or row maps (the kit also builds the same rows as a chunked table of several chunks); the slot's Macaw.Data.Schema or nil; the size {width, height}. Both built-in themes run (Macaw.Layers.Theme.default/0 and dark/0) unless the fixture names one.

The checks, in order

:declarations, :validation, :socketless, :budget, :summary, :theme_roles, :no_inline_style, :columns, :no_decode, :series, :never_raises, :golden: each as spec/04 §3's table says. Findings are {check, {where, what}}, where naming the fixture, the model, the renderer and the theme: {:columns, {{"fixture 2", :polar, :svg, :default}, {:row_read, :get, 412}}}.

Options

  • fixtures: the fixture set;
  • goldens: the directory the :golden check reads, test/support/golden/layers by default, each fixture's SVG at <kind>/<fixture>-<theme>.svg; write: true records them instead (a deliberate regeneration);
  • registry: the frame document's registry the :validation check validates through (Macaw.Frame.Layers.document/1 of [] with the kind added).

Summary

Types

A finding of the kit (§3).

Where a finding is: the fixture, the model, the renderer and the theme.

Functions

Every check's findings for a kind (§3): [] for a kind that passes every one.

One check's findings for a kind (§3); an unknown check is a kit finding.

The kit's checks, in order.

A finding as one line.

Types

finding()

@type finding() :: {atom(), {where(), term()}}

A finding of the kit (§3).

where()

@type where() :: {String.t(), atom(), :svg, atom()} | list()

Where a finding is: the fixture, the model, the renderer and the theme.

Functions

check(kind, opts \\ [])

@spec check(term(), keyword()) :: [finding()]

Every check's findings for a kind (§3): [] for a kind that passes every one.

check(check, kind, opts)

@spec check(term(), term(), keyword()) :: [finding()]

One check's findings for a kind (§3); an unknown check is a kit finding.

checks()

@spec checks() :: [atom(), ...]

The kit's checks, in order.

format(other)

@spec format(term()) :: String.t()

A finding as one line.

iex> Macaw.Frame.LayerKit.format({:columns, {{"fixture 2", :polar, :svg, :default}, {:row_read, :get, 412}}})
"columns: fixture 2 (polar, svg, default): {:row_read, :get, 412}"
iex> Macaw.Frame.LayerKit.format({:kit, {[:check], {:unknown, :check, :nope}}})
"kit: check: {:unknown, :check, :nope}"