| | import { Page } from 'playwright'; |
| | import { getCalypsoURL } from '../../data-helper'; |
| |
|
| | const selectors = { |
| | |
| | readerCard: '.reader-post-card', |
| | streamPlaceholder: 'span.reader__placeholder-text', |
| | actionButton: ( action: 'Share' | 'Comment' ) => |
| | `.reader-post-actions__item:has-text("${ action }")`, |
| |
|
| | |
| | relatedPostsPlaceholder: '.is-placeholder', |
| | commentTextArea: '.comments__form textarea', |
| | commentSubmitButton: '.comments__form button:text("Send")', |
| | comment: ( commentText: string ) => `div:text( '${ commentText }' )`, |
| | }; |
| |
|
| | |
| | |
| | |
| | export class ReaderPage { |
| | private page: Page; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | constructor( page: Page ) { |
| | this.page = page; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async visit(): Promise< void > { |
| | await this.page.goto( getCalypsoURL( 'reader' ) ); |
| | await this.page.waitForURL( /reader/ ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | async visitPost( { index, text }: { index?: number; text?: string } = {} ): Promise< void > { |
| | |
| | |
| | await this.page.locator( selectors.streamPlaceholder ).last().waitFor( { state: 'hidden' } ); |
| |
|
| | let selector = ''; |
| |
|
| | if ( index ) { |
| | selector = `:nth-match(${ selectors.readerCard }, ${ index })`; |
| | } else if ( text ) { |
| | selector = `${ selectors.readerCard }:has-text("${ text }")`; |
| | } else { |
| | throw new Error( 'Unable to select and visit post - specify one of index or text.' ); |
| | } |
| |
|
| | await Promise.all( [ |
| | this.page.waitForURL( /reader\/feeds\/[\d]+\/posts.*/ ), |
| | this.page.click( selector ), |
| | ] ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | async comment( comment: string ): Promise< void > { |
| | |
| | await this.page.waitForSelector( selectors.relatedPostsPlaceholder, { state: 'hidden' } ); |
| |
|
| | |
| | const elementHandle = await this.page.waitForSelector( selectors.commentTextArea ); |
| | await this.page.evaluate( |
| | ( element: SVGElement | HTMLElement ) => element.scrollIntoView(), |
| | elementHandle |
| | ); |
| | await this.page.fill( selectors.commentTextArea, comment ); |
| |
|
| | await Promise.all( [ |
| | this.page.waitForResponse( |
| | ( response ) => response.status() === 200 && response.url().includes( 'new?' ) |
| | ), |
| | this.page.click( selectors.commentSubmitButton ), |
| | ] ); |
| | } |
| | } |
| |
|