Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: fix url checks in e2e tests#12881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 8 commits intomainfromfix-e2e-url-checks
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletionssite/e2e/expectUrl.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
import { expect, type Page } from "@playwright/test";

type PollingOptions = { timeout?: number; intervals?: number[] };

export const expectUrl = expect.extend({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is so interesting. Can we keep a set of extensions and just make it some generic "expectCoder" or something?

I just wonder if we'll build up a set of these.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think having several of them would be a fine outcome personally. This sort of "scoped customexpects" is what the Playwright documentation suggests.

/**
* toHavePathName is an alternative to `toHaveURL` that won't fail if the URL contains query parameters.
*/
async toHavePathName(page: Page, expected: string, options?: PollingOptions) {
let actual: string = new URL(page.url()).pathname;
let pass: boolean;
try {
await expect
.poll(() => (actual = new URL(page.url()).pathname), options)
.toBe(expected);
pass = true;
} catch {
pass = false;
}

return {
name: "toHavePathName",
pass,
actual,
expected,
message: () => "The page does not have the expected URL pathname.",
};
},
});
3 changes: 2 additions & 1 deletionsite/e2e/global.setup.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import { expect, test } from "@playwright/test";
import { Language } from "pages/CreateUserPage/CreateUserForm";
import * as constants from "./constants";
import { expectUrl } from "./expectUrl";
import { storageState } from "./playwright.config";

test("setup deployment", async ({ page }) => {
Expand All@@ -12,7 +13,7 @@ test("setup deployment", async ({ page }) => {
await page.getByLabel(Language.passwordLabel).fill(constants.password);
await page.getByTestId("create").click();

awaitexpect(page).toHaveURL(/\/workspaces.*/);
awaitexpectUrl(page).toHavePathName("/workspaces");
await page.context().storageState({ path: storageState });

await page.getByTestId("button-select-template").isVisible();
Expand Down
37 changes: 19 additions & 18 deletionssite/e2e/helpers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@ import {
prometheusPort,
requireEnterpriseTests,
} from "./constants";
import { expectUrl } from "./expectUrl";
import {
Agent,
type App,
Expand DownExpand Up@@ -49,20 +50,18 @@ export const createWorkspace = async (
richParameters: RichParameter[] = [],
buildParameters: WorkspaceBuildParameter[] = [],
): Promise<string> => {
await page.goto("/templates/" +templateName + "/workspace", {
await page.goto(`/templates/${templateName}/workspace`, {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL("/templates/" +templateName + "/workspace");
awaitexpectUrl(page).toHavePathName(`/templates/${templateName}/workspace`);

const name = randomName();
await page.getByLabel("name").fill(name);

await fillParameters(page, richParameters, buildParameters);
await page.getByTestId("form-submit").click();

// Workaround: OutdatedAgent lands at "http://localhost:3111/@admin/8d6225b7?resources=echo_dev"
// and this is also a correct location.
await page.waitForURL(new RegExp("/@admin/" + name));
await expectUrl(page).toHavePathName("/@admin/" + name);

await page.waitForSelector("*[data-testid='build-status'] >> text=Running", {
state: "visible",
Expand All@@ -79,8 +78,8 @@ export const verifyParameters = async (
await page.goto("/@admin/" + workspaceName + "/settings/parameters", {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL(
"/@admin/" +workspaceName + "/settings/parameters",
awaitexpectUrl(page).toHavePathName(
`/@admin/${workspaceName}/settings/parameters`,
);

for (const buildParameter of expectedBuildParameters) {
Expand DownExpand Up@@ -141,7 +140,7 @@ export const createTemplate = async (
});

await page.goto("/templates/new", { waitUntil: "domcontentloaded" });
awaitexpect(page).toHaveURL("/templates/new");
awaitexpectUrl(page).toHavePathName("/templates/new");

await page.getByTestId("file-upload").setInputFiles({
buffer: await createTemplateVersionTar(responses),
Expand All@@ -151,7 +150,7 @@ export const createTemplate = async (
const name = randomName();
await page.getByLabel("Name *").fill(name);
await page.getByTestId("form-submit").click();
awaitexpect(page).toHaveURL(`/templates/${name}/files`, {
awaitexpectUrl(page).toHavePathName(`/templates/${name}/files`, {
timeout: 30000,
});
return name;
Expand All@@ -161,7 +160,7 @@ export const createTemplate = async (
// random name.
export const createGroup = async (page: Page): Promise<string> => {
await page.goto("/groups/create", { waitUntil: "domcontentloaded" });
awaitexpect(page).toHaveURL("/groups/create");
awaitexpectUrl(page).toHavePathName("/groups/create");

const name = randomName();
await page.getByLabel("Name", { exact: true }).fill(name);
Expand DownExpand Up@@ -222,7 +221,7 @@ export const stopWorkspace = async (page: Page, workspaceName: string) => {
await page.goto("/@admin/" + workspaceName, {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL("/@admin/" +workspaceName);
awaitexpectUrl(page).toHavePathName(`/@admin/${workspaceName}`);

await page.getByTestId("workspace-stop-button").click();

Expand All@@ -241,7 +240,7 @@ export const buildWorkspaceWithParameters = async (
await page.goto("/@admin/" + workspaceName, {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL("/@admin/" +workspaceName);
awaitexpectUrl(page).toHavePathName(`/@admin/${workspaceName}`);

await page.getByTestId("build-parameters-button").click();

Expand DownExpand Up@@ -753,7 +752,7 @@ export const updateTemplateSettings = async (
await page.goto(`/templates/${templateName}/settings`, {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL(`/templates/${templateName}/settings`);
awaitexpectUrl(page).toHavePathName(`/templates/${templateName}/settings`);

for (const [key, value] of Object.entries(templateSettingValues)) {
// Skip max_port_share_level for now since the frontend is not yet able to handle it
Expand All@@ -767,7 +766,7 @@ export const updateTemplateSettings = async (
await page.getByTestId("form-submit").click();

const name = templateSettingValues.name ?? templateName;
awaitexpect(page).toHaveURL(`/templates/${name}`);
awaitexpectUrl(page).toHavePathName(`/templates/${name}`);
};

export const updateWorkspace = async (
Expand All@@ -779,7 +778,7 @@ export const updateWorkspace = async (
await page.goto("/@admin/" + workspaceName, {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL("/@admin/" +workspaceName);
awaitexpectUrl(page).toHavePathName(`/@admin/${workspaceName}`);

await page.getByTestId("workspace-update-button").click();
await page.getByTestId("confirm-button").click();
Expand All@@ -801,8 +800,8 @@ export const updateWorkspaceParameters = async (
await page.goto("/@admin/" + workspaceName + "/settings/parameters", {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL(
"/@admin/" +workspaceName + "/settings/parameters",
awaitexpectUrl(page).toHavePathName(
`/@admin/${workspaceName}/settings/parameters`,
);

await fillParameters(page, richParameters, buildParameters);
Expand All@@ -827,7 +826,9 @@ export async function openTerminalWindow(
// Specify that the shell should be `bash`, to prevent inheriting a shell that
// isn't POSIX compatible, such as Fish.
const commandQuery = `?command=${encodeURIComponent("/usr/bin/env bash")}`;
await expect(terminal).toHaveURL(`/@admin/${workspaceName}.dev/terminal`);
await expectUrl(terminal).toHavePathName(
`/@admin/${workspaceName}.dev/terminal`,
);
await terminal.goto(`/@admin/${workspaceName}.dev/terminal${commandQuery}`);

return terminal;
Expand Down
5 changes: 3 additions & 2 deletionssite/e2e/tests/updateTemplate.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import { expect, test } from "@playwright/test";
import { expectUrl } from "../expectUrl";
import {
createGroup,
createTemplate,
Expand All@@ -25,7 +26,7 @@ test("add and remove a group", async ({ page }) => {
await page.goto(`/templates/${templateName}/settings/permissions`, {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL(
awaitexpectUrl(page).toHavePathName(
`/templates/${templateName}/settings/permissions`,
);

Expand DownExpand Up@@ -55,7 +56,7 @@ test("require latest version", async ({ page }) => {
await page.goto(`/templates/${templateName}/settings`, {
waitUntil: "domcontentloaded",
});
awaitexpect(page).toHaveURL(`/templates/${templateName}/settings`);
awaitexpectUrl(page).toHavePathName(`/templates/${templateName}/settings`);
let checkbox = await page.waitForSelector("#require_active_version");
await checkbox.click();
await page.getByTestId("form-submit").click();
Expand Down
1 change: 1 addition & 0 deletionssite/src/pages/CreateTokenPage/CreateTokenForm.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,6 +116,7 @@ export const CreateTokenForm: FC<CreateTokenFormProps> = ({

{lifetimeDays === "custom" && (
<TextField
data-chromatic="ignore"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Not sure what this is 🤔

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

someone let a leaky date sneak in to chromatic again, so I'm muting it 😅

type="date"
label="Expires on"
defaultValue={dayjs().add(expDays, "day").format("YYYY-MM-DD")}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp