|
| 1 | +defmodule JolaDevWeb.SEOTest do |
| 2 | + use JolaDevWeb.ConnCase, async: true |
| 3 | + |
| 4 | + describe "json_ld/1" do |
| 5 | + test "includes WebSite schema on all pages", %{conn: conn} do |
| 6 | + conn = get(conn, ~p"/") |
| 7 | + schemas = JolaDevWeb.SEO.json_ld(conn) |
| 8 | + |
| 9 | + website = Enum.find(schemas, &(&1["@type"] == "WebSite")) |
| 10 | + assert website["name"] == "jola.dev" |
| 11 | + assert website["url"] == "https://jola.dev" |
| 12 | + end |
| 13 | + |
| 14 | + test "includes BlogPosting schema on blog post pages", %{conn: conn} do |
| 15 | + post = List.first(JolaDev.Blog.all_posts()) |
| 16 | + conn = get(conn, ~p"/posts/#{post.id}") |
| 17 | + schemas = JolaDevWeb.SEO.json_ld(conn) |
| 18 | + |
| 19 | + blog_posting = Enum.find(schemas, &(&1["@type"] == "BlogPosting")) |
| 20 | + assert blog_posting["headline"] == post.title |
| 21 | + assert blog_posting["description"] == post.description |
| 22 | + assert blog_posting["datePublished"] == Date.to_iso8601(post.date) |
| 23 | + assert blog_posting["author"]["@type"] == "Person" |
| 24 | + assert blog_posting["keywords"] == post.tags |
| 25 | + end |
| 26 | + |
| 27 | + test "includes ProfilePage schema on about page", %{conn: conn} do |
| 28 | + conn = get(conn, ~p"/about") |
| 29 | + schemas = JolaDevWeb.SEO.json_ld(conn) |
| 30 | + |
| 31 | + profile = Enum.find(schemas, &(&1["@type"] == "ProfilePage")) |
| 32 | + assert profile["mainEntity"]["@type"] == "Person" |
| 33 | + assert profile["mainEntity"]["name"] == "Johanna Larsson" |
| 34 | + assert is_list(profile["mainEntity"]["sameAs"]) |
| 35 | + end |
| 36 | + |
| 37 | + test "does not include BlogPosting on non-post pages", %{conn: conn} do |
| 38 | + conn = get(conn, ~p"/projects") |
| 39 | + schemas = JolaDevWeb.SEO.json_ld(conn) |
| 40 | + |
| 41 | + refute Enum.any?(schemas, &(&1["@type"] == "BlogPosting")) |
| 42 | + end |
| 43 | + end |
| 44 | +end |
0 commit comments