Repository: apache/airflow
File: airflow-core/src/airflow/ui/tests/e2e/specs/dag-tasks.spec.ts (TypeScript)

Code before:
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
import { test, expect } from "@playwright/test";
import { DagsPage } from "tests/e2e/pages/DagsPage";

const DAG_ID = "example_bash_operator";

test.describe("Dag Tasks Tab", () => {
  test("should navigate to tasks tab and show list", async ({ page }) => {
    const dagPage = new DagsPage(page);

    await dagPage.navigateToDagTasks(DAG_ID);

    await expect(dagPage.tasksTab).toHaveAttribute("class", "active");
    await expect(dagPage.taskCards.first()).toBeVisible();
  });

  test("should search tasks by name", async ({ page }) => {
    const dagPage = new DagsPage(page);

    await dagPage.navigateToDagTasks(DAG_ID);

    await dagPage.searchBox.fill("runme_0");

    // Wait for filter to apply
    await expect(dagPage.taskCards).toHaveCount(1);
    await expect(dagPage.taskCards).toContainText("runme_0");
  });

  test("should filter tasks by operator", async ({ page }) => {
    const dagPage = new DagsPage(page);

    await dagPage.navigateToDagTasks(DAG_ID);

    await dagPage.filterByOperator("BashOperator");

    await expect(dagPage.taskCards.first()).toBeVisible();
    await expect(dagPage.taskCards.first()).toContainText("BashOperator");
  });

Review comment (bug):
Will fail if class is "active some-other-class".
We can use `await expect(page).toHaveURL(/\/tasks$/);`

Code after:
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
import { test, expect } from "@playwright/test";
import { testConfig, AUTH_FILE } from "playwright.config";
import { DagsPage } from "tests/e2e/pages/DagsPage";

test.describe("Dag Tasks Tab", () => {
  const testDagId = testConfig.testDag.id;

  test.beforeAll(async ({ browser }) => {
    test.setTimeout(7 * 60 * 1000);

    const context = await browser.newContext({ storageState: AUTH_FILE });
    const page = await context.newPage();
    const dagPage = new DagsPage(page);

    const dagRunId = await dagPage.triggerDag(testDagId);

    await dagPage.verifyDagRunStatus(testDagId, dagRunId);

    await context.close();
  });
  test("verify tasks tab displays task list", async ({ page }) => {
    const dagPage = new DagsPage(page);

    await dagPage.navigateToDagTasks(testDagId);

    await expect(page).toHaveURL(/\/tasks$/);
    await expect(dagPage.taskCards.first()).toBeVisible();

    const firstCard = dagPage.taskCards.first();

    await expect(firstCard.locator("a").first()).toBeVisible();
    await expect(firstCard).toContainText("Operator");
    await expect(firstCard).toContainText("Trigger Rule");
    await expect(firstCard).toContainText("Last Instance");
  });

  test("verify search tasks by name", async ({ page }) => {