|
| 1 | +import { expect, type Locator, type Page } from '@playwright/test'; |
| 2 | + |
| 3 | +import { NavigationHelper } from '../utils/NavigationHelper'; |
| 4 | + |
| 5 | +export interface TopicConfig { |
| 6 | + name: string; |
| 7 | + description: string; |
| 8 | + minimumAccordions?: number; |
| 9 | +} |
| 10 | + |
| 11 | +export class OverviewPage { |
| 12 | + private readonly navigation: NavigationHelper; |
| 13 | + private readonly page: Page; |
| 14 | + |
| 15 | + constructor(page: Page) { |
| 16 | + this.page = page; |
| 17 | + this.navigation = new NavigationHelper(page); |
| 18 | + } |
| 19 | + |
| 20 | + get choosingMigrationTypeOption() { |
| 21 | + return this.page.getByText('Choosing the right migration type', { exact: true }).first(); |
| 22 | + } |
| 23 | + |
| 24 | + get closeDrawerButton() { |
| 25 | + return this.page.getByRole('button', { name: 'Close drawer panel' }); |
| 26 | + } |
| 27 | + |
| 28 | + async closeTipsAndTricks() { |
| 29 | + await expect(this.closeDrawerButton).toBeVisible(); |
| 30 | + await this.closeDrawerButton.click(); |
| 31 | + await expect(this.tipsAndTricksDrawerTitle).not.toBeVisible(); |
| 32 | + } |
| 33 | + |
| 34 | + get keyTerminologyOption() { |
| 35 | + return this.page.getByText('Key terminology', { exact: true }).first(); |
| 36 | + } |
| 37 | + |
| 38 | + get migratingVMsOption() { |
| 39 | + return this.page.getByText('Migrating your virtual machines', { exact: true }).first(); |
| 40 | + } |
| 41 | + |
| 42 | + async navigateDirectly() { |
| 43 | + await this.navigation.navigateToOverview(); |
| 44 | + await this.waitForPageLoad(); |
| 45 | + } |
| 46 | + |
| 47 | + async navigateFromMainMenu() { |
| 48 | + await this.navigation.navigateToOverview(); |
| 49 | + await this.waitForPageLoad(); |
| 50 | + } |
| 51 | + |
| 52 | + async navigateToNextTopic(currentTopicName: string, nextTopicName: string): Promise<void> { |
| 53 | + await this.page.getByRole('button', { name: currentTopicName }).first().click(); |
| 54 | + await this.page.getByRole('option', { name: nextTopicName }).click(); |
| 55 | + } |
| 56 | + |
| 57 | + async openTipsAndTricks() { |
| 58 | + await expect(this.tipsAndTricksButton).toBeVisible({ timeout: 10000 }); |
| 59 | + await this.tipsAndTricksButton.click(); |
| 60 | + await expect(this.tipsAndTricksDrawerTitle).toBeVisible({ timeout: 10000 }); |
| 61 | + } |
| 62 | + |
| 63 | + async openTipsAndTricksDrawer(): Promise<{ |
| 64 | + drawerTitle: Locator; |
| 65 | + selectTopicButton: Locator; |
| 66 | + closeDrawerButton: Locator; |
| 67 | + }> { |
| 68 | + await this.openTipsAndTricks(); |
| 69 | + |
| 70 | + await expect(this.selectTopicButton).toBeVisible(); |
| 71 | + await expect(this.closeDrawerButton).toBeVisible(); |
| 72 | + |
| 73 | + return { |
| 74 | + drawerTitle: this.tipsAndTricksDrawerTitle, |
| 75 | + selectTopicButton: this.selectTopicButton, |
| 76 | + closeDrawerButton: this.closeDrawerButton, |
| 77 | + }; |
| 78 | + } |
| 79 | + |
| 80 | + get pageTitle() { |
| 81 | + return this.page.getByRole('heading', { name: 'Migration Toolkit for Virtualization' }); |
| 82 | + } |
| 83 | + |
| 84 | + async selectTopic( |
| 85 | + topicName: 'migrating-vms' | 'migration-type' | 'troubleshooting' | 'terminology', |
| 86 | + ) { |
| 87 | + const topicMap = { |
| 88 | + 'migrating-vms': this.migratingVMsOption, |
| 89 | + 'migration-type': this.choosingMigrationTypeOption, |
| 90 | + troubleshooting: this.troubleshootingOption, |
| 91 | + terminology: this.keyTerminologyOption, |
| 92 | + }; |
| 93 | + |
| 94 | + const topic = topicMap[topicName]; |
| 95 | + await expect(topic).toBeVisible(); |
| 96 | + await topic.click(); |
| 97 | + } |
| 98 | + |
| 99 | + get selectTopicButton() { |
| 100 | + return this.page.getByRole('button', { name: 'Select a topic' }); |
| 101 | + } |
| 102 | + |
| 103 | + async selectTopicByCard(topicConfig: TopicConfig): Promise<void> { |
| 104 | + await this.page.getByTestId('topic-card').filter({ hasText: topicConfig.name }).click(); |
| 105 | + await expect( |
| 106 | + this.page.getByRole('heading', { name: topicConfig.name, level: 3 }), |
| 107 | + ).toBeVisible(); |
| 108 | + } |
| 109 | + |
| 110 | + async selectTopicByName(topicName: string): Promise<void> { |
| 111 | + await this.page.getByTestId('topic-card').filter({ hasText: topicName }).click(); |
| 112 | + await this.verifyTopicHeading(topicName); |
| 113 | + } |
| 114 | + |
| 115 | + async testAccordionsStructure(minimumCount: number): Promise<void> { |
| 116 | + const accordions = this.page.locator('.pf-v5-c-expandable-section'); |
| 117 | + await expect(accordions.first()).toBeVisible({ timeout: 10000 }); |
| 118 | + |
| 119 | + const count = await accordions.count(); |
| 120 | + expect(count).toBeGreaterThanOrEqual(minimumCount); |
| 121 | + |
| 122 | + const testCount = Math.min(3, count); |
| 123 | + for (let i = 0; i < testCount; i += 1) { |
| 124 | + const accordion = accordions.nth(i); |
| 125 | + const toggleButton = accordion.locator('button').first(); |
| 126 | + |
| 127 | + await toggleButton.scrollIntoViewIfNeeded(); |
| 128 | + await expect(toggleButton).toBeVisible(); |
| 129 | + |
| 130 | + // Expand then collapse (mimicking old behavior without state assertions) |
| 131 | + await toggleButton.click(); |
| 132 | + await toggleButton.click(); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + get tipsAndTricksButton() { |
| 137 | + return this.page.getByRole('button', { name: 'Tips and tricks' }); |
| 138 | + } |
| 139 | + |
| 140 | + get tipsAndTricksDrawerTitle() { |
| 141 | + return this.page.getByRole('heading', { name: 'Tips and tricks', level: 2 }); |
| 142 | + } |
| 143 | + |
| 144 | + get troubleshootingOption() { |
| 145 | + return this.page.getByText('Troubleshooting', { exact: true }).first(); |
| 146 | + } |
| 147 | + |
| 148 | + async verifyPicklist(topics: TopicConfig[]): Promise<void> { |
| 149 | + await this.selectTopicButton.click(); |
| 150 | + |
| 151 | + for (const topic of topics) { |
| 152 | + await expect(this.page.getByRole('option', { name: topic.name })).toBeVisible(); |
| 153 | + } |
| 154 | + |
| 155 | + await this.selectTopicButton.click(); |
| 156 | + } |
| 157 | + |
| 158 | + async verifyTopicCards(topics: TopicConfig[]): Promise<void> { |
| 159 | + for (const topic of topics) { |
| 160 | + await expect(this.page.getByText(topic.name)).toBeVisible(); |
| 161 | + await expect(this.page.getByText(topic.description)).toBeVisible(); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + async verifyTopicHeading(topicName: string): Promise<void> { |
| 166 | + await expect(this.page.getByRole('heading', { name: topicName, level: 3 })).toBeVisible(); |
| 167 | + } |
| 168 | + |
| 169 | + async waitForPageLoad() { |
| 170 | + await expect(this.pageTitle).toBeVisible({ timeout: 30000 }); |
| 171 | + } |
| 172 | +} |
0 commit comments