|
| 1 | +import { Page, Locator, expect } from '@playwright/test'; |
| 2 | +import { BasePage } from './BasePage'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Discover/Registry page object for browsing and installing servers |
| 6 | + */ |
| 7 | +export class RegistryPage extends BasePage { |
| 8 | + readonly heading: Locator; |
| 9 | + readonly searchInput: Locator; |
| 10 | + readonly serverGrid: Locator; |
| 11 | + readonly serverCards: Locator; |
| 12 | + readonly noResultsMessage: Locator; |
| 13 | + readonly loadingSpinner: Locator; |
| 14 | + readonly serverCount: Locator; |
| 15 | + readonly installedCount: Locator; |
| 16 | + readonly clearFiltersButton: Locator; |
| 17 | + readonly offlineBadge: Locator; |
| 18 | + readonly paginationPrev: Locator; |
| 19 | + readonly paginationNext: Locator; |
| 20 | + readonly paginationInfo: Locator; |
| 21 | + |
| 22 | + constructor(page: Page) { |
| 23 | + super(page); |
| 24 | + this.heading = page.getByRole('heading', { name: 'Discover Servers' }); |
| 25 | + this.searchInput = page.getByPlaceholder('Search servers...'); |
| 26 | + this.serverGrid = page.locator('.grid'); |
| 27 | + this.serverCards = page.locator('[class*="ServerCard"], .rounded-xl.border'); |
| 28 | + this.noResultsMessage = page.locator('text=No servers found'); |
| 29 | + this.loadingSpinner = page.locator('.animate-spin'); |
| 30 | + this.serverCount = page.locator('text=/\\d+ servers? found/'); |
| 31 | + this.installedCount = page.locator('text=/\\d+ installed/'); |
| 32 | + this.clearFiltersButton = page.getByRole('button', { name: 'Clear filters' }); |
| 33 | + this.offlineBadge = page.locator('text=Offline'); |
| 34 | + this.paginationPrev = page.locator('button:has(path[d="M15 18l-6-6 6-6"])'); |
| 35 | + this.paginationNext = page.locator('button:has(path[d="M9 18l6-6-6-6"])'); |
| 36 | + this.paginationInfo = page.locator('text=/\\d+ \\/ \\d+/'); |
| 37 | + } |
| 38 | + |
| 39 | + async search(query: string) { |
| 40 | + await this.searchInput.fill(query); |
| 41 | + // Wait for debounced search |
| 42 | + await this.page.waitForTimeout(400); |
| 43 | + } |
| 44 | + |
| 45 | + async clearSearch() { |
| 46 | + await this.searchInput.clear(); |
| 47 | + await this.page.waitForTimeout(400); |
| 48 | + } |
| 49 | + |
| 50 | + async getServerCount(): Promise<number> { |
| 51 | + const text = await this.serverCount.textContent(); |
| 52 | + const match = text?.match(/(\d+)/); |
| 53 | + return match ? parseInt(match[1], 10) : 0; |
| 54 | + } |
| 55 | + |
| 56 | + async getInstalledCount(): Promise<number> { |
| 57 | + const text = await this.installedCount.textContent(); |
| 58 | + const match = text?.match(/(\d+)/); |
| 59 | + return match ? parseInt(match[1], 10) : 0; |
| 60 | + } |
| 61 | + |
| 62 | + async selectFilter(filterName: string, optionLabel: string) { |
| 63 | + // Find the filter dropdown by nearby label or first select |
| 64 | + const filterSelects = this.page.locator('select'); |
| 65 | + const count = await filterSelects.count(); |
| 66 | + |
| 67 | + for (let i = 0; i < count; i++) { |
| 68 | + const select = filterSelects.nth(i); |
| 69 | + const options = await select.locator('option').allTextContents(); |
| 70 | + if (options.some(o => o.includes(optionLabel))) { |
| 71 | + await select.selectOption({ label: optionLabel }); |
| 72 | + return; |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + async selectSort(sortLabel: string) { |
| 78 | + const sortSelect = this.page.locator('select').last(); |
| 79 | + await sortSelect.selectOption({ label: sortLabel }); |
| 80 | + } |
| 81 | + |
| 82 | + async installServer(serverName: string) { |
| 83 | + const serverCard = this.page.locator(`text="${serverName}"`).first().locator('xpath=ancestor::div[contains(@class, "rounded")]'); |
| 84 | + await serverCard.getByRole('button', { name: /Install/i }).click(); |
| 85 | + } |
| 86 | + |
| 87 | + async uninstallServer(serverName: string) { |
| 88 | + const serverCard = this.page.locator(`text="${serverName}"`).first().locator('xpath=ancestor::div[contains(@class, "rounded")]'); |
| 89 | + await serverCard.getByRole('button', { name: /Uninstall|Remove/i }).click(); |
| 90 | + } |
| 91 | + |
| 92 | + async openServerDetails(serverName: string) { |
| 93 | + const serverCard = this.page.locator(`text="${serverName}"`).first().locator('xpath=ancestor::div[contains(@class, "rounded")]'); |
| 94 | + await serverCard.click(); |
| 95 | + } |
| 96 | + |
| 97 | + async closeServerDetails() { |
| 98 | + await this.page.keyboard.press('Escape'); |
| 99 | + } |
| 100 | + |
| 101 | + async goToNextPage() { |
| 102 | + await this.paginationNext.click(); |
| 103 | + } |
| 104 | + |
| 105 | + async goToPreviousPage() { |
| 106 | + await this.paginationPrev.click(); |
| 107 | + } |
| 108 | +} |
0 commit comments