defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
use Pleroma.DataCase
- alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
+ alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.User
alias Pleroma.Web.OStatus
alias Pleroma.Web.CommonAPI
expected = %{
id: to_string(note.id),
uri: note.data["object"]["id"],
- url: note.data["object"]["id"],
+ url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, note),
account: AccountView.render("account.json", %{user: user}),
in_reply_to_id: nil,
in_reply_to_account_id: nil,
+ card: nil,
reblog: nil,
content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
created_at: created_at,
replies_count: 0,
favourites_count: 0,
reblogged: false,
+ bookmarked: false,
favourited: false,
muted: false,
pinned: false,
]
end
end
+
+ describe "rich media cards" do
+ test "a rich media card without a site name renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ image: page_url <> "/example.jpg",
+ title: "Example website"
+ }
+
+ %{provider_name: "example.com"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+
+ test "a rich media card without a site name or image renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ title: "Example website"
+ }
+
+ %{provider_name: "example.com"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+
+ test "a rich media card without an image renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ site_name: "Example site name",
+ title: "Example website"
+ }
+
+ %{provider_name: "Example site name"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+
+ test "a rich media card with all relevant data renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ site_name: "Example site name",
+ title: "Example website",
+ image: page_url <> "/example.jpg",
+ description: "Example description"
+ }
+
+ %{provider_name: "Example site name"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+ end
end