11/* eslint-disable jest/expect-expect */
2- import { Page } from '@playwright/test' ;
2+ import { expect , Page } from '@playwright/test' ;
33import * as dotenv from 'dotenv' ;
44
55import selectors from './user/selectors' ;
@@ -29,7 +29,7 @@ const USER1_CHAT_VIEW_CLASSNAME = `.${user1Id}`;
2929const NEW_MESSAGE_NOTIFICATION_TEXT = 'New Messages!' as const ;
3030const LAST_REPLY_TEXT = 'Message 299' ;
3131const MESSAGES_WITH_REPLIES = [ 'Message 149' , 'Message 137' , 'Message 124' , 'Message 99' ] ;
32-
32+ const FIRST_MESSAGE_FIRST_PAGE = 'Message 125' ;
3333const QUOTED_MESSAGES = [ 'Message 99' , 'Message 137' ] ;
3434
3535const scrollInSteps = async ( user : TestingUser , msgNumbers = [ '142' , '135' , '128' ] , cycles = 3 ) => {
@@ -157,7 +157,7 @@ test.describe('scroll to the bottom', () => {
157157 test . afterEach ( async ( { controller, page } ) => {
158158 const lastMessage = await page
159159 . locator (
160- `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageList } li:last-of-type ${ selectors . messageText } ` ,
160+ `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageListContainer } li:last-of-type ${ selectors . messageText } ` ,
161161 )
162162 . textContent ( ) ;
163163 if ( ! lastMessage ) return ;
@@ -183,7 +183,7 @@ test.describe('scroll to the bottom', () => {
183183 // check that you are at the bottom
184184 await user
185185 . sees ( MessageList )
186- . isScrolledToBottom ( `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageList } ` ) ;
186+ . isScrolledToBottom ( `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageListContainer } ` ) ;
187187 } ) ;
188188
189189 test ( 'after loading more messages on new message notification click' , async ( {
@@ -196,7 +196,7 @@ test.describe('scroll to the bottom', () => {
196196
197197 // trigger load more messages
198198 const firstLoadedMessage = await page . locator (
199- `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageList } li:first-of-type` ,
199+ `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageListContainer } li:first-of-type` ,
200200 ) ;
201201 await firstLoadedMessage . scrollIntoViewIfNeeded ( ) ;
202202 await controller . sendOtherUserMessage ( ) ;
@@ -208,6 +208,48 @@ test.describe('scroll to the bottom', () => {
208208 // check that you are at the bottom
209209 await user
210210 . sees ( MessageList )
211- . isScrolledToBottom ( `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageList } ` ) ;
211+ . isScrolledToBottom ( `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageListContainer } ` ) ;
212+ } ) ;
213+ } ) ;
214+
215+ test . describe ( 'pagination' , ( ) => {
216+ test . beforeEach ( async ( { controller, user } ) => {
217+ await controller . openStory (
218+ 'navigate-long-message-lists--user1' ,
219+ selectors . channelPreviewButton ,
220+ ) ;
221+ await user . clicks ( ChannelPreview ) . text ( CHANNEL_NAME ) ;
222+ } ) ;
223+
224+ test ( 'does not lead to the viewport content change' , async ( { page, user } ) => {
225+ const messageList = await page . locator ( `${ USER1_CHAT_VIEW_CLASSNAME } ${ selectors . messageList } ` ) ;
226+
227+ const firstMessageFirstPage = await user . get ( Message ) ( FIRST_MESSAGE_FIRST_PAGE ) ;
228+
229+ let firstLoadedMessageBoxBeforePagination ;
230+ const msgListBoxBeforePagination = await messageList . boundingBox ( ) ;
231+
232+ // get message position before the next page of messages is received
233+ page . once ( 'request' , async ( ) => {
234+ firstLoadedMessageBoxBeforePagination = await firstMessageFirstPage . boundingBox ( ) ;
235+ } ) ;
236+
237+ await Promise . all ( [
238+ page . waitForResponse ( ( r ) => r . url ( ) . includes ( '/query' ) && r . ok ( ) ) ,
239+ firstMessageFirstPage . scrollIntoViewIfNeeded ( ) ,
240+ ] ) ;
241+
242+ const msgListBoxAfterPagination = await messageList . boundingBox ( ) ;
243+ const firstLoadedMessageBoxAfterPagination = await firstMessageFirstPage . boundingBox ( ) ;
244+
245+ const firstMessageShiftDistanceYToViewport =
246+ firstLoadedMessageBoxBeforePagination . y - firstLoadedMessageBoxAfterPagination . y ;
247+ expect ( firstMessageShiftDistanceYToViewport ) . toBeLessThanOrEqual (
248+ firstLoadedMessageBoxBeforePagination . height ,
249+ ) ;
250+ expect ( firstMessageShiftDistanceYToViewport ) . toBeGreaterThanOrEqual (
251+ - firstLoadedMessageBoxBeforePagination . height ,
252+ ) ;
253+ expect ( msgListBoxBeforePagination . height ) . not . toStrictEqual ( msgListBoxAfterPagination . height ) ;
212254 } ) ;
213255} ) ;
0 commit comments