050901 非全量刷新
This commit is contained in:
@@ -401,6 +401,25 @@ async function readDocumentSessionSnapshot(page) {
|
||||
});
|
||||
}
|
||||
|
||||
async function readNoReloadProbe(page) {
|
||||
return await page.evaluate(({ primaryRootSelector, secondaryRootSelector }) => ({
|
||||
pagehideCount: Number(window.sessionStorage?.getItem("__mnoteSmokePagehideCount") || "0"),
|
||||
primaryMountId: document.querySelector(primaryRootSelector)?.getAttribute("data-runtime-mount-id") || "",
|
||||
secondaryMountId: document.querySelector(secondaryRootSelector)?.getAttribute("data-runtime-mount-id") || "",
|
||||
}), {
|
||||
primaryRootSelector: paneRootSelector("primary"),
|
||||
secondaryRootSelector: paneRootSelector("secondary"),
|
||||
});
|
||||
}
|
||||
|
||||
async function waitForDocumentPath(page, documentId) {
|
||||
await page.waitForFunction(
|
||||
(expectedDocumentId) => decodeURIComponent(window.location.pathname).endsWith(`/documents/${expectedDocumentId}`),
|
||||
documentId,
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
}
|
||||
|
||||
function countRequests(requests, startIndex, predicate) {
|
||||
return requests.slice(startIndex).filter(predicate).length;
|
||||
}
|
||||
@@ -462,15 +481,24 @@ async function runFixturePhase(page, baseUrl, requests) {
|
||||
assert.equal(fixtureSnapshot.sessions[0]?.viewCount, 2, "同文档双开时单 session 应挂两个 view");
|
||||
|
||||
const navigationIndex = requests.length;
|
||||
const beforeFixtureNavigation = await readNoReloadProbe(page);
|
||||
assert(beforeFixtureNavigation.secondaryMountId, "fixture 导航前应已挂载 secondary editor");
|
||||
await page.getByTestId("wolai-sidebar-row").filter({ hasText: "Fixture Other" }).first().click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.waitForURL((nextUrl) => decodeURIComponent(nextUrl.pathname).endsWith("/documents/doc_other"), {
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
waitUntil: "domcontentloaded",
|
||||
});
|
||||
await waitForDocumentPath(page, "doc_other");
|
||||
await waitForDualPaneReady(page);
|
||||
await waitForRequestCount(requests, navigationIndex, isTreeEventRequest, 1, "sidebar 导航后的 tree EventSource 建连");
|
||||
await page.waitForTimeout(800);
|
||||
assert.equal(countRequests(requests, navigationIndex, isTreeEventRequest), 1, "sidebar 导航后当前页面仍应只建立一条 tree EventSource");
|
||||
const afterFixtureNavigation = await readNoReloadProbe(page);
|
||||
assert.equal(
|
||||
afterFixtureNavigation.pagehideCount,
|
||||
beforeFixtureNavigation.pagehideCount,
|
||||
"fixture sidebar 导航不应触发整页 pagehide",
|
||||
);
|
||||
assert.equal(
|
||||
afterFixtureNavigation.secondaryMountId,
|
||||
beforeFixtureNavigation.secondaryMountId,
|
||||
"fixture sidebar 导航不应重挂 secondary editor",
|
||||
);
|
||||
assert.equal(countRequests(requests, navigationIndex, isTreeEventRequest), 0, "fixture sidebar 导航不应重建 tree EventSource");
|
||||
const navigatedFixtureUrl = new URL(page.url());
|
||||
assert.equal(
|
||||
navigatedFixtureUrl.searchParams.get("secondaryDocumentId"),
|
||||
@@ -496,10 +524,7 @@ async function runLocalFolderPhase(page, baseUrl, requests, fixture) {
|
||||
"不同文档双开时 session 应分别归属到两个 documentId",
|
||||
);
|
||||
await page.getByTestId("wolai-sidebar-row").filter({ hasText: "Local Third" }).first().click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.waitForURL((nextUrl) => decodeURIComponent(nextUrl.pathname).endsWith(`/documents/${fixture.thirdDocumentId}`), {
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
waitUntil: "domcontentloaded",
|
||||
});
|
||||
await waitForDocumentPath(page, fixture.thirdDocumentId);
|
||||
await waitForDualPaneReady(page);
|
||||
const navigatedUrl = new URL(page.url());
|
||||
assert.equal(
|
||||
@@ -581,12 +606,12 @@ async function runLocalFolderPhase(page, baseUrl, requests, fixture) {
|
||||
const savedMarkdown = fs.readFileSync(fixture.readmePath, "utf8");
|
||||
assert(savedMarkdown.includes(externalText), "外部写盘未落到本地 Markdown 文件");
|
||||
|
||||
const closeBefore = await readNoReloadProbe(page);
|
||||
await page.locator('[data-mnote-pane-close="secondary"]').first().click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.waitForURL((nextUrl) => !nextUrl.searchParams.has("secondaryDocumentId"), {
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
waitUntil: "commit",
|
||||
});
|
||||
await page.waitForFunction(() => !new URL(window.location.href).searchParams.has("secondaryDocumentId"), {}, { timeout: UI_TIMEOUT_MS });
|
||||
await waitForSinglePaneReady(page);
|
||||
const closeAfter = await readNoReloadProbe(page);
|
||||
assert.equal(closeAfter.pagehideCount, closeBefore.pagehideCount, "关闭 secondary 不应触发整页 pagehide");
|
||||
await page.reload({ waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
await waitForSinglePaneReady(page);
|
||||
const finalUrl = new URL(page.url());
|
||||
@@ -631,6 +656,21 @@ async function runSinglePaneTitlePhase(page, baseUrl, fixture) {
|
||||
assert.equal(afterClick.inputValue.trim(), expectedTitle, "点击标题后输入框标题不应闪成“无标题”");
|
||||
assert.equal(afterClick.metaTitle.trim(), expectedTitle, "点击标题后页头标题不应闪成“无标题”");
|
||||
assert.equal(afterClick.breadcrumbTitle.trim(), expectedTitle, "点击标题后 breadcrumb 标题不应闪成“无标题”");
|
||||
|
||||
const beforeOpenRight = await readNoReloadProbe(page);
|
||||
assert(beforeOpenRight.primaryMountId, "打开 secondary 前应已挂载 primary editor");
|
||||
await page.evaluate((documentId) => {
|
||||
window.dispatchEvent(new CustomEvent("tree.page.open-right", { detail: { documentId } }));
|
||||
}, fixture.sideDocumentId);
|
||||
await page.waitForFunction(() => new URL(window.location.href).searchParams.has("secondaryDocumentId"), {}, { timeout: UI_TIMEOUT_MS });
|
||||
await waitForDualPaneReady(page);
|
||||
const afterOpenRight = await readNoReloadProbe(page);
|
||||
assert.equal(afterOpenRight.pagehideCount, beforeOpenRight.pagehideCount, "打开 secondary 不应触发整页 pagehide");
|
||||
assert.equal(afterOpenRight.primaryMountId, beforeOpenRight.primaryMountId, "打开 secondary 不应重挂 primary editor");
|
||||
const openRightUrl = new URL(page.url());
|
||||
assert.equal(openRightUrl.searchParams.get("secondaryDocumentId"), fixture.sideDocumentId, "打开 secondary 后 URL 应写入 secondaryDocumentId");
|
||||
assert.equal(openRightUrl.searchParams.get("secondarySourceKind"), "local_folder", "打开 secondary 后 URL 应保留 secondarySourceKind");
|
||||
assert.equal(openRightUrl.searchParams.get("secondaryRootUri"), fixture.rootUri, "打开 secondary 后 URL 应保留 secondaryRootUri");
|
||||
}
|
||||
|
||||
async function main() {
|
||||
@@ -655,6 +695,13 @@ async function main() {
|
||||
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 960 }, locale: "zh-CN" });
|
||||
await context.addInitScript(() => {
|
||||
const key = "__mnoteSmokePagehideCount";
|
||||
window.addEventListener("pagehide", () => {
|
||||
const current = Number(window.sessionStorage?.getItem(key) || "0");
|
||||
window.sessionStorage?.setItem(key, String(current + 1));
|
||||
});
|
||||
});
|
||||
const page = await context.newPage();
|
||||
|
||||
page.on("request", (request) => {
|
||||
|
||||
Reference in New Issue
Block a user