| | import { Page, Response } from 'playwright'; |
| | import { getCalypsoURL } from '../../data-helper'; |
| | import { reloadAndRetry } from '../../element-helper'; |
| |
|
| | type TrashedMenuItems = 'Restore' | 'Copy link' | 'Delete Permanently'; |
| | type GenericMenuItems = 'Trash'; |
| |
|
| | type MenuItems = TrashedMenuItems | GenericMenuItems; |
| | type PostsPageTabs = 'Published' | 'Drafts' | 'Scheduled' | 'Trash'; |
| |
|
| | const selectors = { |
| | |
| | addNewPostButton: 'a.page-title-action, span.split-page-title-action>a', |
| |
|
| | |
| | postRow: 'tr.type-post', |
| | postItem: ( title: string ) => |
| | `a.row-title:has-text("${ title }"), strong>span:has-text("${ title }")`, |
| |
|
| | |
| | statusItem: ( item: string ) => `ul.subsubsub a:has-text("${ item }")`, |
| |
|
| | |
| | actionItem: ( item: string ) => `.row-actions a:has-text("${ item }")`, |
| | }; |
| |
|
| | |
| | |
| | |
| | export class PostsPage { |
| | private page: Page; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | constructor( page: Page ) { |
| | this.page = page; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async visit(): Promise< Response | null > { |
| | return await this.page.goto( getCalypsoURL( 'posts' ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | async clickTab( name: PostsPageTabs ): Promise< void > { |
| | const locator = this.page.locator( selectors.statusItem( name ) ); |
| | await locator.click(); |
| | } |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | private async ensurePostShown( title: string ): Promise< void > { |
| | |
| | |
| | |
| | |
| | |
| | async function waitForPostToAppear( page: Page ): Promise< void > { |
| | const postLocator = page.locator( `${ selectors.postRow } ${ selectors.postItem( title ) }` ); |
| | await postLocator.waitFor( { state: 'visible', timeout: 20 * 1000 } ); |
| | } |
| |
|
| | await reloadAndRetry( this.page, waitForPostToAppear ); |
| | } |
| |
|
| | |
| | |
| | |
| | async newPost(): Promise< void > { |
| | const locator = this.page.locator( selectors.addNewPostButton ); |
| | await Promise.all( [ |
| | this.page.waitForNavigation( { url: /post-new.php/, timeout: 20 * 1000 } ), |
| | locator.click(), |
| | ] ); |
| | } |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | async clickPost( title: string ): Promise< void > { |
| | await this.ensurePostShown( title ); |
| |
|
| | const locator = this.page.locator( `${ selectors.postRow } ${ selectors.postItem( title ) }` ); |
| | await locator.click(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async togglePostActions( title: string ): Promise< void > { |
| | await this.ensurePostShown( title ); |
| |
|
| | const locator = this.page.locator( selectors.postRow, { |
| | has: this.page.locator( selectors.postItem( title ) ), |
| | } ); |
| | await locator.hover(); |
| | } |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | async clickActionItemForPost( { |
| | title, |
| | action, |
| | }: { |
| | title: string; |
| | action: MenuItems; |
| | } ): Promise< void > { |
| | await this.ensurePostShown( title ); |
| |
|
| | await this.togglePostActions( title ); |
| | await this.clickActionItem( title, action ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | private async clickActionItem( title: string, menuItem: string ): Promise< void > { |
| | const locator = this.page.locator( selectors.postRow, { |
| | has: this.page.locator( selectors.postItem( title ) ), |
| | } ); |
| | await locator.locator( selectors.actionItem( menuItem ) ).click(); |
| | } |
| | } |
| |
|