fix(panel): remove range-switch font flicker and simplify rate popover

- Drop transparent-container opacity animations on ConsumptionView and TrendAreaChart range switches that forced DirectWrite grayscale AA transitions, and pool trend X-axis ticks, grid lines, and heatmap cells in-place
- Remove the redundant weekly quota summary row, internal hairlines, and bottom note from the QuotaPoolsWidget empirical burn-rate popover
This commit is contained in:
fish
2026-11-24 19:23:38 +09:00
parent 0b700d1f9f
commit 1692599fd8
13 changed files with 505 additions and 874 deletions
@@ -1673,3 +1673,204 @@ test('xlsxBuilder enforces 32,767 UTF-16 cell limit without splitting surrogate
const cellA3 = cellMatches[1][1];
assert.equal(cellA3, 'ok\uFFFDmid\uFFFDend');
});
test('ConsumptionView and TrendAreaChart patch text DOM nodes in-place without opacity flicker classes on date range switches', async () => {
const consCss = fs.readFileSync(
fileURLToPath(new URL('../src/styles/views-consumption.css', import.meta.url)),
'utf8'
);
for (const bannedToken of [
'is-range-switching',
'is-tab-entering',
'is-switching',
'is-stage-entering',
'anim-cons-content-switch',
'anim-cons-axis-fade',
'anim-cons-stage-in',
]) {
assert.equal(
consCss.includes(bannedToken),
false,
`Expected views-consumption.css not to contain text-opacity flicker rule "${bannedToken}"`
);
}
const { createMockDom } = await import('./mock-dom.mjs');
const prevDoc = globalThis.document;
const prevWin = globalThis.window;
const { document } = createMockDom();
globalThis.document = document;
globalThis.window = {
location: { origin: 'http://127.0.0.1:41234', href: 'http://127.0.0.1:41234/' },
getComputedStyle: () => ({ overflow: 'visible', overflowX: 'visible', overflowY: 'visible' }),
matchMedia: () => ({ matches: false }),
requestAnimationFrame: (cb) => setTimeout(() => cb(performance.now()), 0),
cancelAnimationFrame: (id) => clearTimeout(id),
addEventListener() {},
removeEventListener() {},
};
try {
const { ConsumptionView } = await import('../src/views/ConsumptionView.js');
const { telemetryStore } = await import('../src/store/telemetryStore.js');
const { uiStore } = await import('../src/store/uiStore.js');
const prevTelState = { ...telemetryStore.getState() };
const prevUiState = { ...uiStore.getState() };
uiStore.setState(
{ activeView: 'consumption', monitorVisible: true, settingsOpen: false },
{ sync: true }
);
const view = ConsumptionView();
document.body.appendChild(view.el);
const makeRangePayload = (rangeKey, tokBase, labels) => ({
settings: { modelDisplayMode: 'short', showUpstreamModel: false, orchestratorIdMode: 'label' },
consumption: {
revision: 0,
selectedRange: {
key: rangeKey,
label: rangeKey,
startMs: 1_760_000_000_000,
endMs: 1_760_086_400_000,
},
account: {
totalTokens: tokBase,
inputTokens: Math.round(tokBase * 0.2),
cacheReadTokens: Math.round(tokBase * 0.7),
outputTokens: Math.round(tokBase * 0.1),
responseTokens: Math.round(tokBase * 0.07),
thinkingTokens: Math.round(tokBase * 0.03),
calls: 12,
costUsd: 1.25,
savedCostUsd: 0.85,
cacheHitPct: 77.8,
},
trendSeries: labels.map((lbl, idx) => ({
index: idx,
startMs: 1_760_000_000_000 + idx * 3_600_000,
endMs: 1_760_000_000_000 + (idx + 1) * 3_600_000,
granularity: labels.length > 90 ? 'day' : 'hour',
label: lbl,
fullLabel: lbl,
tokens: 1_000 * (idx + 1),
calls: 1,
costUsd: 0.05,
})),
sourcesBreakdown: [
{
name: 'antigravity',
label: 'Antigravity IDE',
totalTokens: tokBase,
calls: 12,
costUsd: 1.25,
models: [{ label: 'Claude Opus 4.6', shortName: 'Claude Opus 4.6', totalTokens: tokBase, calls: 12 }],
},
],
topConversations: [],
topWorkspaces: [],
monthlyYear: 2026,
monthlySeries: Array.from({ length: 12 }, (_, m) => ({
month: m + 1,
totalTokens: m === 10 ? tokBase : 0,
costUsd: m === 10 ? 1.25 : 0,
calls: m === 10 ? 12 : 0,
})),
},
modelBreakdown: [
{
label: 'Claude Opus 4.6',
shortName: 'Claude Opus 4.6',
totalTokens: tokBase,
inputTokens: Math.round(tokBase * 0.2),
cacheReadTokens: Math.round(tokBase * 0.7),
responseTokens: Math.round(tokBase * 0.07),
thinkingTokens: Math.round(tokBase * 0.03),
outputTokens: Math.round(tokBase * 0.1),
calls: 12,
costUsd: 1.25,
},
],
});
telemetryStore.setState(
{
selectedTimeRange: 'today',
telemetry: makeRangePayload('today', 100_000, ['00:00', '06:00', '12:00', '18:00']),
},
{ sync: true }
);
const matrixEl = view.el.querySelector('.cons-unified-matrix');
const heroNumEl = view.el.querySelector('.cons-hero-num');
const modelRowEl = view.el.querySelector('.cons-item-row');
const modelTitleTextEl = modelRowEl.querySelector('.cons-row-title-text');
const sourceRowEl = view.el.querySelector('.cons-source-row');
const xAxisEl = view.el.querySelector('.trend-x-axis');
const initialTicks = xAxisEl.querySelectorAll('.trend-x-tick');
assert.equal(initialTicks.length, 4);
// Switch to 7d: same model, same source, updated numbers & tick labels -> all DOM nodes reused in-place, zero opacity flicker classes
telemetryStore.setState(
{
selectedTimeRange: '7d',
telemetry: makeRangePayload('7d', 450_000, ['11/18', '11/20', '11/22', '11/24']),
},
{ sync: true }
);
assert.equal(view.el.querySelector('.cons-hero-num'), heroNumEl, 'Hero token element persists');
assert.equal(view.el.querySelector('.cons-item-row'), modelRowEl, 'Model row element persists');
assert.equal(
view.el.querySelector('.cons-item-row .cons-row-title-text'),
modelTitleTextEl,
'Model title text node persists'
);
assert.equal(view.el.querySelector('.cons-source-row'), sourceRowEl, 'Source row element persists');
const nextTicks = xAxisEl.querySelectorAll('.trend-x-tick');
assert.equal(nextTicks.length, 4);
for (let i = 0; i < 4; i++) {
assert.equal(nextTicks[i], initialTicks[i], `Trend X-axis tick #${i} reused in-place`);
}
assert.equal(nextTicks[0].textContent, '11/18');
for (const cls of ['is-range-switching', 'is-tab-entering', 'is-switching', 'is-stage-entering']) {
assert.equal(matrixEl.classList.contains(cls), false);
assert.equal(modelRowEl.parentNode.classList.contains(cls), false);
assert.equal(sourceRowEl.parentNode.classList.contains(cls), false);
assert.equal(xAxisEl.classList.contains(cls), false);
}
// Switch to >90d heatmap and update counts -> month labels and grid cells reuse pooled nodes in-place
const hmLabelsA = Array.from({ length: 95 }, (_, idx) => `08/${String((idx % 28) + 1).padStart(2, '0')}`);
telemetryStore.setState(
{
selectedTimeRange: 'all',
telemetry: makeRangePayload('all', 900_000, hmLabelsA),
},
{ sync: true }
);
const hmGridEl = view.el.querySelector('.trend-hm-grid');
const firstGridCells = [...hmGridEl.children];
assert.ok(firstGridCells.length >= 95);
telemetryStore.setState(
{
selectedTimeRange: 'all',
telemetry: makeRangePayload('all', 950_000, hmLabelsA),
},
{ sync: true }
);
const secondGridCells = [...hmGridEl.children];
assert.equal(secondGridCells.length, firstGridCells.length);
assert.equal(secondGridCells[10], firstGridCells[10], 'Heatmap cell DOM node reused in-place');
view.destroy();
telemetryStore.setState(prevTelState, { sync: true });
uiStore.setState(prevUiState, { sync: true });
} finally {
globalThis.document = prevDoc;
globalThis.window = prevWin;
}
});
+14 -28
View File
@@ -2208,7 +2208,7 @@ test('quota-reservation: 3-tier hybrid estimator unlocks cycle_ratio & anchor_sl
assert.equal(pAfterRestart.get('Claude & GPT').rateEstimate?.eqFullWeeklyTokens, 12_500_000);
});
test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, preliminary labels, and full-pool token references', async () => {
test('QuotaPoolsWidget ? popover renders preliminary labels and full-pool token references without weekly summary row, footer note, or divider rules', async () => {
const { document } = createMockDom();
const origDocument = globalThis.document;
const origWindow = globalThis.window;
@@ -2231,8 +2231,9 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin
const widget = QuotaPoolsWidget();
const popover = widget.refs.ratePopoverEl;
// 1. Collecting state: top weekly summary hidden until at least 1 pool has a weekly capacity estimate
assert.equal(popover.querySelector('.quota-rate-wk-summary')?.hidden, true);
// 1. Minimalist layout: no redundant weekly summary row or footer note element
assert.equal(popover.querySelector('.quota-rate-wk-summary'), null);
assert.equal(popover.querySelector('.quota-rate-pop-note'), null);
// 2. Partial + Preliminary state (Claude ready via anchor_slope, Gemini still collecting)
widget.refs.update({
@@ -2280,9 +2281,8 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin
minuteTick: 1,
});
const wkSummary = popover.querySelector('.quota-rate-wk-summary');
assert.equal(wkSummary.hidden, false);
assert.match(wkSummary.textContent, /预测周额度.*· 1\/2 池.*≈ \$48.*· 9\.9M/);
assert.doesNotMatch(popover.textContent, /预测周额度/);
assert.doesNotMatch(popover.textContent, /同池最省/);
const fallbackRow = popover.querySelector('.quota-rate-model-row.is-fallback');
assert.ok(fallbackRow);
assert.match(fallbackRow.textContent, /池综合均值/);
@@ -2292,7 +2292,7 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin
const wkRowLeft = widget.refs.poolsListEl.querySelectorAll('.quota-win-left')[1];
assert.match(wkRowLeft.getAttribute('title') || '', /满池约 \$48 \(9\.9M\)/);
// 3. All pools calibrated & ready: sums USD + Tokens cleanly ($50 + $35 = $85, 10.3M + 14.2M = 24.5M)
// 3. All pools calibrated & ready: renders per-pool model & fallback cards cleanly
const allReadyData = {
account: { email: 'sjee80343@gmail.com', tierName: 'Google AI Pro' },
quotas: {
@@ -2367,33 +2367,21 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin
},
};
widget.refs.update({ data: allReadyData, minuteTick: 2 });
assert.equal(wkSummary.hidden, false);
assert.equal(wkSummary.querySelector('.quota-rate-wk-sub').hidden, true);
assert.match(wkSummary.textContent, /预测周额度≈ \$85· 24\.5M/);
assert.match(popover.textContent, /Claude Sonnet 4\.6.*5h 满池≈ \$50· 10\.3M.*周限满池≈ \$50· 10\.3M/);
assert.match(popover.textContent, /Gemini.*池综合均值.*5h 满池≈ \$35· 14\.2M/);
// 4. English locale switch updates weekly summary, model cards, and row title tooltip without reload
// 4. English locale switch updates model cards and row title tooltip without reload
setI18nLanguage('en-US');
widget.refs.update({ data: allReadyData, minuteTick: 3 });
assert.match(wkSummary.textContent, /Est\. Weekly Quota≈ \$85· 24\.5M/);
assert.doesNotMatch(popover.textContent, /Est\. Weekly Quota/);
assert.doesNotMatch(popover.textContent, /lowest in pool/);
assert.match(popover.textContent, /5h full≈ \$50· 10\.3M.*Weekly full≈ \$50· 10\.3M/);
assert.match(
widget.refs.poolsListEl.querySelectorAll('.quota-win-left')[1].getAttribute('title') || '',
/Full ~\$50 \(10\.3M\)/
);
// 5. Custom local weekly budget mode hides official weekly capacity summary
widget.refs.update({
data: {
...allReadyData,
quotas: {
...allReadyData.quotas,
weekly: { isOfficial: false },
},
},
minuteTick: 4,
});
assert.equal(wkSummary.hidden, true);
// 6. Pool with 5h-only model card + pool-level preliminary weekly estimate renders supplementary weekly fallback row
// 5. Pool with 5h-only model card + pool-level preliminary weekly estimate renders supplementary weekly fallback row
setI18nLanguage('zh-CN');
widget.refs.update({
data: {
@@ -2443,8 +2431,6 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin
},
minuteTick: 5,
});
assert.equal(wkSummary.hidden, false);
assert.match(wkSummary.textContent, /预测周额度.*· 初估.*≈ \$600.*· 200\.0M/);
const mixedRows = popover.querySelectorAll('.quota-rate-model-row');
assert.equal(mixedRows.length, 2, 'renders 5h model card + supplementary pool weekly fallback row');
assert.match(mixedRows[0].textContent, /Gemini 3\.1 Pro.*5h 满池≈ \$150/);