|
|
import { Page } from 'playwright'; |
|
|
import { clickNavTab, reloadAndRetry } from '../../element-helper'; |
|
|
import { NoticeComponent } from '../components'; |
|
|
|
|
|
export type PeoplePageTabs = 'Users' | 'Followers' | 'Email Followers' | 'Invites'; |
|
|
|
|
|
const selectors = { |
|
|
|
|
|
navTabs: '.section-nav-tabs', |
|
|
navTabsDropdownOptions: '.select-dropdown__option', |
|
|
|
|
|
|
|
|
teamUser: ( username: string ) => `.people-profile:has(:text("${ username }"))`, |
|
|
clearUserButton: 'button:has-text("Clear")', |
|
|
removeUserButton: ( username: string ) => `button:has-text("Remove ${ username }")`, |
|
|
deleteConfirmBanner: ':text("Invite deleted.")', |
|
|
removeConfirmButton: '.dialog__action-buttons button:has-text("Remove")', |
|
|
removeConfirmBanner: ':text("Successfully removed")', |
|
|
|
|
|
|
|
|
addPeopleButton: 'a:text("Add a user")', |
|
|
invitePeopleButton: '.people-list-section-header__add-button', |
|
|
|
|
|
|
|
|
invitedUser: ( email: string ) => `[title="${ email }"]`, |
|
|
revokeInviteButton: 'button:text("Revoke")', |
|
|
inviteRevokedMessage: 'span:text("Invite deleted.")', |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class PeoplePage { |
|
|
private page: Page; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page ) { |
|
|
this.page = page; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async waitUntilLoaded(): Promise< void > { |
|
|
await this.page.waitForLoadState( 'load' ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickViewAllIfAvailable(): Promise< void > { |
|
|
const viewAllLink = await this.page.getByRole( 'link', { name: 'View all' } ); |
|
|
|
|
|
if ( ( await viewAllLink.count() ) > 0 ) { |
|
|
await viewAllLink.click(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickTab( name: PeoplePageTabs ): Promise< void > { |
|
|
|
|
|
if ( name === 'Invites' ) { |
|
|
await Promise.all( [ |
|
|
this.page.waitForNavigation( { url: '**/people/invites/**', waitUntil: 'networkidle' } ), |
|
|
clickNavTab( this.page, name ), |
|
|
] ); |
|
|
return; |
|
|
} |
|
|
await clickNavTab( this.page, name ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectUser( username: string ): Promise< void > { |
|
|
await Promise.all( [ |
|
|
this.page.waitForNavigation(), |
|
|
this.page.click( selectors.teamUser( username ) ), |
|
|
] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async deleteUser( username: string ): Promise< void > { |
|
|
|
|
|
const clearButton = this.page.locator( selectors.clearUserButton ); |
|
|
try { |
|
|
await clearButton.waitFor( { state: 'visible', timeout: 2000 } ); |
|
|
if ( await clearButton.isVisible() ) { |
|
|
await clearButton.click(); |
|
|
await this.page.waitForSelector( selectors.deleteConfirmBanner ); |
|
|
return; |
|
|
} |
|
|
} catch ( e ) {} |
|
|
|
|
|
|
|
|
const removeButton = this.page.locator( selectors.removeUserButton( username ) ); |
|
|
await removeButton.click(); |
|
|
await this.page.click( selectors.removeConfirmButton ); |
|
|
await this.page.waitForSelector( selectors.removeConfirmBanner ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickInviteUser(): Promise< void > { |
|
|
await this.waitUntilLoaded(); |
|
|
|
|
|
await Promise.all( [ |
|
|
this.page.waitForNavigation(), |
|
|
this.page.click( selectors.invitePeopleButton ), |
|
|
] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickAddTeamMember(): Promise< void > { |
|
|
await this.waitUntilLoaded(); |
|
|
|
|
|
await this.page.click( selectors.addPeopleButton ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async selectInvitedUser( emailAddress: string ): Promise< void > { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function waitForInviteToAppear( page: Page ): Promise< void > { |
|
|
await page.waitForSelector( selectors.invitedUser( emailAddress ), { |
|
|
timeout: 5 * 1000, |
|
|
} ); |
|
|
} |
|
|
|
|
|
await reloadAndRetry( this.page, waitForInviteToAppear ); |
|
|
|
|
|
await Promise.all( [ |
|
|
this.page.waitForNavigation(), |
|
|
this.page.click( selectors.invitedUser( emailAddress ) ), |
|
|
] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async revokeInvite(): Promise< void > { |
|
|
await this.waitUntilLoaded(); |
|
|
|
|
|
await this.page.click( selectors.revokeInviteButton ); |
|
|
|
|
|
const noticeComponent = new NoticeComponent( this.page ); |
|
|
await noticeComponent.noticeShown( 'Invite deleted' ); |
|
|
} |
|
|
} |
|
|
|