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
Creates a draft Beacon.Content.Layout
.
Uploads a given "upload metadata" created by beacon_upload_metadata_fixture/1
.
Creates a draft Beacon.Content.Page
Similar to beacon_layout_fixture/1
, but also publishes the layout.
Similar to beacon_page_fixture/1
, but also publishes the page.
Functions
@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{}
@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{}
@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{}
@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{}
@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{}
@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{}
@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{}
@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{}
@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{}
@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{}
@spec beacon_published_layout_fixture(map() | Keyword.t()) :: Beacon.Content.Layout.t()
Similar to beacon_layout_fixture/1
, but also publishes the layout.
@spec beacon_published_page_fixture(map() | Keyword.t()) :: Beacon.Content.Page.t()
Similar to beacon_page_fixture/1
, but also publishes the page.
@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{}
@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{}
@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{}