# `MishkaCmsCore.Test.Factory`
[🔗](https://github.com/mishka-group/mishka_cms_core/blob/v0.0.3/lib/mishka_cms_core/test/factory.ex#L5)

Fixtures for this library's suite and an extension's: sites, users, permissions, and the runtime
records (components, layouts, pages, error pages, JS hooks, media) that everything else is built
on.

These are the same wrappers the CMS's factory exposes. They ship in `lib` so an extension's suite
imports them instead of re-stating them, since a dependency cannot reach into another project's
`test/support`. The generators behind them are `MishkaCmsCore.Dev.Generator`.

Records are tenant-scoped, so each wrapper pops `:site_id` and passes it as the Ash tenant; a
`nil` tenant means the global row.

# `chelekom_rows`

The named rows of the Chelekom kit this library ships, as palette entries (`name`, `attrs`,
`slots`, `template`), in the order asked. The bundle is 12 MB, so call it from `setup_all`.

# `create_component!`

# `create_error_page!`

# `create_js_hook!`

# `create_layout!`

# `create_many!`

`rows` of `resource`, written in one bulk create through its `:create` action under `tenant` (`nil`
for global rows), as a fixture: for a suite that needs more rows than one page of a read holds,
where a create per row costs seconds. Each row is the action's input, and nothing is compiled.

# `create_media!`

# `create_media_category!`

# `create_page!`

# `create_permission!`

# `create_redirect!`

# `create_site!`

# `create_user!`

# `create_user_with_permissions!`

A user holding `permission_names`, returned with `:permissions` loaded so it can be used directly
as an Ash `actor:` without a further load.

Authorization in this CMS turns on two independent things — WHICH permissions a user holds and
WHICH site they belong to — so most policy tests need the same three actors: a master
(`site_id: nil`) with roles, a tenant with the same roles, and a tenant with none. Permissions are
looked up before being created so several actors can share one named permission in a test.

    master = create_user_with_permissions!(["admin:dashboard:*"])
    tenant = create_user_with_permissions!(["admin:dashboard:*"], site_id: site.id)
    nobody = create_user!(site_id: site.id)

# `define_component!`

A component module put by hand at the name the compilers would have built for `name` on `site` (a
site, or `nil` for a global one), drawing `html` — for a test about the canvas rather than the
compile pipeline.

It answers the site it stands for as a compiled one does, since
`MishkaCmsCore.Runtime.LiveViewHelpers` draws a module only for its own site, and it goes when the
test does.

# `every_option_shape`

An `attrs` declaration holding one of every option shape the Chelekom kit ships, for a test about
what a save keeps.

Defaults of `nil`, `""`, `false`, `true`, `0`, `1.0` and `[]`; `values` that include `nil`, as
`chelekom-button`'s `type` does; `editor`; and `default_struct` on a struct attribute. Rows are
string-keyed, as a row read back from the database is. `every_option_template/0` reads each one.

# `every_option_template`

A template reading every attribute `every_option_shape/0` declares, so a default lost on the way
raises `KeyError` the first time the component renders without that attribute.

# `forget_component_on_exit`

The same cleanup `create_component!/1` registers, for a name the component only takes during the
test — a rename builds a second module, under the new name.

# `renamed_form_pair`

Chelekom's Form Wrapper and Simple Form copied as `wrapper` and `simple`, the Simple Form calling
the copied wrapper and no longer requiring `for`: a pair only their markup marks as forms. `rows`
holds both originals, as `chelekom_rows/1` answers them.

---

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