@celestia-island/hikari 0.55.391 → 0.55.392
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/HkNotificationBell.barrel.test.ts +27 -0
- package/src/components/HkNotificationBell.contract.test.ts +66 -0
- package/src/components/HkNotificationBell.scss +199 -0
- package/src/components/HkNotificationBell.test.tsx +240 -0
- package/src/components/HkNotificationBell.tsx +212 -0
- package/src/i18n/locales/ar/components.json +7 -1
- package/src/i18n/locales/de/components.json +7 -1
- package/src/i18n/locales/en/components.json +7 -1
- package/src/i18n/locales/es/components.json +7 -1
- package/src/i18n/locales/fr/components.json +7 -1
- package/src/i18n/locales/ja/components.json +7 -1
- package/src/i18n/locales/ko/components.json +7 -1
- package/src/i18n/locales/pt/components.json +7 -1
- package/src/i18n/locales/ru/components.json +7 -1
- package/src/i18n/locales/zh-Hans/components.json +7 -1
- package/src/i18n/locales/zh-Hant/components.json +7 -1
- package/src/index.ts +14 -0
- package/src/runtime/emergencyJournal.test.ts +144 -0
- package/src/runtime/index.ts +14 -0
- package/src/runtime/notificationCenter.test.ts +229 -0
- package/src/runtime/notificationCenter.ts +367 -0
- package/src/runtime/toastJournal.test.ts +145 -0
- package/src/runtime/useBlockingToast.ts +32 -1
- package/src/runtime/useEmergencyAlert.ts +47 -3
- package/src/runtime/useToast.ts +74 -6
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as barrel from "../index";
|
|
3
|
+
import { asIndexable } from "../utils/typing";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The public barrel guard (HkAddTile.barrel.test.ts shape): deleting
|
|
7
|
+
* the export lines from index.ts kept the ENTIRE suite green while the
|
|
8
|
+
* component's own tests reach the module through "./HkNotificationBell"
|
|
9
|
+
* — only an external consumer would have noticed.
|
|
10
|
+
*/
|
|
11
|
+
describe("the public barrel", () => {
|
|
12
|
+
it("exports the bell under both family names", () => {
|
|
13
|
+
const hk = asIndexable(barrel.HkNotificationBell);
|
|
14
|
+
expect(hk, "HkNotificationBell must be re-exported").toBeTruthy();
|
|
15
|
+
expect(hk.name).toBe("HkNotificationBell");
|
|
16
|
+
// The H- alias rides the HCard/HkCard family convention: consumers
|
|
17
|
+
// import either name, one component underneath.
|
|
18
|
+
expect(barrel.HNotificationBell).toBe(barrel.HkNotificationBell);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("exports the journal context surface", () => {
|
|
22
|
+
expect(typeof (barrel as Record<string, unknown>).useNotificationCenter).toBe("function");
|
|
23
|
+
expect(typeof (barrel as Record<string, unknown>).recordNotification).toBe("function");
|
|
24
|
+
expect(typeof (barrel as Record<string, unknown>).markAllNotificationsRead).toBe("function");
|
|
25
|
+
expect((barrel as Record<string, unknown>).MAX_NOTIFICATION_ENTRIES).toBe(100);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import componentSource from "./HkNotificationBell.tsx?raw";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Composition contract for the notification bell (the
|
|
7
|
+
* HEmergencySnoozeTray.contract.test.ts shape): read the component's
|
|
8
|
+
* own source and pin the structural decisions that make the bell ONE
|
|
9
|
+
* grammar with the rest of the chrome — deviations here are exactly
|
|
10
|
+
* how a second notification UI grows next to the first one.
|
|
11
|
+
*/
|
|
12
|
+
function body(): string {
|
|
13
|
+
// Strip comments so prose can never satisfy a contract.
|
|
14
|
+
return componentSource.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("HkNotificationBell composition contract", () => {
|
|
18
|
+
it("the surface IS HkPopover with sheetOnMobile — no bespoke popup markup", () => {
|
|
19
|
+
const src = body();
|
|
20
|
+
expect(src).toContain("HkPopover");
|
|
21
|
+
expect(src).toContain("sheetOnMobile");
|
|
22
|
+
// No hand-rolled overlay/teleport/scrim in this component.
|
|
23
|
+
expect(src).not.toContain("Teleport");
|
|
24
|
+
expect(src).not.toContain("ensureOverlayRoot");
|
|
25
|
+
expect(src).not.toContain("scrim");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("the trigger IS HkIconButton on the chrome ladder", () => {
|
|
29
|
+
const src = body();
|
|
30
|
+
expect(src).toContain("HkIconButton");
|
|
31
|
+
expect(src).toContain("useChromeActionSize");
|
|
32
|
+
// The unread mark is the button's OWN dot (2026-10-28 ruling), not
|
|
33
|
+
// a wrapper badge around the trigger.
|
|
34
|
+
expect(src).toContain("dot=");
|
|
35
|
+
expect(src).toContain("dotLabel");
|
|
36
|
+
expect(src).not.toContain("HkCornerBadge");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("open IS the read receipt — markAllRead rides the open flag", () => {
|
|
40
|
+
const src = body();
|
|
41
|
+
expect(src).toContain("markAllRead");
|
|
42
|
+
expect(src).toContain("watch(open");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("restore is REPLAY-FREE except the entry's own resummon path", () => {
|
|
46
|
+
const src = body();
|
|
47
|
+
// The only action a row may fire is the journal-carried callback,
|
|
48
|
+
// gated on the SNOOZED state (an on-screen band has nothing to
|
|
49
|
+
// restore — R2 finding, PR #1322).
|
|
50
|
+
expect(src).toContain("onResummon?.()");
|
|
51
|
+
expect(src).toContain('entry.state === "snoozed"');
|
|
52
|
+
// No direct emergency/toast import here — resummon must ride the
|
|
53
|
+
// journal entry, or replay semantics would fork.
|
|
54
|
+
expect(src).not.toContain("useEmergencyAlert");
|
|
55
|
+
expect(src).not.toContain("unsnoozeEmergencyAlert");
|
|
56
|
+
expect(src).not.toContain("useToast");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("the journal is the ONLY data source", () => {
|
|
60
|
+
const src = body();
|
|
61
|
+
expect(src).toContain("useNotificationCenter");
|
|
62
|
+
// No private storage reading — persistence belongs to the context.
|
|
63
|
+
expect(src).not.toContain("sessionStorage");
|
|
64
|
+
expect(src).not.toContain("localStorage");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HkNotificationBell chrome: the bell wrapper and the notification-
|
|
3
|
+
* center panel body. Tone colors reuse the badge/status channels the
|
|
4
|
+
* toast family already speaks (HkToast's --hi-color-* family) so a
|
|
5
|
+
* journal row reads as the same grammar as the surface it records;
|
|
6
|
+
* layout is deliberately plain flex/flow — the popup chrome (glass,
|
|
7
|
+
* scroll, sheet band) is HkPopover's job, not ours.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
.hk-notification-bell {
|
|
11
|
+
position: relative;
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Panel body: the list is the popup's ONE scroll surface (the
|
|
17
|
+
* single-scroll contract — never a nested pane inside it). */
|
|
18
|
+
.hk-notification-center {
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
width: min(22rem, 100%);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.hk-notification-center__list {
|
|
25
|
+
list-style: none;
|
|
26
|
+
margin: 0;
|
|
27
|
+
padding: 0;
|
|
28
|
+
max-height: min(24rem, 55vh);
|
|
29
|
+
overflow-y: auto;
|
|
30
|
+
overscroll-behavior: contain;
|
|
31
|
+
/* Native-scrollbar invariant (nativeScrollbar.contract.test.ts): the
|
|
32
|
+
list keeps native overflow mechanics, the platform bar never
|
|
33
|
+
paints — overlay scrollbars ride the popup chrome instead. */
|
|
34
|
+
scrollbar-width: none;
|
|
35
|
+
|
|
36
|
+
&::-webkit-scrollbar {
|
|
37
|
+
display: none;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Mobile sheet branch (R2 finding, PR #1322): HkPopover's own sheet
|
|
41
|
+
panel is the scroller there, so the list must NOT become a second,
|
|
42
|
+
contained scroll surface — a drag inside the list would never hand
|
|
43
|
+
off to the sheet, stranding the Clear-all foot on short viewports.
|
|
44
|
+
The sheet shows the whole list; its panel scrolls. */
|
|
45
|
+
.hk-is-sheet & {
|
|
46
|
+
max-height: none;
|
|
47
|
+
overflow-y: visible;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.hk-notification-center__empty {
|
|
52
|
+
margin: 0;
|
|
53
|
+
padding: var(--space-12, 0.75rem) var(--space-8, 0.5rem);
|
|
54
|
+
color: rgb(var(--color-text) / 55%);
|
|
55
|
+
font-size: 0.8125rem;
|
|
56
|
+
text-align: center;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.hk-notification-center__foot {
|
|
60
|
+
display: flex;
|
|
61
|
+
justify-content: flex-end;
|
|
62
|
+
padding-top: var(--space-8, 0.5rem);
|
|
63
|
+
border-top: 1px solid rgb(var(--color-border) / 10%);
|
|
64
|
+
margin-top: var(--space-8, 0.5rem);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.hk-notification-center__clear {
|
|
68
|
+
appearance: none;
|
|
69
|
+
background: none;
|
|
70
|
+
border: none;
|
|
71
|
+
padding: 0 var(--space-4, 0.25rem);
|
|
72
|
+
color: rgb(var(--color-text) / 55%);
|
|
73
|
+
font-size: 0.75rem;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
|
|
76
|
+
&:hover {
|
|
77
|
+
color: rgb(var(--color-text) / 85%);
|
|
78
|
+
text-decoration: underline;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* ── rows ─────────────────────────────────────────────────────────── */
|
|
83
|
+
|
|
84
|
+
.hk-notification-row {
|
|
85
|
+
display: flex;
|
|
86
|
+
gap: var(--space-8, 0.5rem);
|
|
87
|
+
padding: var(--space-8, 0.5rem) var(--space-8, 0.5rem);
|
|
88
|
+
border-bottom: 1px solid rgb(var(--color-border) / 6%);
|
|
89
|
+
|
|
90
|
+
&:last-child {
|
|
91
|
+
border-bottom: none;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.hk-notification-row__icon {
|
|
96
|
+
flex: none;
|
|
97
|
+
display: inline-flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
padding-top: 2px;
|
|
100
|
+
/* Tone ink follows the row's tone class (rules below). */
|
|
101
|
+
color: rgb(var(--color-text) / 65%);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Tone ink on the glyph (the toast family's own --hi-color-<tone>
|
|
105
|
+
channels, theme-following; fallbacks are the tokenInventory-canonical
|
|
106
|
+
literals, NOT the toast family's sheet-local ones). */
|
|
107
|
+
.hk-notification-row.is-error .hk-notification-row__icon {
|
|
108
|
+
color: var(--hi-color-danger, #f7768e);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.hk-notification-row.is-warning .hk-notification-row__icon {
|
|
112
|
+
color: var(--hi-color-warning, #eed677);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.hk-notification-row.is-success .hk-notification-row__icon {
|
|
116
|
+
color: var(--hi-color-success, #0eb840);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.hk-notification-row.is-info .hk-notification-row__icon,
|
|
120
|
+
.hk-notification-row.is-loading .hk-notification-row__icon {
|
|
121
|
+
color: rgb(var(--color-text) / 65%);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.hk-notification-row__body {
|
|
125
|
+
flex: 1 1 auto;
|
|
126
|
+
min-width: 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.hk-notification-row__top {
|
|
130
|
+
display: flex;
|
|
131
|
+
align-items: baseline;
|
|
132
|
+
gap: var(--space-8, 0.5rem);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.hk-notification-row__title {
|
|
136
|
+
flex: 1 1 auto;
|
|
137
|
+
min-width: 0;
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
text-overflow: ellipsis;
|
|
140
|
+
white-space: nowrap;
|
|
141
|
+
font-size: 0.8125rem;
|
|
142
|
+
color: rgb(var(--color-text) / 92%);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.hk-notification-row__time {
|
|
146
|
+
flex: none;
|
|
147
|
+
font-size: 0.6875rem;
|
|
148
|
+
font-variant-numeric: tabular-nums;
|
|
149
|
+
color: rgb(var(--color-text) / 45%);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.hk-notification-row__detail {
|
|
153
|
+
margin: 2px 0 0;
|
|
154
|
+
display: flex;
|
|
155
|
+
align-items: center;
|
|
156
|
+
gap: var(--space-4, 0.25rem);
|
|
157
|
+
overflow: hidden;
|
|
158
|
+
white-space: nowrap;
|
|
159
|
+
font-size: 0.75rem;
|
|
160
|
+
color: rgb(var(--color-text) / 55%);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.hk-notification-row__detail-text {
|
|
164
|
+
overflow: hidden;
|
|
165
|
+
text-overflow: ellipsis;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.hk-notification-row__code {
|
|
169
|
+
flex: none;
|
|
170
|
+
font-family: var(--font-mono, ui-monospace, monospace);
|
|
171
|
+
font-size: 0.6875rem;
|
|
172
|
+
padding: 0 4px;
|
|
173
|
+
border: 1px solid rgb(var(--color-border) / 25%);
|
|
174
|
+
border-radius: 4px;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.hk-notification-row__meta {
|
|
178
|
+
display: flex;
|
|
179
|
+
align-items: center;
|
|
180
|
+
gap: var(--space-8, 0.5rem);
|
|
181
|
+
margin-top: 2px;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.hk-notification-row__state {
|
|
185
|
+
font-size: 0.6875rem;
|
|
186
|
+
color: rgb(var(--color-text) / 45%);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.hk-notification-row__restore {
|
|
190
|
+
appearance: none;
|
|
191
|
+
background: none;
|
|
192
|
+
border: none;
|
|
193
|
+
padding: 0;
|
|
194
|
+
font-size: 0.75rem;
|
|
195
|
+
color: rgb(var(--color-primary, var(--color-text)) / 90%);
|
|
196
|
+
cursor: pointer;
|
|
197
|
+
text-decoration: underline;
|
|
198
|
+
text-underline-offset: 2px;
|
|
199
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createApp, h, nextTick } from "vue";
|
|
3
|
+
|
|
4
|
+
import HkNotificationBell from "./HkNotificationBell";
|
|
5
|
+
import { recordNotification, resetNotifications, useNotificationCenter } from "../runtime/notificationCenter";
|
|
6
|
+
import { raiseEmergencyAlert, resetEmergencyAlerts, snoozeEmergencyAlert } from "../runtime/useEmergencyAlert";
|
|
7
|
+
import { setLocale } from "../i18n/context";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* HkNotificationBell behavior tests:
|
|
11
|
+
* - the bell renders an icon button with the notification aria label
|
|
12
|
+
* - an unread journal lights the button's own dot (with its label)
|
|
13
|
+
* - clicking the bell opens the panel (HkPopover panel mounts) and
|
|
14
|
+
* opening IS the read receipt (dot goes dark)
|
|
15
|
+
* - rows render title / time / detail / code chip
|
|
16
|
+
* - a snoozed emergency entry shows the Hidden state chip and its
|
|
17
|
+
* restore button unsnoozes through the journal's resummon path
|
|
18
|
+
* - Clear all empties the journal
|
|
19
|
+
*
|
|
20
|
+
* (Repo test convention: raw createApp + document queries, no
|
|
21
|
+
* @vue/test-utils dependency.)
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
25
|
+
|
|
26
|
+
function mountBell() {
|
|
27
|
+
const container = document.createElement("div");
|
|
28
|
+
document.body.appendChild(container);
|
|
29
|
+
const app = createApp({ render: () => h(HkNotificationBell) });
|
|
30
|
+
mounts.push({ app, container });
|
|
31
|
+
app.mount(container);
|
|
32
|
+
return container;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function settle() {
|
|
36
|
+
await nextTick();
|
|
37
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
38
|
+
await nextTick();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function bellButton(): HTMLButtonElement {
|
|
42
|
+
return document.querySelector<HTMLButtonElement>(".hk-notification-bell .hk-icon-button")!;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function panel(): HTMLElement | null {
|
|
46
|
+
return document.querySelector<HTMLElement>(".hk-notification-center");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function rows(): HTMLElement[] {
|
|
50
|
+
return Array.from(document.querySelectorAll<HTMLElement>(".hk-notification-row"));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
for (const { app, container } of mounts) {
|
|
55
|
+
app.unmount();
|
|
56
|
+
container.remove();
|
|
57
|
+
}
|
|
58
|
+
mounts.length = 0;
|
|
59
|
+
document.body
|
|
60
|
+
.querySelectorAll(".hk-popover-scrim, .hk-popover-panel")
|
|
61
|
+
.forEach((el) => el.remove());
|
|
62
|
+
resetNotifications();
|
|
63
|
+
resetEmergencyAlerts();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("bell trigger", () => {
|
|
67
|
+
it("renders the bell with the notification label", async () => {
|
|
68
|
+
await setLocale("zh-Hans");
|
|
69
|
+
mountBell();
|
|
70
|
+
await settle();
|
|
71
|
+
expect(bellButton().getAttribute("aria-label")).toBe("通知中心");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("an unread journal lights the button's own dot; open clears it", async () => {
|
|
75
|
+
await setLocale("en");
|
|
76
|
+
recordNotification({ id: "t1", kind: "toast", tone: "error", title: "boom" });
|
|
77
|
+
mountBell();
|
|
78
|
+
await settle();
|
|
79
|
+
const btn = bellButton();
|
|
80
|
+
expect(btn.querySelector(".hk-icon-button-dot")).toBeTruthy();
|
|
81
|
+
|
|
82
|
+
btn.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
83
|
+
await settle();
|
|
84
|
+
expect(panel()).toBeTruthy();
|
|
85
|
+
await settle();
|
|
86
|
+
// Opening IS the read receipt — the dot is gone while the panel is open.
|
|
87
|
+
expect(btn.querySelector(".hk-icon-button-dot")).toBeFalsy();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("an empty journal shows the empty state", async () => {
|
|
91
|
+
await setLocale("en");
|
|
92
|
+
mountBell();
|
|
93
|
+
await settle();
|
|
94
|
+
bellButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
95
|
+
await settle();
|
|
96
|
+
expect(document.querySelector(".hk-notification-center__empty")?.textContent).toBe(
|
|
97
|
+
"No notifications yet",
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("panel rows", () => {
|
|
103
|
+
it("renders title, time, detail and code chip", async () => {
|
|
104
|
+
await setLocale("en");
|
|
105
|
+
recordNotification({
|
|
106
|
+
id: "emergency:quota",
|
|
107
|
+
kind: "emergency",
|
|
108
|
+
tone: "warning",
|
|
109
|
+
title: "可用额度已用完",
|
|
110
|
+
detail: "充值后立即可用",
|
|
111
|
+
code: "QUOTA_EXHAUSTED",
|
|
112
|
+
});
|
|
113
|
+
mountBell();
|
|
114
|
+
await settle();
|
|
115
|
+
bellButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
116
|
+
await settle();
|
|
117
|
+
expect(rows()).toHaveLength(1);
|
|
118
|
+
const row = rows()[0];
|
|
119
|
+
expect(row.querySelector(".hk-notification-row__title")?.textContent).toBe("可用额度已用完");
|
|
120
|
+
expect(row.querySelector(".hk-notification-row__detail-text")?.textContent).toBe("充值后立即可用");
|
|
121
|
+
expect(row.querySelector(".hk-notification-row__code")?.textContent).toBe("QUOTA_EXHAUSTED");
|
|
122
|
+
expect(row.querySelector(".hk-notification-row__time")).toBeTruthy();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("a snoozed emergency shows Hidden + a working restore button", async () => {
|
|
126
|
+
await setLocale("en");
|
|
127
|
+
raiseEmergencyAlert({ id: "quota", severity: "warning", title: "quota out" });
|
|
128
|
+
snoozeEmergencyAlert("quota");
|
|
129
|
+
mountBell();
|
|
130
|
+
await settle();
|
|
131
|
+
bellButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
132
|
+
await settle();
|
|
133
|
+
const row = rows()[0];
|
|
134
|
+
expect(row.classList.contains("is-snoozed")).toBe(true);
|
|
135
|
+
expect(row.querySelector(".hk-notification-row__state")?.textContent).toBe("Hidden");
|
|
136
|
+
const restore = row.querySelector<HTMLButtonElement>(".hk-notification-row__restore");
|
|
137
|
+
expect(restore?.textContent).toBe("Show again");
|
|
138
|
+
restore!.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
139
|
+
await settle();
|
|
140
|
+
// The band is live again and the record follows — and the restore
|
|
141
|
+
// button is GONE (R2 finding: no dead control on an active band).
|
|
142
|
+
expect(row.classList.contains("is-active")).toBe(true);
|
|
143
|
+
expect(row.querySelector(".hk-notification-row__restore")).toBeFalsy();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("an ACTIVE emergency row (band on screen) shows no restore button", async () => {
|
|
147
|
+
await setLocale("en");
|
|
148
|
+
raiseEmergencyAlert({ id: "quota", severity: "warning", title: "quota out" });
|
|
149
|
+
mountBell();
|
|
150
|
+
await settle();
|
|
151
|
+
bellButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
152
|
+
await settle();
|
|
153
|
+
const row = rows()[0];
|
|
154
|
+
expect(row.classList.contains("is-active")).toBe(true);
|
|
155
|
+
expect(row.querySelector(".hk-notification-row__restore")).toBeFalsy();
|
|
156
|
+
expect(row.querySelector(".hk-notification-row__state")).toBeFalsy();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("a same-millisecond tie renders the LATER push above (append order)", async () => {
|
|
160
|
+
// R8/R9 pin (PR #1322): with updatedAt equal the journal's own
|
|
161
|
+
// append order judges — the later push must sit above the earlier
|
|
162
|
+
// one (string ids carry no numeric order, so an id tiebreak would
|
|
163
|
+
// flip across digit widths).
|
|
164
|
+
await setLocale("en");
|
|
165
|
+
recordNotification({ id: "toast:e:1:9", kind: "toast", tone: "error", title: "earlier" });
|
|
166
|
+
recordNotification({ id: "toast:e:1:10", kind: "toast", tone: "warning", title: "later" });
|
|
167
|
+
const { entries } = useNotificationCenter();
|
|
168
|
+
entries.forEach((e) => { e.updatedAt = 1_000; });
|
|
169
|
+
mountBell();
|
|
170
|
+
await settle();
|
|
171
|
+
bellButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
172
|
+
await settle();
|
|
173
|
+
const titles = rows().map((r) => r.querySelector(".hk-notification-row__title")?.textContent);
|
|
174
|
+
expect(titles).toEqual(["later", "earlier"]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("the restore button is STATE-gated even when a callback lingers", async () => {
|
|
178
|
+
// R2 finding, PR #1322 (mutation-e pin): the S1 gate is redundant
|
|
179
|
+
// in-tree (active emergencies never carry a callback), so this test
|
|
180
|
+
// builds the one shape that would otherwise render a dead control —
|
|
181
|
+
// a host-recorded entry holding a callback in a non-snoozed state.
|
|
182
|
+
await setLocale("en");
|
|
183
|
+
recordNotification({
|
|
184
|
+
id: "emergency:done",
|
|
185
|
+
kind: "emergency",
|
|
186
|
+
tone: "warning",
|
|
187
|
+
title: "resolved but armed",
|
|
188
|
+
state: "cleared",
|
|
189
|
+
onResummon: () => {},
|
|
190
|
+
});
|
|
191
|
+
mountBell();
|
|
192
|
+
await settle();
|
|
193
|
+
bellButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
194
|
+
await settle();
|
|
195
|
+
const row = rows()[0];
|
|
196
|
+
expect(row.querySelector(".hk-notification-row__state")?.textContent).toBe("Resolved");
|
|
197
|
+
expect(row.querySelector(".hk-notification-row__restore")).toBeFalsy();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("a cleared emergency shows Resolved without a restore button", async () => {
|
|
201
|
+
await setLocale("en");
|
|
202
|
+
recordNotification({
|
|
203
|
+
id: "emergency:done",
|
|
204
|
+
kind: "emergency",
|
|
205
|
+
tone: "warning",
|
|
206
|
+
title: "resolved",
|
|
207
|
+
state: "cleared",
|
|
208
|
+
});
|
|
209
|
+
mountBell();
|
|
210
|
+
await settle();
|
|
211
|
+
bellButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
212
|
+
await settle();
|
|
213
|
+
const row = rows()[0];
|
|
214
|
+
expect(row.querySelector(".hk-notification-row__state")?.textContent).toBe("Resolved");
|
|
215
|
+
expect(row.querySelector(".hk-notification-row__restore")).toBeFalsy();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("rows sort newest-first and Clear all empties the journal", async () => {
|
|
219
|
+
await setLocale("en");
|
|
220
|
+
const { entries } = useNotificationCenter();
|
|
221
|
+
recordNotification({ id: "old", kind: "toast", tone: "error", title: "older" });
|
|
222
|
+
recordNotification({ id: "new", kind: "toast", tone: "warning", title: "newer" });
|
|
223
|
+
// Same-millisecond pushes would tie on updatedAt — make the recency
|
|
224
|
+
// explicit for this assertion (the pure-tie case is pinned below).
|
|
225
|
+
entries.find((e) => e.id === "new")!.updatedAt = Date.now() + 5_000;
|
|
226
|
+
mountBell();
|
|
227
|
+
await settle();
|
|
228
|
+
bellButton().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
229
|
+
await settle();
|
|
230
|
+
const titles = rows().map((r) => r.querySelector(".hk-notification-row__title")?.textContent);
|
|
231
|
+
expect(titles).toEqual(["newer", "older"]);
|
|
232
|
+
|
|
233
|
+
(document.querySelector<HTMLButtonElement>(".hk-notification-center__clear")!).dispatchEvent(
|
|
234
|
+
new MouseEvent("click", { bubbles: true }),
|
|
235
|
+
);
|
|
236
|
+
await settle();
|
|
237
|
+
expect(document.querySelector(".hk-notification-center__empty")).toBeTruthy();
|
|
238
|
+
expect(rows()).toHaveLength(0);
|
|
239
|
+
});
|
|
240
|
+
});
|