From 64cea557bebdb0a5b4f17362d8e66845b0a77113 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Mon, 5 Dec 2022 23:44:26 -0500 Subject: Collapse linkify mentions (#123) --- tests/activities/models/test_post.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'tests/activities') diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py index 06d26ed..a5f2f79 100644 --- a/tests/activities/models/test_post.py +++ b/tests/activities/models/test_post.py @@ -32,7 +32,9 @@ def test_fetch_post(httpx_mock: HTTPXMock, config_system): @pytest.mark.django_db -def test_linkify_mentions_remote(identity, remote_identity): +def test_linkify_mentions_remote( + identity, identity2, remote_identity, remote_identity2 +): """ Tests that we can linkify post mentions properly for remote use """ @@ -77,9 +79,28 @@ def test_linkify_mentions_remote(identity, remote_identity): == '

Hey @test

' ) + # Test that collapsing only applies to the first unique, short username + post = Post.objects.create( + content="

Hey @TeSt@remote.test and @test@remote2.test

", + author=identity, + local=True, + ) + post.mentions.set([remote_identity, remote_identity2]) + assert post.safe_content_remote() == ( + '

Hey @test ' + 'and @test@remote2.test

' + ) + + post.content = "

Hey @TeSt, @Test@remote.test and @test

" + assert post.safe_content_remote() == ( + '

Hey @test, ' + '@test@remote.test ' + 'and @test

' + ) + @pytest.mark.django_db -def test_linkify_mentions_local(identity, remote_identity): +def test_linkify_mentions_local(identity, identity2, remote_identity): """ Tests that we can linkify post mentions properly for local use """ @@ -96,14 +117,16 @@ def test_linkify_mentions_local(identity, remote_identity): ) # Test a full username (local) post = Post.objects.create( - content="

@test@example.com, welcome!

", + content="

@test@example.com, welcome! @test@example2.com @test@example.com

", author=identity, local=True, ) post.mentions.add(identity) - assert ( - post.safe_content_local() - == '

@test, welcome!

' + post.mentions.add(identity2) + assert post.safe_content_local() == ( + '

@test, welcome!' + ' @test@example2.com' + ' @test

' ) # Test a full username (remote) with no

post = Post.objects.create( -- cgit v1.2.3