@@ -6,12 +6,41 @@ class TestBuildTextAndFacets:
66 def setup_method (self ):
77 self .poster = PosterBluesky .__new__ (PosterBluesky )
88
9- def test_no_tags_produces_no_facets (self ):
9+ def test_no_tags_no_link_produces_no_facets (self ):
1010 post = Post (text = "Hello, world!" )
1111 text , facets = self .poster ._build_text_and_facets (post )
1212 assert text == "Hello, world!"
1313 assert facets == []
1414
15+ def test_link_without_tags_produces_link_facet (self ):
16+ url = "https://example.com/adopt"
17+ post = Post (text = f"Meet Poppy!\n \n { url } " , link = url )
18+ text , facets = self .poster ._build_text_and_facets (post )
19+
20+ assert text == post .text
21+ assert len (facets ) == 1
22+ enc = text .encode ("utf-8" )
23+ f = facets [0 ]
24+ assert enc [f ["index" ]["byteStart" ] : f ["index" ]["byteEnd" ]] == url .encode ("utf-8" )
25+ assert f ["features" ][0 ]["$type" ] == "app.bsky.richtext.facet#link"
26+ assert f ["features" ][0 ]["uri" ] == url
27+
28+ def test_link_and_tags_facets_sorted_by_byte_start (self ):
29+ url = "https://rg.org/pet/1"
30+ post = Post (
31+ text = f"Adopt me!\n \n { url } " ,
32+ tags = ["AdoptDontShop" , "Boston" , "DogsOfBluesky" ],
33+ link = url ,
34+ )
35+ text , facets = self .poster ._build_text_and_facets (post )
36+
37+ assert text .endswith ("\n \n #AdoptDontShop #Boston #DogsOfBluesky" )
38+ assert len (facets ) == 4
39+ assert facets [0 ]["features" ][0 ]["$type" ] == "app.bsky.richtext.facet#link"
40+ assert facets [0 ]["features" ][0 ]["uri" ] == url
41+ for facet in facets [1 :]:
42+ assert facet ["features" ][0 ]["$type" ] == "app.bsky.richtext.facet#tag"
43+
1544 def test_tags_produce_facets_with_correct_byte_offsets (self ):
1645 post = Post (text = "Adopt me!" , tags = ["AdoptDontShop" , "Boston" , "DogsOfBluesky" ])
1746 text , facets = self .poster ._build_text_and_facets (post )
0 commit comments