-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests) add tests for server configs [WD-7703]
Signed-off-by: Mason Hu <[email protected]>
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Locator, Page } from "@playwright/test"; | ||
import { TIMEOUT } from "./constants"; | ||
|
||
export type ServerSettingType = "checkbox" | "text" | "number" | "password"; | ||
|
||
export const visitServerSettings = async (page: Page) => { | ||
await page.goto("/ui/"); | ||
await page.getByRole("link", { name: "Settings", exact: true }).click(); | ||
}; | ||
|
||
export const activateSetting = async (page: Page, settingName: string) => { | ||
await page | ||
.locator("css=tr", { hasText: settingName }) | ||
.getByRole("button") | ||
.click(); | ||
}; | ||
|
||
export const updateCheckbox = async (settingRow: Locator) => { | ||
const checkbox = settingRow.locator(".p-checkbox__label"); | ||
await checkbox.click(); | ||
}; | ||
|
||
export const checkIfChangeButtonExist = async (settingRow: Locator) => { | ||
const changeButton = settingRow.getByRole("button", { | ||
name: "Change", | ||
exact: true, | ||
}); | ||
return changeButton.isVisible({ timeout: 1000 }); | ||
}; | ||
|
||
export const updateSetting = async ( | ||
page: Page, | ||
settingName: string, | ||
settingType: ServerSettingType, | ||
content?: string, | ||
) => { | ||
const settingRow = page.locator("css=tr", { hasText: settingName }); | ||
if (settingType === "checkbox") { | ||
await updateCheckbox(settingRow); | ||
} else { | ||
const settingInput = settingRow.locator(`css=input[type=${settingType}]`); | ||
if (content) { | ||
await settingInput.fill(content); | ||
} | ||
} | ||
await settingRow.getByRole("button", { name: "Save", exact: true }).click(); | ||
await page.waitForSelector("text=Setting updated.", TIMEOUT); | ||
}; | ||
|
||
export const resetSetting = async (page: Page, settingName: string) => { | ||
const settingRow = page.locator("css=tr", { hasText: settingName }); | ||
if (await checkIfChangeButtonExist(settingRow)) { | ||
const removeButton = settingRow.getByRole("button", { | ||
name: "Remove", | ||
exact: true, | ||
}); | ||
await removeButton.click(); | ||
await page.waitForSelector("text=Setting updated.", TIMEOUT); | ||
return; | ||
} | ||
|
||
await settingRow | ||
.getByRole("button", { name: "Reset to default", exact: true }) | ||
.click(); | ||
await settingRow.getByRole("button", { name: "Save", exact: true }).click(); | ||
await page.waitForSelector("text=Setting updated.", TIMEOUT); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { test } from "@playwright/test"; | ||
import { | ||
ServerSettingType, | ||
activateSetting, | ||
resetSetting, | ||
updateSetting, | ||
visitServerSettings, | ||
} from "./helpers/server"; | ||
|
||
const settings: { | ||
settingName: string; | ||
settingType: ServerSettingType; | ||
content?: string; | ||
}[] = [ | ||
{ settingName: "acme.agree_tos", settingType: "checkbox" }, | ||
{ | ||
settingName: "acme.ca_url", | ||
settingType: "text", | ||
content: "https://acme-v02.api.letsencrypt.org/directory/test", | ||
}, | ||
{ | ||
settingName: "acme.domain", | ||
settingType: "text", | ||
content: "test.com", | ||
}, | ||
{ | ||
settingName: "acme.email", | ||
settingType: "text", | ||
content: "[email protected]", | ||
}, | ||
{ | ||
settingName: "loki.auth.password", | ||
settingType: "password", | ||
content: "abc123", | ||
}, | ||
{ | ||
settingName: "user.ui_title", | ||
settingType: "text", | ||
content: "Test User", | ||
}, | ||
]; | ||
|
||
test("test all non-critical server settings", async ({ page }) => { | ||
await visitServerSettings(page); | ||
for (const setting of settings) { | ||
// Update setting | ||
await activateSetting(page, setting.settingName); | ||
await updateSetting( | ||
page, | ||
setting.settingName, | ||
setting.settingType, | ||
setting.content, | ||
); | ||
// Reset setting | ||
await activateSetting(page, setting.settingName); | ||
await resetSetting(page, setting.settingName); | ||
} | ||
}); |