|
| 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 | + private drawer: Locator; |
| 12 | + private drawerMenu: Locator; |
| 13 | + private experimentsSection: Locator; |
| 14 | + |
| 15 | + constructor(page: Page) { |
| 16 | + this.sidebarContainer = page.locator('.gn-aside-header__aside-content'); |
| 17 | + this.logoButton = this.sidebarContainer.locator('.gn-logo__btn-logo'); |
| 18 | + this.footer = this.sidebarContainer.locator('.gn-aside-header__footer'); |
| 19 | + this.drawer = page.locator('.gn-drawer'); |
| 20 | + this.drawerMenu = page.locator('.gn-settings-menu'); |
| 21 | + this.experimentsSection = this.drawerMenu |
| 22 | + .locator('.gn-settings-menu__item') |
| 23 | + .filter({hasText: 'Experiments'}); |
| 24 | + |
| 25 | + // Footer buttons with specific icons |
| 26 | + const footerItems = this.sidebarContainer.locator('.gn-footer-item'); |
| 27 | + this.documentationButton = footerItems.filter({hasText: 'Documentation'}); |
| 28 | + this.settingsButton = footerItems |
| 29 | + .filter({hasText: 'Settings'}) |
| 30 | + .locator('.gn-composite-bar-item__btn-icon'); |
| 31 | + this.accountButton = footerItems.filter({hasText: 'Account'}); |
| 32 | + |
| 33 | + this.collapseButton = this.sidebarContainer.locator('.gn-collapse-button'); |
| 34 | + } |
| 35 | + |
| 36 | + async waitForSidebarToLoad() { |
| 37 | + await this.sidebarContainer.waitFor({state: 'visible'}); |
| 38 | + } |
| 39 | + |
| 40 | + async isSidebarVisible() { |
| 41 | + return this.sidebarContainer.isVisible(); |
| 42 | + } |
| 43 | + |
| 44 | + async isLogoButtonVisible() { |
| 45 | + return this.logoButton.isVisible(); |
| 46 | + } |
| 47 | + |
| 48 | + async isSettingsButtonVisible() { |
| 49 | + return this.settingsButton.isVisible(); |
| 50 | + } |
| 51 | + |
| 52 | + async isDocumentationButtonVisible() { |
| 53 | + return this.documentationButton.isVisible(); |
| 54 | + } |
| 55 | + |
| 56 | + async isAccountButtonVisible() { |
| 57 | + return this.accountButton.isVisible(); |
| 58 | + } |
| 59 | + |
| 60 | + async clickLogoButton() { |
| 61 | + await this.logoButton.click(); |
| 62 | + } |
| 63 | + |
| 64 | + async clickSettings() { |
| 65 | + await this.settingsButton.click(); |
| 66 | + } |
| 67 | + |
| 68 | + async clickDocumentation() { |
| 69 | + await this.documentationButton.click(); |
| 70 | + } |
| 71 | + |
| 72 | + async clickAccount() { |
| 73 | + await this.accountButton.click(); |
| 74 | + } |
| 75 | + |
| 76 | + async toggleCollapse() { |
| 77 | + await this.collapseButton.click(); |
| 78 | + } |
| 79 | + |
| 80 | + async isCollapsed() { |
| 81 | + const button = await this.collapseButton; |
| 82 | + const title = await button.getAttribute('title'); |
| 83 | + return title === 'Expand'; |
| 84 | + } |
| 85 | + |
| 86 | + async getFooterItemsCount(): Promise<number> { |
| 87 | + return this.footer.locator('.gn-composite-bar-item').count(); |
| 88 | + } |
| 89 | + |
| 90 | + async isFooterItemVisible(index: number) { |
| 91 | + const items = this.footer.locator('.gn-composite-bar-item'); |
| 92 | + return items.nth(index).isVisible(); |
| 93 | + } |
| 94 | + |
| 95 | + async clickFooterItem(index: number) { |
| 96 | + const items = this.footer.locator('.gn-composite-bar-item'); |
| 97 | + await items.nth(index).click(); |
| 98 | + } |
| 99 | + |
| 100 | + async getFooterItemText(index: number): Promise<string> { |
| 101 | + const items = this.footer.locator('.gn-composite-bar-item'); |
| 102 | + const item = items.nth(index); |
| 103 | + return item.locator('.gn-composite-bar-item__title-text').innerText(); |
| 104 | + } |
| 105 | + |
| 106 | + async isDrawerVisible() { |
| 107 | + return this.drawer.isVisible(); |
| 108 | + } |
| 109 | + |
| 110 | + async getDrawerMenuItems(): Promise<string[]> { |
| 111 | + const items = this.drawerMenu.locator('.gn-settings-menu__item >> span'); |
| 112 | + const count = await items.count(); |
| 113 | + const texts: string[] = []; |
| 114 | + for (let i = 0; i < count; i++) { |
| 115 | + texts.push(await items.nth(i).innerText()); |
| 116 | + } |
| 117 | + return texts; |
| 118 | + } |
| 119 | + |
| 120 | + async clickExperimentsSection() { |
| 121 | + await this.experimentsSection.click(); |
| 122 | + } |
| 123 | + |
| 124 | + async toggleExperimentByTitle(title: string) { |
| 125 | + const experimentItem = this.drawer |
| 126 | + .locator('.gn-settings__item-title') |
| 127 | + .filter({hasText: title}); |
| 128 | + // Click the label element which wraps the switch, avoiding the slider that intercepts events |
| 129 | + const switchLabel = experimentItem.locator( |
| 130 | + 'xpath=../../..//label[contains(@class, "g-control-label")]', |
| 131 | + ); |
| 132 | + await switchLabel.click(); |
| 133 | + } |
| 134 | + |
| 135 | + async getFirstExperimentTitle(): Promise<string> { |
| 136 | + const experimentItem = this.drawer.locator('.gn-settings__item-title').first(); |
| 137 | + return experimentItem.innerText(); |
| 138 | + } |
| 139 | + |
| 140 | + async isExperimentEnabled(title: string): Promise<boolean> { |
| 141 | + const experimentItem = this.drawer |
| 142 | + .locator('.gn-settings__item-title') |
| 143 | + .filter({hasText: title}); |
| 144 | + const switchControl = experimentItem.locator('xpath=../../..//input[@type="checkbox"]'); |
| 145 | + return switchControl.isChecked(); |
| 146 | + } |
| 147 | +} |
0 commit comments