修复:区分通知加载失败与空列表
This commit is contained in:
1 parent
3d6d4deabb
commit
9b8124a4ea
3 files changed
+109
-5
No files matched your search
+21
-1
@@ -244,6 +244,7 @@ const userItems = computed(() => [
|
|||||||
const {
|
const {
|
||||||
count: unreadCount,
|
count: unreadCount,
|
||||||
recent: recentMessages,
|
recent: recentMessages,
|
||||||
|
status: mailboxStatus,
|
||||||
refresh: refreshMailbox,
|
refresh: refreshMailbox,
|
||||||
} = useMailbox();
|
} = useMailbox();
|
||||||
const mailboxOpen = ref(false);
|
const mailboxOpen = ref(false);
|
||||||
@@ -672,7 +673,26 @@ useHead(() => ({
|
|||||||
:draggable="false"
|
:draggable="false"
|
||||||
>
|
>
|
||||||
<div class="mail-pop">
|
<div class="mail-pop">
|
||||||
<div v-if="recentMessages.length" class="mail-pop-list">
|
<div
|
||||||
|
v-if="mailboxStatus === 'loading' || mailboxStatus === 'idle'"
|
||||||
|
class="mail-pop-empty"
|
||||||
|
role="status"
|
||||||
|
>
|
||||||
|
正在加载通知…
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else-if="mailboxStatus === 'error'"
|
||||||
|
class="mail-pop-empty"
|
||||||
|
role="alert"
|
||||||
|
>
|
||||||
|
<Icon name="lucide:triangle-alert" aria-hidden="true" />
|
||||||
|
<strong>通知暂时不可用</strong>
|
||||||
|
<span>加载失败,请重试</span>
|
||||||
|
<button type="button" class="mail-pop-foot" @click="refreshMailbox">
|
||||||
|
重新加载通知
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="recentMessages.length" class="mail-pop-list">
|
||||||
<button
|
<button
|
||||||
v-for="message in recentMessages"
|
v-for="message in recentMessages"
|
||||||
:key="message.id"
|
:key="message.id"
|
||||||
|
|||||||
+11
-4
@@ -7,6 +7,7 @@ function i() {
|
|||||||
let i = useState(`mail-unread-count`, () => 0),
|
let i = useState(`mail-unread-count`, () => 0),
|
||||||
a = useState(`mail-recent`, () => []),
|
a = useState(`mail-recent`, () => []),
|
||||||
o = useState(`mail-types`, () => []),
|
o = useState(`mail-types`, () => []),
|
||||||
|
status = useState(`mail-status`, () => `idle`),
|
||||||
s = useState(`mail-session`, () => null),
|
s = useState(`mail-session`, () => null),
|
||||||
c = useState(`mail-request-id`, () => 0),
|
c = useState(`mail-request-id`, () => 0),
|
||||||
l = useAuth(),
|
l = useAuth(),
|
||||||
@@ -19,31 +20,37 @@ function i() {
|
|||||||
(c.value += 1),
|
(c.value += 1),
|
||||||
(i.value = 0),
|
(i.value = 0),
|
||||||
(a.value = []),
|
(a.value = []),
|
||||||
(o.value = []));
|
(o.value = []),
|
||||||
|
(status.value = `idle`));
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
immediate: !0,
|
immediate: !0,
|
||||||
flush: `sync`,
|
flush: `sync`,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
// 接口现有摘要位于 credit_limit 字段;失败保留本会话既有摘要,不中断页面主流程。
|
// 失败可保留本会话摘要,但必须显式标为不可用;只有成功的空结果才是暂无通知。
|
||||||
async function d() {
|
async function d() {
|
||||||
if (!l.token) return;
|
if (!l.token) return;
|
||||||
let e = l.token,
|
let e = l.token,
|
||||||
t = ++c.value;
|
t = ++c.value;
|
||||||
|
status.value = `loading`;
|
||||||
try {
|
try {
|
||||||
let n = await u.get(`/client_care/mail`);
|
let n = await u.get(`/client_care/mail`);
|
||||||
if (e !== l.token || t !== c.value) return;
|
if (e !== l.token || t !== c.value) return;
|
||||||
let r = n?.credit_limit;
|
let r = n?.credit_limit;
|
||||||
((i.value = Number(r?.count ?? 0)),
|
((i.value = Number(r?.count ?? 0)),
|
||||||
(a.value = r?.list ?? []),
|
(a.value = r?.list ?? []),
|
||||||
(o.value = r?.type ?? []));
|
(o.value = r?.type ?? []),
|
||||||
} catch {}
|
(status.value = `success`));
|
||||||
|
} catch {
|
||||||
|
if (e === l.token && t === c.value) status.value = `error`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
count: i,
|
count: i,
|
||||||
recent: a,
|
recent: a,
|
||||||
types: o,
|
types: o,
|
||||||
|
status,
|
||||||
refresh: d,
|
refresh: d,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/** 通知摘要失败、加载和空结果必须在真实外壳内明确区分。 */
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { test } from "node:test";
|
||||||
|
import { backendOrigin, login, scenario } from "./helpers/console-browser.mjs";
|
||||||
|
|
||||||
|
test("Failed notification summaries expose retry instead of an empty inbox", (t) =>
|
||||||
|
scenario(t, {}, async (page) => {
|
||||||
|
let retry = false;
|
||||||
|
let release;
|
||||||
|
const pending = new Promise((resolve) => (release = resolve));
|
||||||
|
await page
|
||||||
|
.context()
|
||||||
|
.route(`${backendOrigin}/console/v1/client_care/mail`, async (route) => {
|
||||||
|
if (retry) await pending;
|
||||||
|
await route.fulfill({
|
||||||
|
json: retry
|
||||||
|
? {
|
||||||
|
status: 200,
|
||||||
|
msg: "",
|
||||||
|
data: {
|
||||||
|
credit_limit: {
|
||||||
|
count: 1,
|
||||||
|
list: [
|
||||||
|
{
|
||||||
|
id: 7,
|
||||||
|
title: "待处理通知",
|
||||||
|
read: 0,
|
||||||
|
create_time: 1700000000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
type: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: { status: 503, msg: "通知服务暂不可用", data: {} },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
await login(page);
|
||||||
|
await page.getByRole("button", { name: "查看消息", exact: true }).click();
|
||||||
|
const dialog = page.getByRole("dialog", { name: "事件通知", exact: true });
|
||||||
|
await dialog.getByRole("alert").waitFor();
|
||||||
|
assert.equal(
|
||||||
|
await dialog.getByText("暂无事件通知", { exact: true }).count(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
retry = true;
|
||||||
|
await dialog
|
||||||
|
.getByRole("button", { name: "重新加载通知", exact: true })
|
||||||
|
.click();
|
||||||
|
await dialog.getByRole("status").waitFor();
|
||||||
|
assert.equal(await dialog.getByRole("alert").count(), 0);
|
||||||
|
assert.equal(
|
||||||
|
await dialog.getByText("暂无事件通知", { exact: true }).count(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
release();
|
||||||
|
await dialog
|
||||||
|
.getByRole("button", { name: "待处理通知", exact: false })
|
||||||
|
.waitFor();
|
||||||
|
assert.equal(await dialog.getByRole("status").count(), 0);
|
||||||
|
return {
|
||||||
|
unavailableNotEmpty: true,
|
||||||
|
pendingNotEmpty: true,
|
||||||
|
explicitRetryRecovered: true,
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
|
||||||
|
test("A successful empty notification summary remains a genuine empty inbox", (t) =>
|
||||||
|
scenario(t, {}, async (page) => {
|
||||||
|
await login(page);
|
||||||
|
await page.getByRole("button", { name: "查看消息", exact: true }).click();
|
||||||
|
const dialog = page.getByRole("dialog", { name: "事件通知", exact: true });
|
||||||
|
await dialog.getByText("暂无事件通知", { exact: true }).waitFor();
|
||||||
|
assert.equal(await dialog.getByRole("alert").count(), 0);
|
||||||
|
assert.equal(await dialog.getByRole("status").count(), 0);
|
||||||
|
return { successfulEmptySummary: true, falseFailure: false };
|
||||||
|
}));
|
||||||
Reference in new issue
Block a user