View Source Beacon.Test.Fixtures (Beacon v0.2.1)

Fixture data for testing Beacon content.

Only use for testing

These fixtures should be used only for testing purposes, if you are looking to run seeds or some sort of content automation then you should use Beacon.Content functions instead.

Usage

Most of the times you'll use the Beacon.Test function instead of using fixtures directly:

use Beacon.Test

Using Beacon.Test will import the fixtures for you.

But you can also use the fixtures directly for some cases:

use Beacon.Test.Fixtures

Fixtures

All fixtures accept either a map or a keyword list, so these are equivalent:

beacon_page_fixture(path: "/contact")
beacon_page_fixture(%{path: "/contact"})
beacon_page_fixture(%{"path" => "/contact"})

Or no attributes at all to use the default values:

beacon_page_fixture()

Default site

You can pass a default site to be used in the attrs for all fixture functions:

use Beacon.Test.Fixtures, site: :blog

Note that only one default site is permitted per test module, if you have a test that requires asserting multiple sites you can just override particular fixtures:

use Beacon.Test.Fixtures, site: :blog

# create a page for the default site
beacon_page_fixture()

# create a page for another site
beacon_page_fixture(site: :other)

Summary

Functions

Link to this function

beacon_component_fixture(attrs)

View Source
@spec beacon_component_fixture(map() | Keyword.t()) :: Beacon.Content.Component.t()

Creates a Beacon.Content.Component.

Example

iex> beacon_component_fixture(name: "sample_component")
%Beacon.Content.Component{}
Link to this function

beacon_error_page_fixture(attrs)

View Source
@spec beacon_error_page_fixture(map() | Keyword.t()) :: Beacon.Content.ErrorPage.t()

Creates a Beacon.Content.ErrorPage.

Example

iex> beacon_error_page_fixture(status: 404, template: "nothing here")
%Beacon.Content.ErrorPage{}
Link to this function

beacon_event_handler_fixture(attrs)

View Source
@spec beacon_event_handler_fixture(map() | Keyword.t()) ::
  Beacon.Content.EventHandler.t()

Creates a Beacon.Content.EventHandler.

Example

iex> beacon_event_handler_fixture(code: ~S"""
  email = event_params["newsletter"]["email"]
  MyApp.Newsletter.subscribe(email)
  {:noreply, socket}
""")
%Beacon.Content.EventHandler{}
Link to this function

beacon_info_handler_fixture(attrs)

View Source
@spec beacon_info_handler_fixture(map() | Keyword.t()) ::
  Beacon.Content.InfoHandler.t()

Creates a Beacon.Content.InfoHandler.

Example

iex> beacon_info_handler_fixture(msg: "{:subscribed, email}", code: ~S"""
MyApp.Notifications.send_email(email, "Welcome!")
{:noreply, socket}
""")
%Beacon.Content.InfoHandler{}
Link to this function

beacon_layout_fixture(attrs \\ %{})

View Source
@spec beacon_layout_fixture(map() | Keyword.t()) :: Beacon.Content.Layout.t()

Creates a draft Beacon.Content.Layout.

Examples

iex> beacon_layout_fixture()
%Beacon.Content.Layout{}

iex> beacon_layout_fixture(template: "<%= @inner_content %>")
%Beacon.Content.Layout{}
Link to this function

beacon_live_data_assign_fixture(attrs)

View Source
@spec beacon_live_data_assign_fixture(map() | Keyword.t()) ::
  Beacon.Content.LiveDataAssign.t()

Creates a Beacon.Content.LiveDataAssign.

Example

iex> beacon_live_data_assign_fixture(live_data: live_data, key: "user", value: "%{id: 1, name: "John"}")
%Beacon.Content.LiveDataAssign{}
Link to this function

beacon_live_data_fixture(attrs)

View Source
@spec beacon_live_data_fixture(map() | Keyword.t()) :: Beacon.Content.LiveData.t()

Creates a Beacon.Content.LiveData.

Example

iex> beacon_live_data_fixture(path: "/contact")
%Beacon.Content.LiveData{}
Link to this function

beacon_media_library_asset_fixture(attrs)

View Source
@spec beacon_media_library_asset_fixture(map() | Keyword.t()) ::
  Beacon.MediaLibrary.Asset.t()

Uploads a given "upload metadata" created by beacon_upload_metadata_fixture/1.

Example

iex> beacon_media_library_asset_fixture(upload_metadata)
%Beacon.MediaLibrary.Asset{}
Link to this function

beacon_page_fixture(attrs)

View Source
@spec beacon_page_fixture(map() | Keyword.t()) :: Beacon.Content.Page.t()

Creates a draft Beacon.Content.Page

Examples

iex> beacon_page_fixture()
%Beacon.Content.Page{}

iex> beacon_page_fixture(title: "Home")
%Beacon.Content.Page{}
Link to this function

beacon_page_variant_fixture(attrs)

View Source
@spec beacon_page_variant_fixture(map() | Keyword.t()) ::
  Beacon.Content.PageVariant.t()

Creates a Beacon.Content.PageVariant.

Example

iex> beacon_page_variant_fixture(page: page, weight: 50, template: "<h1>Variant B</h1>")
%Beacon.Content.PageVariant{}
Link to this function

beacon_published_layout_fixture(attrs)

View Source
@spec beacon_published_layout_fixture(map() | Keyword.t()) ::
  Beacon.Content.Layout.t()

Similar to beacon_layout_fixture/1, but also publishes the layout.

Link to this function

beacon_published_page_fixture(attrs)

View Source
@spec beacon_published_page_fixture(map() | Keyword.t()) :: Beacon.Content.Page.t()

Similar to beacon_page_fixture/1, but also publishes the page.

Link to this function

beacon_snippet_helper_fixture(attrs)

View Source
@spec beacon_snippet_helper_fixture(map() | Keyword.t()) ::
  Beacon.Content.Snippets.Helper.t()

Creates a Beacon.Content.Snippets.Helper.

Example

iex> beacon_snippet_helper_fixture(body: ~S"""
  assigns |> get_in(["page", "title"]) |> String.trim()
""")
%Beacon.Content.Snippets.Helper{}
Link to this function

beacon_stylesheet_fixture(attrs)

View Source
@spec beacon_stylesheet_fixture(map() | Keyword.t()) :: Beacon.Content.Stylesheet.t()

Creates a Beacon.Content.Stylesheet.

Example

iex> beacon_stylesheet_fixture(content: "h1 { color: red; }")
%Beacon.Content.Stylesheet{}
Link to this function

beacon_upload_metadata_fixture(attrs)

View Source
@spec beacon_upload_metadata_fixture(map() | Keyword.t()) ::
  Beacon.MediaLibrary.UploadMetadata.t()

Creates a Beacon.MediaLibrary.UploadMetadata.

Example

iex> beacon_upload_metadata_fixture(file_size: 100_000)
%Beacon.MediaLibrary.UploadMetadata{}