11// @vitest -environment node
22import type { PostSegment } from '../../shared/trending-post'
33import { describe , expect , it } from 'vitest'
4- import { postExcerpt , relativeDay , unstyled } from '../../shared/trending-post'
4+ import { postExcerpt , relativeDay } from '../../shared/trending-post'
55
66function plain ( segments : PostSegment [ ] ) : string {
77 return segments . map ( s => s . value ) . join ( '' )
@@ -86,28 +86,9 @@ describe('postExcerpt', () => {
8686 expect ( text . length ) . toBeLessThan ( 80 )
8787 } )
8888
89- it ( 'drops emoji and keeps the words around them' , ( ) => {
90- const excerpt = postExcerpt ( {
91- text : 'π Celebrating π (500+ new stars) π¦ blader / humanizer βοΈ π¨βπ©βπ§ π¦πΊ' ,
92- names : [ ] ,
93- budget : 200 ,
94- } )
95- expect ( plain ( excerpt ) ) . toBe ( 'Celebrating (500+ new stars) blader / humanizer' )
96- } )
97-
98- it ( 'keeps the digit of a keycap emoji' , ( ) => {
99- const excerpt = postExcerpt ( { text : '1οΈβ£ Install\n2οΈβ£ Prompt' , names : [ ] , budget : 200 } )
100- expect ( plain ( excerpt ) ) . toBe ( '1 Install\n2 Prompt' )
101- } )
102-
103- it ( 'reads Unicode bold and italic letters as plain text' , ( ) => {
104- const excerpt = postExcerpt ( {
105- text : 'as long as you ππ΅πΌπ πΆπ ππΌπ½-ππΆπ²πΏ design with ππͺπ’ππ£ππ―ππ§' ,
106- names : [ 'humanizer' ] ,
107- budget : 200 ,
108- } )
109- expect ( plain ( excerpt ) ) . toBe ( 'as long as you show it top-tier design with humanizer' )
110- expect ( mentions ( excerpt ) ) . toEqual ( [ 'humanizer' ] )
89+ it ( 'keeps every character it is given, so the server and the browser cut the same text' , ( ) => {
90+ const text = '33.5kβ
π ππ΅πΌπ ββ'
91+ expect ( plain ( postExcerpt ( { text, names : [ ] , budget : 200 } ) ) ) . toBe ( text )
11192 } )
11293
11394 it ( 'returns the tidied text as one segment when no name matches' , ( ) => {
@@ -116,12 +97,6 @@ describe('postExcerpt', () => {
11697 } )
11798} )
11899
119- describe ( 'unstyled' , ( ) => {
120- it ( 'returns a display name as plain letters without emoji' , ( ) => {
121- expect ( unstyled ( 'ππΌπ΅π» β‘οΈ' ) . trim ( ) ) . toBe ( 'John' )
122- } )
123- } )
124-
125100describe ( 'relativeDay' , ( ) => {
126101 const NOW = 1_760_000_000
127102
0 commit comments