@@ -19,6 +19,8 @@ import { UserClass } from '../../support/user/UserClass';
1919import { REACTION_EMOJIS , reactOnFeed } from '../../utils/activityFeed' ;
2020import { performAdminLogin } from '../../utils/admin' ;
2121import {
22+ getAuthContext ,
23+ getToken ,
2224 redirectToHomePage ,
2325 removeLandingBanner ,
2426 uuid ,
@@ -33,18 +35,24 @@ import { editDisplayName } from '../../utils/user';
3335
3436const test = base ;
3537
36- const adminUser = new UserClass ( ) ;
37- const user1 = new UserClass ( ) ;
38- const entity = new TableClass ( ) ;
39- const extraEntity = new TableClass ( ) ;
40- const testPersona = new PersonaClass ( ) ;
41-
4238test . describe ( 'FeedWidget on landing page' , ( ) => {
39+ let adminUser : UserClass ;
40+ let user1 : UserClass ;
41+ let entity : TableClass ;
42+ let extraEntity : TableClass ;
43+ let testPersona : PersonaClass ;
44+
4345 test . beforeAll (
4446 'setup: seed entities, users, create persona, and customize widget' ,
4547 async ( { browser } ) => {
4648 test . slow ( true ) ;
4749
50+ adminUser = new UserClass ( ) ;
51+ user1 = new UserClass ( ) ;
52+ entity = new TableClass ( ) ;
53+ extraEntity = new TableClass ( ) ;
54+ testPersona = new PersonaClass ( ) ;
55+
4856 const { apiContext, afterAction } = await performAdminLogin ( browser ) ;
4957
5058 try {
@@ -369,9 +377,9 @@ test.describe('FeedWidget on landing page', () => {
369377} ) ;
370378
371379test . describe ( 'Mention notifications in Notification Box' , ( ) => {
372- const adminUser = new UserClass ( ) ;
373- const user1 = new UserClass ( ) ;
374- const entity = new TableClass ( ) ;
380+ let adminUser : UserClass ;
381+ let user1 : UserClass ;
382+ let entity : TableClass ;
375383
376384 const test = base . extend < {
377385 adminPage : Page ;
@@ -392,12 +400,25 @@ test.describe('Mention notifications in Notification Box', () => {
392400 } ) ;
393401
394402 test . beforeAll ( 'Setup entities and users' , async ( { browser } ) => {
403+ adminUser = new UserClass ( ) ;
404+ user1 = new UserClass ( ) ;
405+ entity = new TableClass ( ) ;
406+
395407 const { apiContext, afterAction } = await performAdminLogin ( browser ) ;
396408
397409 await adminUser . create ( apiContext ) ;
398410 await adminUser . setAdminRole ( apiContext ) ;
399411 await user1 . create ( apiContext ) ;
400412 await entity . create ( apiContext ) ;
413+
414+ await apiContext . post ( '/api/v1/feed' , {
415+ data : {
416+ message : 'Initial conversation thread for mention test' ,
417+ about : `<#E::table::${ entity . entityResponseData . fullyQualifiedName } >` ,
418+ type : 'Conversation' ,
419+ } ,
420+ } ) ;
421+
401422 await afterAction ( ) ;
402423 } ) ;
403424
@@ -407,57 +428,44 @@ test.describe('Mention notifications in Notification Box', () => {
407428 } ) => {
408429 test . slow ( ) ;
409430
410- await test . step ( 'Admin user creates a conversation on an entity' , async ( ) => {
411- await entity . visitEntityPage ( adminPage ) ;
412- // Added a safety check on waiting for activity feed count to avoid missing feed
413- // Poll the activity feed tab count from the page until it's a valid non-negative number
414- let count = NaN ;
415- const maxRetries = 30 ;
416- for ( let i = 0 ; i < maxRetries && ( isNaN ( count ) || count <= 0 ) ; i ++ ) {
417- const countText = await adminPage
418- . getByRole ( 'tab' , { name : 'Activity Feeds & Tasks' } )
419- . getByTestId ( 'count' )
420- . textContent ( ) ;
421- count = Number ( countText ?? '0' ) ;
422- if ( isNaN ( count ) || count <= 0 ) {
423- await adminPage . reload ( ) ;
424- await waitForAllLoadersToDisappear ( adminPage ) ;
425- }
426- }
427-
428- await adminPage . getByTestId ( 'activity_feed' ) . click ( ) ;
429-
430- await waitForAllLoadersToDisappear ( adminPage ) ;
431-
432- await adminPage . getByTestId ( 'comments-input-field' ) . click ( ) ;
431+ await test . step ( 'User1 mentions admin user in a reply' , async ( ) => {
432+ await entity . visitEntityPage ( user1Page ) ;
433433
434- await adminPage
435- . locator (
436- '[data-testid="editor-wrapper"] [contenteditable="true"].ql-editor'
434+ const token = await getToken ( user1Page ) ;
435+ const apiContext = await getAuthContext ( token ) ;
436+ const feedUrl = `/api/v1/feed?entityLink=${ encodeURIComponent (
437+ `<#E::table::${ entity . entityResponseData . fullyQualifiedName } >`
438+ ) } &type=Conversation&limit=25`;
439+
440+ await expect
441+ . poll (
442+ async ( ) => {
443+ const response = await apiContext . get ( feedUrl ) ;
444+ const data = await response . json ( ) ;
445+
446+ return ( data . data ?? [ ] ) . some ( ( thread : { message ?: string } ) =>
447+ thread . message ?. includes (
448+ 'Initial conversation thread for mention test'
449+ )
450+ ) ;
451+ } ,
452+ { timeout : 60_000 , intervals : [ 2_000 ] }
437453 )
438- . fill ( 'Initial conversation thread for mention test' ) ;
454+ . toBe ( true ) ;
439455
440- await expect (
441- adminPage . locator ( '[data-testid="send-button"]' )
442- ) . toBeVisible ( ) ;
443- await expect (
444- adminPage . locator ( '[data-testid="send-button"]' )
445- ) . not . toBeDisabled ( ) ;
456+ await apiContext . dispose ( ) ;
446457
447- const postConversation = adminPage . waitForResponse (
448- ( response ) =>
449- response . url ( ) . includes ( '/api/v1/feed' ) &&
450- response . request ( ) . method ( ) === 'POST' &&
451- response . url ( ) . includes ( '/posts' )
452- ) ;
453- await adminPage . locator ( '[data-testid="send-button"]' ) . click ( ) ;
454- await postConversation ;
455- } ) ;
458+ await user1Page . getByTestId ( 'activity_feed' ) . click ( ) ;
456459
457- await test . step ( 'User1 mentions admin user in a reply' , async ( ) => {
458- await entity . visitEntityPage ( user1Page ) ;
460+ await waitForAllLoadersToDisappear ( user1Page ) ;
459461
460- await user1Page . getByTestId ( 'activity_feed' ) . click ( ) ;
462+ const seededThread = user1Page
463+ . locator ( '[data-testid="message-container"]' )
464+ . filter ( { hasText : 'Initial conversation thread for mention test' } )
465+ . first ( ) ;
466+
467+ await expect ( seededThread ) . toBeVisible ( { timeout : 30_000 } ) ;
468+ await seededThread . click ( ) ;
461469
462470 await waitForAllLoadersToDisappear ( user1Page ) ;
463471
@@ -616,15 +624,21 @@ test.describe('Mention notifications in Notification Box', () => {
616624} ) ;
617625
618626test . describe ( 'Mentions: Chinese character encoding in activity feed' , ( ) => {
619- const database = new DatabaseClass ( ) ;
620- const endpointName = `测试Endpoint- ${ uuid ( ) } ` ;
621- const apiEndpoint = new ApiEndpointClass ( undefined , endpointName ) ;
627+ let adminUser : UserClass ;
628+ let database : DatabaseClass ;
629+ let apiEndpoint : ApiEndpointClass ;
622630 let schemaFqn : string ;
623- const userName = `测试- ${ uuid ( ) } ` ;
631+ let userName : string ;
624632
625633 test . beforeAll (
626634 'Create database, schema, and user with Chinese name' ,
627635 async ( { browser } ) => {
636+ adminUser = new UserClass ( ) ;
637+ database = new DatabaseClass ( ) ;
638+ userName = `测试-${ uuid ( ) } ` ;
639+ const endpointName = `测试Endpoint-${ uuid ( ) } ` ;
640+ apiEndpoint = new ApiEndpointClass ( undefined , endpointName ) ;
641+
628642 const { apiContext, afterAction } = await performAdminLogin ( browser ) ;
629643
630644 await database . create ( apiContext ) ;
@@ -798,15 +812,15 @@ test.describe('Mentions: Chinese character encoding in activity feed', () => {
798812 const url = response . url ( ) ;
799813 return (
800814 url . includes ( '/api/v1/search/query' ) &&
801- url . includes ( encodeURIComponent ( endpointName ) )
815+ url . includes ( encodeURIComponent ( apiEndpoint . entity . name ) )
802816 ) ;
803817 } ) ;
804818
805- await editorLocator . pressSequentially ( endpointName ) ;
819+ await editorLocator . pressSequentially ( apiEndpoint . entity . name ) ;
806820 await endpointSuggestionsResponse ;
807821
808822 await page
809- . locator ( `[data-value="#apiEndpoint/${ endpointName } "]` )
823+ . locator ( `[data-value="#apiEndpoint/${ apiEndpoint . entity . name } "]` )
810824 . first ( )
811825 . click ( ) ;
812826
@@ -852,7 +866,7 @@ test.describe('Mentions: Chinese character encoding in activity feed', () => {
852866 await waitForAllLoadersToDisappear ( newPage ) ;
853867
854868 await expect ( newPage . getByTestId ( 'entity-header-display-name' ) ) . toHaveText (
855- endpointName
869+ apiEndpoint . entity . name
856870 ) ;
857871 } ) ;
858872} ) ;
0 commit comments