+ {_text, mentions, []} = Formatter.linkify(text)
+ [{username, user}] = mentions
+
+ assert username == "@lain@lain.com"
+ assert user.nickname == "lain@lain.com"
+ end
+
+ test "gives a replacement for user links, using local nicknames in user links text" do
+ text = "@gsimg According to @archa_eme_, that is @daggsy. Also hello @archaeme@archae.me"
+ gsimg = insert(:user, %{nickname: "gsimg"})
+
+ archaeme =
+ insert(:user,
+ nickname: "archa_eme_",
+ source_data: %{"url" => "https://archeme/@archa_eme_"}
+ )
+
+ archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
+
+ {text, mentions, []} = Formatter.linkify(text)
+
+ assert length(mentions) == 3
+
+ expected_text =
+ ~s(<span class="h-card"><a data-user="#{gsimg.id}" class="u-url mention" href="#{
+ gsimg.ap_id
+ }" rel="ugc">@<span>gsimg</span></a></span> According to <span class="h-card"><a data-user="#{
+ archaeme.id
+ }" class="u-url mention" href="#{"https://archeme/@archa_eme_"}" rel="ugc">@<span>archa_eme_</span></a></span>, that is @daggsy. Also hello <span class="h-card"><a data-user="#{
+ archaeme_remote.id
+ }" class="u-url mention" href="#{archaeme_remote.ap_id}" rel="ugc">@<span>archaeme</span></a></span>)
+
+ assert expected_text == text
+ end
+
+ test "gives a replacement for user links when the user is using Osada" do
+ {:ok, mike} = User.get_or_fetch("mike@osada.macgirvin.com")
+
+ text = "@mike@osada.macgirvin.com test"
+
+ {text, mentions, []} = Formatter.linkify(text)
+
+ assert length(mentions) == 1
+
+ expected_text =
+ ~s(<span class="h-card"><a data-user="#{mike.id}" class="u-url mention" href="#{
+ mike.ap_id
+ }" rel="ugc">@<span>mike</span></a></span> test)
+
+ assert expected_text == text
+ end
+
+ test "gives a replacement for single-character local nicknames" do
+ text = "@o hi"
+ o = insert(:user, %{nickname: "o"})
+
+ {text, mentions, []} = Formatter.linkify(text)
+
+ assert length(mentions) == 1
+
+ expected_text =
+ ~s(<span class="h-card"><a data-user="#{o.id}" class="u-url mention" href="#{o.ap_id}" rel="ugc">@<span>o</span></a></span> hi)
+
+ assert expected_text == text