| | import { Page } from 'playwright'; |
| | import { envVariables } from '../..'; |
| | import { waitForWPWidgetsIfNecessary } from '../../element-helper'; |
| |
|
| | |
| | |
| | |
| | export class CommentsComponent { |
| | private page: Page; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | constructor( page: Page ) { |
| | this.page = page; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async postComment( comment: string ): Promise< void > { |
| | const commentForm = this.page.locator( '#commentform' ); |
| | await commentForm.scrollIntoViewIfNeeded(); |
| |
|
| | let commentField; |
| | let submitButton; |
| |
|
| | if ( envVariables.TEST_ON_ATOMIC ) { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | await waitForWPWidgetsIfNecessary( this.page ); |
| |
|
| | const parentFrame = this.page.frameLocator( '#jetpack_remote_comment' ); |
| |
|
| | commentField = parentFrame.locator( '#comment' ); |
| | submitButton = parentFrame.locator( 'input:has-text("Post Comment")' ); |
| | } else { |
| | commentField = this.page.locator( '#comment' ); |
| | submitButton = this.page.locator( 'input:has-text("Post Comment")' ); |
| | } |
| |
|
| | await commentField.type( comment ); |
| |
|
| | await submitButton.click(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async like( comment: string ): Promise< void > { |
| | let likeButton; |
| | let likedStatus; |
| |
|
| | if ( envVariables.TEST_ON_ATOMIC ) { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | await waitForWPWidgetsIfNecessary( this.page ); |
| |
|
| | const likeButtonFrame = this.page |
| | .frameLocator( `iframe[name^="like-comment-frame"]:below(:text("${ comment }"))` ) |
| | .first(); |
| |
|
| | likeButton = likeButtonFrame.getByRole( 'link', { name: 'Like' } ); |
| | likedStatus = likeButtonFrame.getByRole( 'link', { name: 'Liked by you' } ); |
| | } else { |
| | const commentContent = this.page.locator( '.comment-content', { hasText: comment } ); |
| |
|
| | likeButton = commentContent.locator( ':text-is("Like"):visible' ); |
| | likedStatus = commentContent.locator( ':text("Liked by"):visible' ); |
| | } |
| |
|
| | await this.page.getByText( comment ).scrollIntoViewIfNeeded(); |
| | await likeButton.waitFor(); |
| | await likeButton.click(); |
| | |
| | if ( envVariables.TEST_ON_ATOMIC ) { |
| | await this.page.waitForTimeout( 5 * 1000 ); |
| | await likeButton.waitFor(); |
| | await likeButton.click(); |
| | } |
| | await likedStatus.waitFor(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async unlike( comment: string ): Promise< void > { |
| | let unlikeButton; |
| | let unlikedStatus; |
| |
|
| | if ( envVariables.TEST_ON_ATOMIC ) { |
| | |
| | await waitForWPWidgetsIfNecessary( this.page ); |
| |
|
| | const commentContent = this.page.locator( '.comment-content', { hasText: comment } ); |
| | const likeButtonFrame = commentContent.frameLocator( "iframe[name^='like-comment-frame']" ); |
| |
|
| | unlikeButton = likeButtonFrame.getByRole( 'link', { name: 'Liked by you' } ); |
| | unlikedStatus = likeButtonFrame.getByRole( 'link', { name: 'Like' } ); |
| | } else { |
| | const commentContent = this.page.locator( '.comment-content', { hasText: comment } ); |
| |
|
| | unlikeButton = commentContent.locator( '.comment-liked:has-text("Liked by") > a' ); |
| | unlikedStatus = commentContent.locator( '.comment-not-liked > span:text-is("Like"):visible' ); |
| | } |
| |
|
| | await this.page.getByText( comment ).scrollIntoViewIfNeeded(); |
| | await unlikeButton.click(); |
| | await unlikedStatus.waitFor(); |
| | } |
| | } |
| |
|