Repository: apache/airflow
File: airflow-core/src/airflow/ui/tests/e2e/pages/BackfillPage.ts (TypeScript)

Code before:
  public getColumnHeader(columnName: string): Locator {
    return this.page.locator(`th:has-text("${columnName}")`);
  }

  public async getColumnIndexMap(): Promise<Map<string, number>> {
    const headers = this.page.locator("table thead th");

    await headers.first().waitFor({ state: "visible", timeout: 10_000 });
    const headerTexts = await headers.allTextContents();

    return new Map(headerTexts.map((text, index) => [text.trim(), index]));
  }

  public getFilterButton(): Locator {
    return this.page.locator(
      'button[aria-label*="Filter table columns"], button:has-text("Filter table columns")',
    );
  }

  public async getTableColumnCount(): Promise<number> {
    const headers = this.page.locator("table thead th");

    return await headers.count();
  }

  public async isBackfillDateErrorVisible(): Promise<boolean> {
    return this.backfillDateError.isVisible();
  }

  public async isBackfillPaused(): Promise<boolean> {
    await expect(this.pauseButton).toBeVisible({ timeout: 10_000 });
    const ariaLabel = await this.pauseButton.getAttribute("aria-label");

    return Boolean(ariaLabel?.toLowerCase().includes("unpause"));
  }

  public async navigateToBackfillsTab(dagName: string): Promise<void> {
    await this.navigateTo(BackfillPage.getBackfillsUrl(dagName));
    await expect(this.backfillsTable).toBeVisible({ timeout: 20_000 });
  }

  public async navigateToDagDetail(dagName: string): Promise<void> {
    await this.navigateTo(BackfillPage.getDagDetailUrl(dagName));
    await this.page.waitForLoadState("networkidle");
  }

  public async openBackfillDialog(): Promise<void> {
    await expect(this.triggerButton).toBeVisible({ timeout: 20_000 });
    await this.triggerButton.click();

    await expect(this.backfillModeRadio).toBeVisible({ timeout: 20_000 });

Review comment (refactor):
Lets remove this its not being used in tests. Also if needed we can use playwright isVisible() method

Code after:
  }

  public async getBackfillDetailsByDateRange(identifier: BackfillRowIdentifier): Promise<BackfillDetails> {
    const row = await this.findBackfillRowByDateRange(identifier);
    const cells = row.locator("td");
    const columnMap = await this.getColumnIndexMap();

    const fromIndex = BackfillPage.findColumnIndex(columnMap, ["From", "table.from"]);
    const toIndex = BackfillPage.findColumnIndex(columnMap, ["To", "table.to"]);
    const reprocessIndex = BackfillPage.findColumnIndex(columnMap, [
      "Reprocess Behavior",
      "backfill.reprocessBehavior",
    ]);
    const createdAtIndex = BackfillPage.findColumnIndex(columnMap, ["Created at", "table.createdAt"]);

    const [fromDate, toDate, reprocessBehavior, createdAt] = await Promise.all([
      cells.nth(fromIndex === -1 ? 0 : fromIndex).textContent(),
      cells.nth(toIndex === -1 ? 1 : toIndex).textContent(),
      cells.nth(reprocessIndex === -1 ? 2 : reprocessIndex).textContent(),
      cells.nth(createdAtIndex === -1 ? 3 : createdAtIndex).textContent(),
    ]);

    return {
      createdAt: (createdAt ?? "").trim(),
      fromDate: (fromDate ?? "").trim(),
      reprocessBehavior: (reprocessBehavior ?? "").trim(),
      toDate: (toDate ?? "").trim(),
    };
  }

  public async getBackfillsTableRows(): Promise<number> {
    const rows = this.page.locator("table tbody tr");

    try {
      await rows.first().waitFor({ state: "visible", timeout: 5000 });
    } catch {
      return 0;
    }

    return await rows.count();
  }

  public async getBackfillStatus(rowIndex: number = 0): Promise<string> {
    const row = this.page.locator("table tbody tr").nth(rowIndex);

    await expect(row).toBeVisible({ timeout: 10_000 });

    const headers = this.page.locator("table thead th");
    const headerTexts = await headers.allTextContents();
    const completedAtIndex = headerTexts.findIndex((text) => text.toLowerCase().includes("completed"));