dsh-usage-peak 1.4.0 → 1.4.1
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/CHANGELOG.md +4 -0
- package/client.js +8 -2
- package/package.json +1 -1
- package/test/client.test.js +7 -1
package/CHANGELOG.md
CHANGED
package/client.js
CHANGED
|
@@ -388,6 +388,12 @@ window.__ModuleLoader__.load({
|
|
|
388
388
|
return `${base}?days=${days || DEFAULT_DAYS}${project ? `&project=${encodeURIComponent(project)}` : ''}${fresh ? '&fresh=1' : ''}`;
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
+
// Keep the peak/valley countdown visible in the pill; the warning is an
|
|
392
|
+
// accent plus a prefix, never a replacement for the status text.
|
|
393
|
+
function pillStatus(alertActive, switchText) {
|
|
394
|
+
return alertActive ? `⚠ ${switchText}` : switchText;
|
|
395
|
+
}
|
|
396
|
+
|
|
391
397
|
// Generation guard rejects old filter responses and older same-filter reloads.
|
|
392
398
|
function requestGate() {
|
|
393
399
|
let key = null;
|
|
@@ -516,7 +522,7 @@ window.__ModuleLoader__.load({
|
|
|
516
522
|
const walletTip =
|
|
517
523
|
wallet && wallet.balance !== null
|
|
518
524
|
? `${t('kpi.balance')} ${yuan(wallet.balance)}${walletText ? ` · ${walletText}` : ''}`
|
|
519
|
-
:
|
|
525
|
+
: walletText;
|
|
520
526
|
const tip = data
|
|
521
527
|
? `${word} · ${t('widget.today')} ${yuan(today)} · ${tokens(data.today ? data.today.tokens : 0, t)} tokens · ${t('status.switchIn')} ${switchText}${walletTip ? ` · ${walletTip}` : ''}`
|
|
522
528
|
: word;
|
|
@@ -571,7 +577,7 @@ window.__ModuleLoader__.load({
|
|
|
571
577
|
textOverflow: 'ellipsis',
|
|
572
578
|
},
|
|
573
579
|
},
|
|
574
|
-
data ? (walletAlert
|
|
580
|
+
data ? pillStatus(walletAlert, switchText) : '',
|
|
575
581
|
),
|
|
576
582
|
);
|
|
577
583
|
|
package/package.json
CHANGED
package/test/client.test.js
CHANGED
|
@@ -10,7 +10,7 @@ function helpers(storage = {}) {
|
|
|
10
10
|
const context = { window: { localStorage: storage, dispatchEvent: (event) => events.push(event) }, CustomEvent: class { constructor(type, options) { this.type = type; this.detail = options.detail; } }, C: { error: 'red', peak: 'amber', text3: 'gray' }, DATA_URL: '/data', DEFAULT_DAYS: 14 };
|
|
11
11
|
const start = source.indexOf(" const PREFS_KEY =");
|
|
12
12
|
const stop = source.indexOf(' function useFeed(', start);
|
|
13
|
-
vm.runInNewContext(source.slice(start, stop) + '\nthis.api = { validatePrefs, readPrefs, savePrefs, alertState, feedUrl, requestGate, tint };', context);
|
|
13
|
+
vm.runInNewContext(source.slice(start, stop) + '\nthis.api = { validatePrefs, readPrefs, savePrefs, alertState, feedUrl, requestGate, tint, pillStatus };', context);
|
|
14
14
|
return { ...context.api, events };
|
|
15
15
|
}
|
|
16
16
|
const plain = (value) => JSON.parse(JSON.stringify(value));
|
|
@@ -74,6 +74,12 @@ test('client data and CSV URLs encode project identity and preserve scope', () =
|
|
|
74
74
|
assert.equal(api.feedUrl('/data', 14, ''), '/data?days=14');
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
+
test('client alert prefix keeps the peak/valley countdown visible', () => {
|
|
78
|
+
const api = helpers();
|
|
79
|
+
assert.equal(api.pillStatus(true, '2:43 后转谷'), '⚠ 2:43 后转谷');
|
|
80
|
+
assert.equal(api.pillStatus(false, '2:43 后转谷'), '2:43 后转谷');
|
|
81
|
+
});
|
|
82
|
+
|
|
77
83
|
test('client request generation guard rejects old filters, refreshes, and unmount results', () => {
|
|
78
84
|
const gate = helpers().requestGate();
|
|
79
85
|
gate.select('alpha');
|