@@ -91,10 +91,11 @@ describe('Profile Info Component', () => {
9191
9292 const { getByText } = render ( < ProfileInfo profile = { profile } /> ) ;
9393
94- expect ( getByText ( '@janedoe ' ) ) . toBeTruthy ( ) ;
94+ expect ( getByText ( '@janedoe' ) ) . toBeTruthy ( ) ;
9595 } ) ;
9696
9797 it ( 'navigates to user profile when mention is clicked' , ( ) => {
98+ const mockOnPressMention = jest . fn ( ) ;
9899 const profile = {
99100 ...mockProfile ,
100101 bio : 'Hello @janedoe' ,
@@ -104,12 +105,14 @@ describe('Profile Info Component', () => {
104105 } ,
105106 } ;
106107
107- const { getAllByText } = render ( < ProfileInfo profile = { profile } /> ) ;
108+ const { getByText } = render (
109+ < ProfileInfo profile = { profile } onPressMention = { mockOnPressMention } />
110+ ) ;
108111
109- const mentions = getAllByText ( '@janedoe ' ) ;
110- fireEvent . press ( mentions [ 0 ] ) ; // Press the first one (the link)
112+ const mention = getByText ( '@janedoe' ) ;
113+ fireEvent . press ( mention ) ;
111114
112- expect ( mockPush ) . toHaveBeenCalledWith ( 'UserProfile' , { username : ' janedoe' } ) ;
115+ expect ( mockOnPressMention ) . toHaveBeenCalledWith ( 'janedoe' ) ;
113116 } ) ;
114117
115118 it ( 'renders bio with hashtags as links' , ( ) => {
@@ -125,13 +128,10 @@ describe('Profile Info Component', () => {
125128 } ,
126129 } ;
127130
128- const { getAllByText } = render ( < ProfileInfo profile = { profile } /> ) ;
129-
130- const codingHashtags = getAllByText ( '#Coding ' ) ;
131- const techHashtags = getAllByText ( '#Tech ' ) ;
131+ const { getByText } = render ( < ProfileInfo profile = { profile } /> ) ;
132132
133- expect ( codingHashtags . length ) . toBeGreaterThan ( 0 ) ;
134- expect ( techHashtags . length ) . toBeGreaterThan ( 0 ) ;
133+ expect ( getByText ( '#Coding' ) ) . toBeTruthy ( ) ;
134+ expect ( getByText ( '#Tech' ) ) . toBeTruthy ( ) ;
135135 } ) ;
136136
137137 it ( 'renders bio with mixed mentions and hashtags' , ( ) => {
@@ -144,15 +144,10 @@ describe('Profile Info Component', () => {
144144 } ,
145145 } ;
146146
147- const { getAllByText } = render ( < ProfileInfo profile = { profile } /> ) ;
148-
149- const mentions = getAllByText ( '@janedoe ' ) ;
150- expect ( mentions . length ) . toBeGreaterThan ( 0 ) ;
151-
152- const hashtags = getAllByText ( '#Coding ' ) ;
153- expect ( hashtags . length ) . toBeGreaterThan ( 0 ) ;
147+ const { getByText } = render ( < ProfileInfo profile = { profile } /> ) ;
154148
155- // Note: "check " is part of a larger text segment, not a separate text node
149+ expect ( getByText ( '@janedoe' ) ) . toBeTruthy ( ) ;
150+ expect ( getByText ( '#Coding' ) ) . toBeTruthy ( ) ;
156151 } ) ;
157152
158153 it ( 'handles bio with no entities' , ( ) => {
@@ -192,12 +187,10 @@ describe('Profile Info Component', () => {
192187 } ,
193188 } ;
194189
195- const { getByText, getAllByText } = render ( < ProfileInfo profile = { profile } /> ) ;
190+ const { getByText } = render ( < ProfileInfo profile = { profile } /> ) ;
196191
197192 expect ( getByText ( 'Text with hashtag ' ) ) . toBeTruthy ( ) ;
198-
199- const hashtags = getAllByText ( '#Test ' ) ;
200- expect ( hashtags . length ) . toBeGreaterThan ( 0 ) ;
193+ expect ( getByText ( '#Test' ) ) . toBeTruthy ( ) ;
201194 } ) ;
202195
203196 it ( 'handles bio with undefined hashtags in bioEntities' , ( ) => {
@@ -210,12 +203,10 @@ describe('Profile Info Component', () => {
210203 } ,
211204 } ;
212205
213- const { getByText, getAllByText } = render ( < ProfileInfo profile = { profile } /> ) ;
206+ const { getByText } = render ( < ProfileInfo profile = { profile } /> ) ;
214207
215208 expect ( getByText ( 'Text with mention ' ) ) . toBeTruthy ( ) ;
216-
217- const mentions = getAllByText ( '@user ' ) ;
218- expect ( mentions . length ) . toBeGreaterThan ( 0 ) ;
209+ expect ( getByText ( '@user' ) ) . toBeTruthy ( ) ;
219210 } ) ;
220211
221212 it ( 'passes correct data to ProfileUser' , ( ) => {
@@ -240,12 +231,10 @@ describe('Profile Info Component', () => {
240231 } ,
241232 } ;
242233
243- const { getAllByText } = render ( < ProfileInfo profile = { profile } /> ) ;
244-
245- const mentions = getAllByText ( '@janedoe ' ) ;
246- expect ( mentions . length ) . toBeGreaterThan ( 0 ) ;
234+ const { getByText } = render ( < ProfileInfo profile = { profile } /> ) ;
247235
248- // Note: "hello" is part of the bio text that follows the mention
236+ expect ( getByText ( '@janedoe' ) ) . toBeTruthy ( ) ;
237+ expect ( getByText ( ' hello' ) ) . toBeTruthy ( ) ;
249238 } ) ;
250239
251240 it ( 'handles bio entities at the end of the bio' , ( ) => {
@@ -258,12 +247,10 @@ describe('Profile Info Component', () => {
258247 } ,
259248 } ;
260249
261- const { getByText, getAllByText } = render ( < ProfileInfo profile = { profile } /> ) ;
250+ const { getByText } = render ( < ProfileInfo profile = { profile } /> ) ;
262251
263252 expect ( getByText ( 'hello ' ) ) . toBeTruthy ( ) ;
264-
265- const mentions = getAllByText ( '@janedoe ' ) ;
266- expect ( mentions . length ) . toBeGreaterThan ( 0 ) ;
253+ expect ( getByText ( '@janedoe' ) ) . toBeTruthy ( ) ;
267254 } ) ;
268255
269256 it ( 'sorts entities by start position' , ( ) => {
@@ -276,14 +263,9 @@ describe('Profile Info Component', () => {
276263 } ,
277264 } ;
278265
279- const { getAllByText } = render ( < ProfileInfo profile = { profile } /> ) ;
280-
281- const hashtags = getAllByText ( '#Tech ' ) ;
282- expect ( hashtags . length ) . toBeGreaterThan ( 0 ) ;
283-
284- const mentions = getAllByText ( '@janedoe ' ) ;
285- expect ( mentions . length ) . toBeGreaterThan ( 0 ) ;
266+ const { getByText } = render ( < ProfileInfo profile = { profile } /> ) ;
286267
287- // Entities are sorted and rendered in correct order
268+ expect ( getByText ( '#Tech' ) ) . toBeTruthy ( ) ;
269+ expect ( getByText ( '@janedoe' ) ) . toBeTruthy ( ) ;
288270 } ) ;
289271} ) ;
0 commit comments