|
| 1 | +import type {Locator, Page} from '@playwright/test'; |
| 2 | + |
| 3 | +export class Sidebar { |
| 4 | + private sidebarContainer: Locator; |
| 5 | + private logoButton: Locator; |
| 6 | + private footer: Locator; |
| 7 | + private settingsButton: Locator; |
| 8 | + private documentationButton: Locator; |
| 9 | + private accountButton: Locator; |
| 10 | + private collapseButton: Locator; |
| 11 | + |
| 12 | + constructor(page: Page) { |
| 13 | + this.sidebarContainer = page.locator('.gn-aside-header__aside-content'); |
| 14 | + this.logoButton = this.sidebarContainer.locator('.gn-logo__btn-logo'); |
| 15 | + this.footer = this.sidebarContainer.locator('.gn-aside-header__footer'); |
| 16 | + |
| 17 | + // Footer buttons with specific icons |
| 18 | + const footerItems = this.sidebarContainer.locator('.gn-footer-item'); |
| 19 | + this.documentationButton = footerItems.filter({hasText: 'Documentation'}); |
| 20 | + this.settingsButton = footerItems |
| 21 | + .filter({hasText: 'Settings'}) |
| 22 | + .locator('.gn-composite-bar-item__btn-icon'); |
| 23 | + this.accountButton = footerItems.filter({hasText: 'Account'}); |
| 24 | + |
| 25 | + this.collapseButton = this.sidebarContainer.locator('.gn-collapse-button'); |
| 26 | + } |
| 27 | + |
| 28 | + async waitForSidebarToLoad() { |
| 29 | + await this.sidebarContainer.waitFor({state: 'visible'}); |
| 30 | + } |
| 31 | + |
| 32 | + async isSidebarVisible() { |
| 33 | + return this.sidebarContainer.isVisible(); |
| 34 | + } |
| 35 | + |
| 36 | + async isLogoButtonVisible() { |
| 37 | + return this.logoButton.isVisible(); |
| 38 | + } |
| 39 | + |
| 40 | + async isSettingsButtonVisible() { |
| 41 | + return this.settingsButton.isVisible(); |
| 42 | + } |
| 43 | + |
| 44 | + async isDocumentationButtonVisible() { |
| 45 | + return this.documentationButton.isVisible(); |
| 46 | + } |
| 47 | + |
| 48 | + async isAccountButtonVisible() { |
| 49 | + return this.accountButton.isVisible(); |
| 50 | + } |
| 51 | + |
| 52 | + async clickLogoButton() { |
| 53 | + await this.logoButton.click(); |
| 54 | + } |
| 55 | + |
| 56 | + async clickSettings() { |
| 57 | + await this.settingsButton.click(); |
| 58 | + } |
| 59 | + |
| 60 | + async clickDocumentation() { |
| 61 | + await this.documentationButton.click(); |
| 62 | + } |
| 63 | + |
| 64 | + async clickAccount() { |
| 65 | + await this.accountButton.click(); |
| 66 | + } |
| 67 | + |
| 68 | + async toggleCollapse() { |
| 69 | + await this.collapseButton.click(); |
| 70 | + } |
| 71 | + |
| 72 | + async isCollapsed() { |
| 73 | + const button = await this.collapseButton; |
| 74 | + const title = await button.getAttribute('title'); |
| 75 | + return title === 'Expand'; |
| 76 | + } |
| 77 | + |
| 78 | + async getFooterItemsCount(): Promise<number> { |
| 79 | + return this.footer.locator('.gn-composite-bar-item').count(); |
| 80 | + } |
| 81 | + |
| 82 | + async isFooterItemVisible(index: number) { |
| 83 | + const items = this.footer.locator('.gn-composite-bar-item'); |
| 84 | + return items.nth(index).isVisible(); |
| 85 | + } |
| 86 | + |
| 87 | + async clickFooterItem(index: number) { |
| 88 | + const items = this.footer.locator('.gn-composite-bar-item'); |
| 89 | + await items.nth(index).click(); |
| 90 | + } |
| 91 | + |
| 92 | + async getFooterItemText(index: number): Promise<string> { |
| 93 | + const items = this.footer.locator('.gn-composite-bar-item'); |
| 94 | + const item = items.nth(index); |
| 95 | + return item.locator('.gn-composite-bar-item__title-text').innerText(); |
| 96 | + } |
| 97 | +} |
0 commit comments