|
| 1 | +import type { Page } from "@playwright/test"; |
| 2 | + |
| 3 | +import { expect, test } from "../../fixtures"; |
| 4 | + |
| 5 | +const TRIGGER_NAME = "timezone_trigger"; |
| 6 | +const DEFAULT_TIMEZONE = "Etc/GMT"; |
| 7 | + |
| 8 | +async function createTrigger(page: Page, name: string, cronExpression: string, fileName: string, functionName: string) { |
| 9 | + await page.getByRole("button", { name: "Add Triggers" }).click(); |
| 10 | + await page.getByRole("textbox", { name: "Name", exact: true }).fill(name); |
| 11 | + await page.getByTestId("select-trigger-type").click(); |
| 12 | + await page.getByRole("option", { name: "Scheduler" }).click(); |
| 13 | + await page.getByRole("textbox", { name: "Cron expression" }).fill(cronExpression); |
| 14 | + await page.getByTestId("select-file").click(); |
| 15 | + await page.getByRole("option", { name: fileName }).click(); |
| 16 | + await page.getByRole("textbox", { name: "Function name" }).fill(functionName); |
| 17 | + await page.getByRole("button", { name: "Save", exact: true }).click(); |
| 18 | +} |
| 19 | + |
| 20 | +async function returnToTriggersList(page: Page) { |
| 21 | + await page.getByRole("button", { name: "Return back" }).click(); |
| 22 | +} |
| 23 | + |
| 24 | +async function hoverTriggerInfo(page: Page, triggerName: string) { |
| 25 | + await page.locator(`button[aria-label='Trigger information for "${triggerName}"']`).hover(); |
| 26 | +} |
| 27 | + |
| 28 | +async function selectTimezone(page: Page, searchTerm: string, optionName: RegExp) { |
| 29 | + await page.getByRole("combobox", { name: DEFAULT_TIMEZONE }).click(); |
| 30 | + await page.keyboard.type(searchTerm); |
| 31 | + await page.getByRole("option", { name: optionName }).click(); |
| 32 | +} |
| 33 | + |
| 34 | +test.describe("Trigger Timezone Features", () => { |
| 35 | + test.beforeEach(async ({ dashboardPage }) => { |
| 36 | + await dashboardPage.createProjectFromMenu(); |
| 37 | + }); |
| 38 | + |
| 39 | + test("Trigger shows default UTC timezone in info popover", async ({ page }) => { |
| 40 | + await createTrigger(page, TRIGGER_NAME, "5 4 * * *", "program.py", "on_trigger"); |
| 41 | + await returnToTriggersList(page); |
| 42 | + |
| 43 | + await hoverTriggerInfo(page, TRIGGER_NAME); |
| 44 | + |
| 45 | + await expect(page.getByTestId("trigger-detail-timezone")).toHaveText("UTC"); |
| 46 | + }); |
| 47 | + |
| 48 | + test("Edit trigger timezone and verify change in info popover", async ({ page }) => { |
| 49 | + await createTrigger(page, TRIGGER_NAME, "5 4 * * *", "program.py", "on_trigger"); |
| 50 | + await returnToTriggersList(page); |
| 51 | + |
| 52 | + await page.getByText(TRIGGER_NAME).click(); |
| 53 | + await selectTimezone(page, "jeru", /Jerusalem/); |
| 54 | + await page.getByRole("button", { name: "Save", exact: true }).click(); |
| 55 | + |
| 56 | + await hoverTriggerInfo(page, TRIGGER_NAME); |
| 57 | + |
| 58 | + await expect(page.getByTestId("trigger-detail-timezone")).toHaveText("Asia/Jerusalem"); |
| 59 | + }); |
| 60 | + |
| 61 | + test("Invalid timezone input retains original value", async ({ page }) => { |
| 62 | + await createTrigger(page, TRIGGER_NAME, "5 4 * * *", "program.py", "on_trigger"); |
| 63 | + |
| 64 | + await page.getByRole("combobox", { name: DEFAULT_TIMEZONE }).fill("invalid_timezone"); |
| 65 | + await page.getByRole("textbox", { name: "Cron expression" }).click(); |
| 66 | + |
| 67 | + await expect(page.getByRole("combobox", { name: DEFAULT_TIMEZONE })).toBeVisible(); |
| 68 | + }); |
| 69 | +}); |
0 commit comments