mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: fix e2e tests (#19076)
Closes https://github.com/coder/internal/issues/824
This commit is contained in:
+34
-17
@@ -127,6 +127,10 @@ export const createWorkspace = async (
|
||||
const name = randomName();
|
||||
await page.getByLabel("name").fill(name);
|
||||
|
||||
if (buildParameters.length > 0) {
|
||||
await page.waitForSelector("form", { state: "visible" });
|
||||
}
|
||||
|
||||
await fillParameters(page, richParameters, buildParameters);
|
||||
|
||||
if (useExternalAuth) {
|
||||
@@ -898,28 +902,29 @@ const fillParameters = async (
|
||||
);
|
||||
}
|
||||
|
||||
const parameterLabel = await page.waitForSelector(
|
||||
`[data-testid='parameter-field-${richParameter.name}']`,
|
||||
{ state: "visible" },
|
||||
// Use modern locator approach instead of waitForSelector
|
||||
const parameterLabel = page.getByTestId(
|
||||
`parameter-field-${richParameter.name}`,
|
||||
);
|
||||
await expect(parameterLabel).toBeVisible();
|
||||
|
||||
if (richParameter.type === "bool") {
|
||||
const parameterField = await parameterLabel.waitForSelector(
|
||||
`[data-testid='parameter-field-bool'] .MuiRadio-root input[value='${buildParameter.value}']`,
|
||||
);
|
||||
const parameterField = parameterLabel
|
||||
.getByTestId("parameter-field-bool")
|
||||
.locator(`.MuiRadio-root input[value='${buildParameter.value}']`);
|
||||
await parameterField.click();
|
||||
} else if (richParameter.options.length > 0) {
|
||||
const parameterField = await parameterLabel.waitForSelector(
|
||||
`[data-testid='parameter-field-options'] .MuiRadio-root input[value='${buildParameter.value}']`,
|
||||
);
|
||||
const parameterField = parameterLabel
|
||||
.getByTestId("parameter-field-options")
|
||||
.locator(`.MuiRadio-root input[value='${buildParameter.value}']`);
|
||||
await parameterField.click();
|
||||
} else if (richParameter.type === "list(string)") {
|
||||
throw new Error("not implemented yet"); // FIXME
|
||||
} else {
|
||||
// text or number
|
||||
const parameterField = await parameterLabel.waitForSelector(
|
||||
"[data-testid='parameter-field-text'] input",
|
||||
);
|
||||
const parameterField = parameterLabel
|
||||
.getByTestId("parameter-field-text")
|
||||
.locator("input");
|
||||
await parameterField.fill(buildParameter.value);
|
||||
}
|
||||
}
|
||||
@@ -1217,22 +1222,34 @@ export const disableDynamicParameters = async (
|
||||
waitUntil: "domcontentloaded",
|
||||
});
|
||||
|
||||
await page.waitForSelector("form", { state: "visible" });
|
||||
|
||||
// Find and uncheck the "Enable dynamic parameters" checkbox
|
||||
const dynamicParamsCheckbox = page.getByRole("checkbox", {
|
||||
name: /Enable dynamic parameters for workspace creation/,
|
||||
});
|
||||
|
||||
await dynamicParamsCheckbox.waitFor({ state: "visible" });
|
||||
|
||||
// If the checkbox is checked, uncheck it
|
||||
if (await dynamicParamsCheckbox.isChecked()) {
|
||||
await dynamicParamsCheckbox.click();
|
||||
}
|
||||
|
||||
// Save the changes
|
||||
await page.getByRole("button", { name: /save/i }).click();
|
||||
const saveButton = page.getByRole("button", { name: /save/i });
|
||||
await saveButton.waitFor({ state: "visible" });
|
||||
await saveButton.click();
|
||||
|
||||
// Wait for the success message or page to update
|
||||
await page.waitForSelector("text=Template updated successfully", {
|
||||
state: "visible",
|
||||
timeout: 10000,
|
||||
});
|
||||
await page
|
||||
.locator("[role='alert']:has-text('Template updated successfully')")
|
||||
.first()
|
||||
.waitFor({
|
||||
state: "visible",
|
||||
timeout: 15000,
|
||||
});
|
||||
|
||||
// Additional wait to ensure the changes are persisted
|
||||
await page.waitForTimeout(500);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user