Skip to content

Commit

Permalink
Another test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
APB9785 committed Jan 23, 2024
1 parent e5e5b1e commit ec4addd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 36 deletions.
36 changes: 0 additions & 36 deletions test/beacon/loader/page_module_loader_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,6 @@ defmodule Beacon.Loader.PageModuleLoaderTest do
end

describe "page_assigns/1" do
test "interpolates meta tag snippets" do
snippet_helper_fixture(%{
site: "my_site",
name: "og_description",
body: ~S"""
assigns
|> get_in(["page", "description"])
|> String.upcase()
"""
})

layout = published_layout_fixture()

page =
[
site: "my_site",
layout_id: layout.id,
path: "page/meta-tag",
title: "my first page",
description: "my test page",
meta_tags: [
%{"property" => "og:description", "content" => "{% helper 'og_description' %}"},
%{"property" => "og:url", "content" => "http://example.com/{{ page.path }}"}
]
]
|> published_page_fixture()
|> Repo.preload(:event_handlers)

Beacon.Loader.load_page(page)

{:ok, _module, ast} = PageModuleLoader.load_page!(page)

assert has_fields?(ast, [{"content", "MY TEST PAGE"}, {"property", "og:description"}])
assert has_fields?(ast, [{"content", "http://example.com/page/meta-tag"}, {"property", "og:url"}])
end

test "interpolates raw_schema snippets" do
snippet_helper_fixture(%{
site: "my_site",
Expand Down
50 changes: 50 additions & 0 deletions test/beacon_web/live/page_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,56 @@ defmodule BeaconWeb.Live.PageLiveTest do
test "render without meta tags", %{conn: conn} do
assert {:ok, _view, _html} = live(conn, "/without_meta_tags")
end

test "interpolate snippets", %{conn: conn} do
snippet_helper_fixture(%{
site: "my_site",
name: "og_description",
body: ~S"""
assigns
|> get_in(["page", "description"])
|> String.upcase()
"""
})

layout = published_layout_fixture()

page =
[
site: "my_site",
layout_id: layout.id,
path: "page/meta-tag",
title: "my first page",
description: "my test page",
meta_tags: [
%{"property" => "og:description", "content" => "{% helper 'og_description' %}"},
%{"property" => "og:url", "content" => "http://example.com/{{ page.path }}"},
%{"property" => "og:image", "content" => "{{ live_data.image }}"}
]
]
|> published_page_fixture()
|> Beacon.Repo.preload(:event_handlers)

live_data = live_data_fixture(path: "page/meta-tag")
live_data_assign_fixture(live_data, format: :text, key: "image", value: "http://img.example.com")

Beacon.Loader.DataSourceModuleLoader.load_data_source([Beacon.Repo.preload(live_data, :assigns)], :my_site)
Beacon.Loader.load_page(page)

{:ok, _view, html} = live(conn, "/page/meta-tag")

expected =
~S"""
<meta content="MY TEST PAGE" property="og:description"/>
<meta content="http://example.com/page/meta-tag" property="og:url"/>
<meta content="http://img.example.com" property="og:image"/>
"""
|> String.replace("\n", "")
|> String.replace(" ", "")
|> Regex.compile!()

assert html =~ expected
end
end

describe "resource links" do
Expand Down

0 comments on commit ec4addd

Please sign in to comment.