docs/test(P18B-5,P18B-6): 收口资产盘点矩阵文档与回归
这个提交包含在:
@@ -0,0 +1,143 @@
|
||||
import { expect, test, type Locator, type Page } from "@playwright/test";
|
||||
|
||||
const FINANCE_MGR = { identifier: "[email protected]", password: "FinanceMgrPassword1234", name: "Finance Manager" };
|
||||
const ADMINISTRATION = { identifier: "[email protected]", password: "AdministrationPassword1234", name: "Administration" };
|
||||
|
||||
async function login(page: Page, user: { identifier: string; password: string }) {
|
||||
await page.goto("/login");
|
||||
await page.getByTestId("login-identifier").fill(user.identifier);
|
||||
await page.getByTestId("login-password").fill(user.password);
|
||||
await page.getByTestId("login-submit").click();
|
||||
await expect(page).toHaveURL(/\/dashboard/);
|
||||
}
|
||||
|
||||
async function logout(page: Page, userDisplayName: string) {
|
||||
await page.getByRole("button", { name: userDisplayName }).click();
|
||||
await page.getByRole("menuitem", { name: "退出登录" }).click();
|
||||
await expect(page).toHaveURL(/\/login/);
|
||||
}
|
||||
|
||||
|
||||
async function selectOptionByText(locator: Locator, pattern: RegExp) {
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return locator.locator("option").evaluateAll((options, rawPattern) => {
|
||||
const regexp = new RegExp(rawPattern as string);
|
||||
return options
|
||||
.map((option) => ({
|
||||
value: (option as HTMLOptionElement).value,
|
||||
label: (option as HTMLOptionElement).label,
|
||||
disabled: (option as HTMLOptionElement).disabled,
|
||||
}))
|
||||
.filter((option) => option.value && !option.disabled && regexp.test(option.label))
|
||||
.map((option) => option.value)[0] ?? "";
|
||||
}, pattern.source);
|
||||
})
|
||||
.not.toBe("");
|
||||
|
||||
const optionValue = await locator.locator("option").evaluateAll((options, rawPattern) => {
|
||||
const regexp = new RegExp(rawPattern as string);
|
||||
return options
|
||||
.map((option) => ({
|
||||
value: (option as HTMLOptionElement).value,
|
||||
label: (option as HTMLOptionElement).label,
|
||||
disabled: (option as HTMLOptionElement).disabled,
|
||||
}))
|
||||
.filter((option) => option.value && !option.disabled && regexp.test(option.label))
|
||||
.map((option) => option.value)[0] ?? "";
|
||||
}, pattern.source);
|
||||
|
||||
await locator.selectOption(optionValue);
|
||||
}
|
||||
|
||||
async function selectFirstBusinessOption(locator: Locator) {
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const optionValues = await locator.locator("option").evaluateAll((options) =>
|
||||
options
|
||||
.map((option) => ({ value: (option as HTMLOptionElement).value, disabled: (option as HTMLOptionElement).disabled }))
|
||||
.filter((option) => option.value && !option.disabled)
|
||||
.map((option) => option.value),
|
||||
);
|
||||
return optionValues[0] ?? "";
|
||||
})
|
||||
.not.toBe("");
|
||||
|
||||
const optionValues = await locator.locator("option").evaluateAll((options) =>
|
||||
options
|
||||
.map((option) => ({ value: (option as HTMLOptionElement).value, disabled: (option as HTMLOptionElement).disabled }))
|
||||
.filter((option) => option.value && !option.disabled)
|
||||
.map((option) => option.value),
|
||||
);
|
||||
|
||||
await locator.selectOption(optionValues[0]);
|
||||
}
|
||||
|
||||
test("E2E 资产流转主链路:建卡→领用归还→调拨→盘点", async ({ page }) => {
|
||||
const suffix = Date.now();
|
||||
const categoryCode = `PW_ASSET_${suffix}`;
|
||||
const categoryName = `Playwright资产分类${suffix}`;
|
||||
const assetName = `Playwright资产卡片${suffix}`;
|
||||
|
||||
await login(page, FINANCE_MGR);
|
||||
await page.getByRole("link", { name: "资产台账" }).click();
|
||||
|
||||
await page.getByTestId("asset-category-reset").click();
|
||||
await page.getByTestId("asset-category-code").fill(categoryCode);
|
||||
await page.getByTestId("asset-category-name").fill(categoryName);
|
||||
await page.getByTestId("asset-category-save").click();
|
||||
|
||||
await page.getByTestId("asset-create").click();
|
||||
await page.getByTestId("asset-name").fill(assetName);
|
||||
await page.getByTestId("asset-category").selectOption({ label: categoryName });
|
||||
await selectFirstBusinessOption(page.getByTestId("asset-legal-entity"));
|
||||
await selectFirstBusinessOption(page.getByTestId("asset-cost-center"));
|
||||
await page.getByTestId("asset-location").fill("深圳办公室 A-01");
|
||||
await page.getByTestId("asset-save").click();
|
||||
|
||||
const assetRow = page.getByTestId("asset-row").filter({ hasText: assetName }).first();
|
||||
await expect(assetRow).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
await logout(page, FINANCE_MGR.name);
|
||||
|
||||
await login(page, ADMINISTRATION);
|
||||
await page.getByRole("link", { name: "资产台账" }).click();
|
||||
await page.getByTestId("asset-row").filter({ hasText: assetName }).first().click();
|
||||
|
||||
await selectOptionByText(page.getByTestId("asset-movement-assignee"), /Employee/);
|
||||
await page.getByTestId("asset-movement-note").fill("Playwright 首次领用");
|
||||
await page.getByTestId("asset-assign-submit").click();
|
||||
await expect(page.getByText(/当前归属人:Employee/)).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
await page.getByTestId("asset-return-submit").click();
|
||||
await expect(page.getByText(/当前归属人:未分配/)).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
await selectOptionByText(page.getByTestId("asset-movement-assignee"), /Employee/);
|
||||
await page.getByTestId("asset-assign-submit").click();
|
||||
await expect(page.getByText(/当前归属人:Employee/)).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
await selectOptionByText(page.getByTestId("asset-movement-assignee"), /Finance Manager/);
|
||||
await page.getByTestId("asset-movement-location").fill("深圳办公室 B-02");
|
||||
await page.getByTestId("asset-transfer-submit").click();
|
||||
await expect(page.getByText(/当前归属人:Finance Manager/)).toBeVisible({ timeout: 30_000 });
|
||||
await expect(page.getByText(/位置:深圳办公室 B-02/)).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
await logout(page, ADMINISTRATION.name);
|
||||
|
||||
await login(page, FINANCE_MGR);
|
||||
await page.getByRole("link", { name: "资产盘点" }).click();
|
||||
await page.getByTestId("inventory-create").click();
|
||||
|
||||
const inventoryRow = page.getByTestId("inventory-row").first();
|
||||
await expect(inventoryRow).toBeVisible({ timeout: 30_000 });
|
||||
await page.getByTestId("inventory-start").click();
|
||||
await selectOptionByText(page.getByTestId("inventory-item-asset"), new RegExp(assetName));
|
||||
await page.getByTestId("inventory-item-result").selectOption("matched");
|
||||
await page.getByTestId("inventory-item-note").fill("Playwright 盘点一致");
|
||||
await page.getByTestId("inventory-item-save").click();
|
||||
await expect(page.getByRole("row").filter({ hasText: assetName }).last()).toBeVisible({ timeout: 30_000 });
|
||||
await page.getByTestId("inventory-complete").click();
|
||||
await expect(page.locator(".card-std").nth(1).getByText("已完成", { exact: true })).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
await logout(page, FINANCE_MGR.name);
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户