Merge pull request #3097 from NeckBozia/fix/5h-resets-at-stale

fix(usage): sync 5h ResetsAt to SessionWindowEnd and zero expired window
This commit is contained in:
Wesley Liddick
2026-06-08 09:08:23 +08:00
committed by GitHub
13 changed files with 229 additions and 5 deletions
@@ -149,7 +149,7 @@ const shouldShowResetTime = computed(() => {
const formatResetTime = computed(() => {
// For rolling windows, when utilization is 0%, treat as immediately available.
if (props.showNowWhenIdle && props.utilization <= 0) {
return '现在'
return t('usage.resetNow')
}
if (!props.resetsAt) return '-'
@@ -157,7 +157,11 @@ const formatResetTime = computed(() => {
const date = new Date(props.resetsAt)
const diffMs = date.getTime() - now.value.getTime()
if (diffMs <= 0) return '现在'
// resetsAt 已过期:utilization>0 说明后端窗口数据还没刷新(active poll 没回写),
// 显示「待刷新」以区别于真正可用的「现在」。
if (diffMs <= 0) {
return props.utilization > 0 ? t('usage.resetPending') : t('usage.resetNow')
}
const diffHours = Math.floor(diffMs / (1000 * 60 * 60))
const diffMins = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60))
@@ -33,7 +33,7 @@ describe('UsageProgressBar', () => {
}
})
expect(wrapper.text()).toContain('现在')
expect(wrapper.text()).toContain('usage.resetNow')
expect(wrapper.text()).not.toContain('2h 30m')
})
@@ -49,7 +49,8 @@ describe('UsageProgressBar', () => {
})
expect(wrapper.text()).toContain('2h 30m')
expect(wrapper.text()).not.toContain('现在')
expect(wrapper.text()).not.toContain('usage.resetNow')
expect(wrapper.text()).not.toContain('usage.resetPending')
})
it('showNowWhenIdle=false 时保持原有倒计时行为', () => {
@@ -64,6 +65,35 @@ describe('UsageProgressBar', () => {
})
expect(wrapper.text()).toContain('2h 30m')
expect(wrapper.text()).not.toContain('现在')
expect(wrapper.text()).not.toContain('usage.resetNow')
})
it('resetsAt 已过期且利用率大于 0 时显示「待刷新」', () => {
const wrapper = mount(UsageProgressBar, {
props: {
label: '5h',
utilization: 53,
// 早于 fake system time 2026-03-17T00:00:00Z
resetsAt: '2026-03-16T22:00:00Z',
color: 'indigo'
}
})
expect(wrapper.text()).toContain('usage.resetPending')
expect(wrapper.text()).not.toContain('usage.resetNow')
})
it('resetsAt 已过期且利用率为 0 时仍显示「现在」', () => {
const wrapper = mount(UsageProgressBar, {
props: {
label: '5h',
utilization: 0,
resetsAt: '2026-03-16T22:00:00Z',
color: 'indigo'
}
})
expect(wrapper.text()).toContain('usage.resetNow')
expect(wrapper.text()).not.toContain('usage.resetPending')
})
})
+2
View File
@@ -856,6 +856,8 @@ export default {
accountCost: 'Cost',
userBilled: 'User billed',
accountBilled: 'Account billed',
resetNow: 'Now',
resetPending: 'Pending refresh',
accountMultiplier: 'Account rate',
avgDuration: 'Avg Duration',
inSelectedRange: 'in selected range',
+2
View File
@@ -860,6 +860,8 @@ export default {
accountCost: '成本',
userBilled: '用户扣费',
accountBilled: '账号计费',
resetNow: '现在',
resetPending: '待刷新',
accountMultiplier: '账号倍率',
avgDuration: '平均耗时',
inSelectedRange: '所选范围内',