|
| 1 | +/*! |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +import { expect, type Locator, type Page } from "@playwright/test"; |
| 20 | +import { BasePage } from "tests/e2e/pages/BasePage"; |
| 21 | + |
| 22 | +export class DagCalendarTab extends BasePage { |
| 23 | + public readonly dailyToggle: Locator; |
| 24 | + public readonly failedToggle = this.page.getByRole("button", { name: /failed/i }); |
| 25 | + public readonly hourlyToggle: Locator; |
| 26 | + public readonly totalToggle = this.page.getByRole("button", { name: /total/i }); |
| 27 | + |
| 28 | + public get activeCells(): Locator { |
| 29 | + return this.page.locator('[data-testid="calendar-cell"][data-has-data="true"]'); |
| 30 | + } |
| 31 | + |
| 32 | + public get calendarCells(): Locator { |
| 33 | + return this.page.getByTestId("calendar-cell"); |
| 34 | + } |
| 35 | + |
| 36 | + public get tooltip(): Locator { |
| 37 | + return this.page.getByTestId("calendar-tooltip"); |
| 38 | + } |
| 39 | + |
| 40 | + public constructor(page: Page) { |
| 41 | + super(page); |
| 42 | + |
| 43 | + this.hourlyToggle = page.getByRole("button", { name: /hourly/i }); |
| 44 | + this.dailyToggle = page.getByRole("button", { name: /daily/i }); |
| 45 | + } |
| 46 | + |
| 47 | + public async getActiveCellColors(): Promise<Array<string>> { |
| 48 | + const count = await this.activeCells.count(); |
| 49 | + const colors: Array<string> = []; |
| 50 | + |
| 51 | + for (let i = 0; i < count; i++) { |
| 52 | + const cell = this.activeCells.nth(i); |
| 53 | + const bg = await cell.evaluate((el) => window.getComputedStyle(el).backgroundColor); |
| 54 | + |
| 55 | + colors.push(bg); |
| 56 | + } |
| 57 | + |
| 58 | + return colors; |
| 59 | + } |
| 60 | + |
| 61 | + public async getActiveCellCount(): Promise<number> { |
| 62 | + return this.activeCells.count(); |
| 63 | + } |
| 64 | + |
| 65 | + public async getManualRunStates(): Promise<Array<string>> { |
| 66 | + const count = await this.activeCells.count(); |
| 67 | + const states: Array<string> = []; |
| 68 | + |
| 69 | + for (let i = 0; i < count; i++) { |
| 70 | + const cell = this.activeCells.nth(i); |
| 71 | + |
| 72 | + await cell.hover(); |
| 73 | + await expect(this.tooltip).toBeVisible({ timeout: 20_000 }); |
| 74 | + |
| 75 | + const text = ((await this.tooltip.textContent()) ?? "").toLowerCase(); |
| 76 | + |
| 77 | + if (text.includes("success")) states.push("success"); |
| 78 | + if (text.includes("failed")) states.push("failed"); |
| 79 | + if (text.includes("running")) states.push("running"); |
| 80 | + } |
| 81 | + |
| 82 | + return states; |
| 83 | + } |
| 84 | + |
| 85 | + public async navigateToCalendar(dagId: string) { |
| 86 | + await this.page.goto(`/dags/${dagId}/calendar`); |
| 87 | + await this.waitForCalendarReady(); |
| 88 | + } |
| 89 | + |
| 90 | + public async switchToFailedView() { |
| 91 | + await this.failedToggle.click(); |
| 92 | + } |
| 93 | + |
| 94 | + public async switchToHourly() { |
| 95 | + await this.hourlyToggle.click(); |
| 96 | + |
| 97 | + await this.page.getByTestId("calendar-hourly-view").waitFor({ state: "visible", timeout: 30_000 }); |
| 98 | + } |
| 99 | + |
| 100 | + public async switchToTotalView() { |
| 101 | + await this.totalToggle.click(); |
| 102 | + } |
| 103 | + |
| 104 | + public async verifyMonthGridRendered() { |
| 105 | + await this.waitForCalendarReady(); |
| 106 | + } |
| 107 | + |
| 108 | + private async waitForCalendarReady(): Promise<void> { |
| 109 | + await this.page.getByTestId("dag-calendar-root").waitFor({ state: "visible", timeout: 120_000 }); |
| 110 | + |
| 111 | + await this.page.getByTestId("calendar-current-period").waitFor({ state: "visible", timeout: 120_000 }); |
| 112 | + |
| 113 | + const overlay = this.page.getByTestId("calendar-loading-overlay"); |
| 114 | + |
| 115 | + if (await overlay.isVisible().catch(() => false)) { |
| 116 | + await overlay.waitFor({ state: "hidden", timeout: 120_000 }); |
| 117 | + } |
| 118 | + |
| 119 | + await this.page.getByTestId("calendar-grid").waitFor({ state: "visible", timeout: 120_000 }); |
| 120 | + |
| 121 | + await this.page.waitForFunction(() => { |
| 122 | + const cells = document.querySelectorAll('[data-testid="calendar-cell"]'); |
| 123 | + |
| 124 | + return cells.length > 0; |
| 125 | + }); |
| 126 | + } |
| 127 | +} |
0 commit comments