fix: keep stock previews current and clarify member access

This commit is contained in:
leefer
2026-07-23 08:46:27 +08:00
parent 1b21350f11
commit d22a0f62a1
5 changed files with 78 additions and 21 deletions
+28 -1
View File
@@ -53,7 +53,17 @@ async function mockApplication(page, authSession = session()) {
let payload = { ok: true };
if (url.pathname === "/api/auth/me") payload = authSession;
else if (url.pathname === "/api/dashboard") payload = dashboard;
else if (url.pathname === "/api/watchlist" || url.pathname === "/api/notes") payload = { items: [] };
else if (url.pathname === "/api/stock/002141/preview") {
payload = {
meta: { trade_date: "2026-07-23", realtime: false, intraday_notice: "" },
stock: { code: "002141", name: "Test Stock", industry: "Test Sector", price: 10.8, change: 2.4 },
prices: [
{ trade_date: "2026-07-22", open: 10, high: 10.5, low: 9.9, close: 10.2, volume: 1000 },
{ trade_date: "2026-07-23", open: 10.3, high: 10.9, low: 10.2, close: 10.8, volume: 1200 },
],
intraday: [],
};
} else if (url.pathname === "/api/watchlist" || url.pathname === "/api/notes") payload = { items: [] };
else if (url.pathname === "/api/alerts") {
payload = {
items: [{
@@ -180,6 +190,23 @@ test("regular account cannot see admin controls and member features are gated",
await page.locator('[data-view="screenerView"]').first().click();
await expect(page.locator("#screenerView .member-gate")).toBeVisible();
await expect(page.locator("#screenerRunButton")).toBeDisabled();
await page.locator("#assistantButton").click();
await expect(page.locator("#settingsDialog")).toBeVisible();
await expect(page.locator("#membershipAccessNotice")).toHaveText("复盘助手仅对会员开放");
await expect(page.locator("#membershipAccessNotice")).toBeVisible();
});
test("stock hover preview ignores the selected historical date", async ({ page }) => {
await mockApplication(page, session("user", true));
await page.goto("/index.html");
await page.locator("#tradeDate").fill("2026-07-01");
const requestPromise = page.waitForRequest((request) => request.url().includes("/api/stock/002141/preview"));
await page.evaluate(() => showStockPreview("002141", document.querySelector("#globalSearchButton")));
const request = await requestPromise;
const requestUrl = new URL(request.url());
expect(requestUrl.searchParams.has("trade_date")).toBe(false);
await expect(page.locator("#stockPreviewDate")).toHaveText("2026-07-23");
await expect(page.locator("#stockPreviewName")).toHaveText("Test Stock");
});
test("mobile shell stays within the viewport", async ({ page }) => {
+15
View File
@@ -72,6 +72,21 @@ class FrontendContractTests(unittest.TestCase):
for label in prohibited:
self.assertNotIn(label, self.script)
def test_stock_hover_preview_always_uses_latest_market_context(self):
start = self.script.index("async function showStockPreview")
end = self.script.index("function renderStockPreviewLoading", start)
preview_loader = self.script[start:end]
self.assertIn('const cacheKey = `${code}:latest`;', preview_loader)
self.assertIn('/preview`', preview_loader)
self.assertNotIn("trade_date", preview_loader)
self.assertNotIn("elements.tradeDate.value", preview_loader)
def test_membership_copy_includes_review_assistant_access(self):
self.assertIn("复盘助手仅对会员开放", self.script)
self.assertIn("智能选股、问师、问天、复盘助手等智能功能", self.html)
self.assertIn("自选股、复盘记录与交易日志", self.html)
self.assertIn("每日智能分析额度", self.html)
if __name__ == "__main__":
unittest.main()