This is an automated email from the ASF dual-hosted git repository. imbajin pushed a commit to branch feat/oink-core-platform in repository https://gitbox.apache.org/repos/asf/hugegraph-doc.git
commit 061fbacc8f50850f6d1b8c1efbf3a70eb22ef2e8 Author: dark <[email protected]> AuthorDate: Fri Sep 4 20:43:55 2026 +0800 test(search): share ranking fixtures - load the metadata query fixture when PR-B is integrated - keep PR-A fallback cases for standalone validation - assert expected routes directly within the top three results --- tests/e2e/search-ranking.spec.js | 81 ++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/tests/e2e/search-ranking.spec.js b/tests/e2e/search-ranking.spec.js index 6c9e362ef..191dbfa05 100644 --- a/tests/e2e/search-ranking.spec.js +++ b/tests/e2e/search-ranking.spec.js @@ -1,39 +1,52 @@ const { test, expect } = require("@playwright/test"); +const fs = require("node:fs"); +const path = require("node:path"); -const CASES = { +const FALLBACK_CASES = { en: [ - ["introduction", "/docs/introduction/", "Apache HugeGraph Introduction"], - ["server", "/docs/quickstart/hugegraph/hugegraph-server/", "HugeGraph Server Quick Start"], - ["hstore", "/docs/quickstart/hugegraph/hugegraph-hstore/", "HugeGraph-Store Quick Start"], - ["placement driver", "/docs/quickstart/hugegraph/hugegraph-pd/", "HugeGraph-PD Quick Start"], - ["computer", "/docs/quickstart/computing/hugegraph-computer/", "HugeGraph-Computer Quick Start"], - ["loader", "/docs/quickstart/toolchain/hugegraph-loader/", "HugeGraph-Loader Quick Start"], - ["hubble", "/docs/quickstart/toolchain/hugegraph-hubble/", "HugeGraph-Hubble Quick Start"], - ["clients", "/docs/clients/", "Clients and APIs"], - ["rest api", "/docs/clients/restful-api/", "HugeGraph RESTful API"], - ["configuration", "/docs/config/", "HugeGraph-Server Configuration"], - ["authentication", "/docs/config/config-authentication/", "Built-in User Authentication"], - ["download", "/docs/download/download/", "Download Apache HugeGraph"] + ["introduction", "/docs/introduction/"], + ["server", "/docs/quickstart/hugegraph/hugegraph-server/"], + ["hstore", "/docs/quickstart/hugegraph/hugegraph-hstore/"], + ["placement driver", "/docs/quickstart/hugegraph/hugegraph-pd/"], + ["computer", "/docs/quickstart/computing/hugegraph-computer/"], + ["loader", "/docs/quickstart/toolchain/hugegraph-loader/"], + ["hubble", "/docs/quickstart/toolchain/hugegraph-hubble/"], + ["clients", "/docs/clients/"], + ["rest api", "/docs/clients/restful-api/"], + ["configuration", "/docs/config/"], + ["authentication", "/docs/config/config-authentication/"], + ["download", "/docs/download/download/"] ], cn: [ - ["介绍", "/cn/docs/introduction/", "Apache HugeGraph 介绍"], - ["服务端", "/cn/docs/quickstart/hugegraph/hugegraph-server/", "HugeGraph Server 快速开始"], - ["HStore", "/cn/docs/quickstart/hugegraph/hugegraph-hstore/", "HugeGraph-Store Quick Start"], - ["PD", "/cn/docs/quickstart/hugegraph/hugegraph-pd/", "HugeGraph-PD Quick Start"], - ["图计算", "/cn/docs/quickstart/computing/hugegraph-computer/", "HugeGraph-Computer Quick Start"], - ["数据导入", "/cn/docs/quickstart/toolchain/hugegraph-loader/", "HugeGraph-Loader Quick Start"], - ["图形化界面", "/cn/docs/quickstart/toolchain/hugegraph-hubble/", "HugeGraph-Hubble Quick Start"], - ["客户端", "/cn/docs/clients/", "客户端与 API"], - ["REST API", "/cn/docs/clients/restful-api/", "HugeGraph RESTful API"], - ["配置", "/cn/docs/config/", "HugeGraph-Server 配置"], - ["认证", "/cn/docs/config/config-authentication/", "HugeGraph 内置用户权限"], - ["下载", "/cn/docs/download/download/", "下载 Apache HugeGraph"] + ["介绍", "/cn/docs/introduction/"], + ["服务端", "/cn/docs/quickstart/hugegraph/hugegraph-server/"], + ["HStore", "/cn/docs/quickstart/hugegraph/hugegraph-hstore/"], + ["PD", "/cn/docs/quickstart/hugegraph/hugegraph-pd/"], + ["图计算", "/cn/docs/quickstart/computing/hugegraph-computer/"], + ["数据导入", "/cn/docs/quickstart/toolchain/hugegraph-loader/"], + ["图形化界面", "/cn/docs/quickstart/toolchain/hugegraph-hubble/"], + ["客户端", "/cn/docs/clients/"], + ["REST API", "/cn/docs/clients/restful-api/"], + ["配置", "/cn/docs/config/"], + ["认证", "/cn/docs/config/config-authentication/"], + ["下载", "/cn/docs/download/download/"] ] }; -for (const [locale, cases] of Object.entries(CASES)) { +const metadataFixture = path.resolve(__dirname, "../../scripts/fixtures/community_search_queries.json"); +const cases = fs.existsSync(metadataFixture) + ? Object.groupBy( + JSON.parse(fs.readFileSync(metadataFixture, "utf8")).map((entry) => [ + entry.query, + entry.expected_ref + ]), + ([query, expectedRef]) => (expectedRef.startsWith("/cn/") ? "cn" : "en") + ) + : FALLBACK_CASES; + +for (const [locale, localeCases] of Object.entries(cases)) { test(`summary Lunr ranks fixed ${locale} entry queries`, async ({ page }) => { - for (const [query, expectedRef, expectedTitle] of cases) { + for (const [query, expectedRef] of localeCases) { await page.goto(locale === "cn" ? "/cn/docs/" : "/docs/"); await page.locator("[data-td-shell-search-open]").first().click(); const input = page.locator(".td-shell-search__input"); @@ -43,16 +56,18 @@ for (const [locale, cases] of Object.entries(CASES)) { .first() .locator('[role="option"]'); await expect(pageResults.first(), `no Lunr results for ${query}`).toBeVisible(); - const titles = await pageResults.evaluateAll((rows) => - rows.slice(0, 3).map((row) => - row.querySelector(".td-shell-search__item-title").textContent.trim() - ) + const paths = await pageResults.evaluateAll((rows) => + rows.slice(0, 3).map((row) => new URL(row.href).pathname) ); expect( - titles.some((title) => title.includes(expectedTitle)), + paths.includes(expectedRef), `${query} must rank ${expectedRef} in the top three` ).toBe(true); - const target = pageResults.filter({ hasText: expectedTitle }).first(); + const target = page + .locator("#td-shell-search-results .td-shell-search__group") + .first() + .locator(`a[role="option"][href="${expectedRef}"]`) + .first(); await target.click(); await expect(page).toHaveURL((url) => url.pathname === expectedRef); }
