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 authored and GitHub committed 2026-06-08 09:08:23 +08:00
commit 870cefddf5
13 files changed
+229 -5

No files matched your search

@@ -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')
})
})