chore: 统一日报时间逻辑

This commit is contained in:
Wxw-Gu
2026-09-02 16:02:05 +08:00
parent 7c8b45a24a
commit 76e9e683c4
19 changed files with 124 additions and 43 deletions
+9 -9
View File
@@ -133,7 +133,7 @@ describe('daily report controls', () => {
</>
)
expect(screen.getByRole('radio', { name: '今天' })).toBeChecked()
expect(screen.getByRole('radio', { name: '今日' })).toBeChecked()
await user.click(screen.getByRole('radio', { name: '近 7 天' }))
expect(onRangeChange).toHaveBeenCalledWith('7days')
expect(screen.getAllByRole('checkbox')).toHaveLength(SUMMARY_TYPE_OPTIONS.length)
@@ -382,7 +382,7 @@ describe('daily report controls', () => {
id: 'report-1',
contactId: 'group-md5',
contactName: '测试群',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-12T10:00:00.000Z',
reportDate: '2026-08-12',
@@ -443,7 +443,7 @@ describe('daily report controls', () => {
id: 'temporary-result',
contactId: 'group-md5',
contactName: '测试群',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-13T10:00:00.000Z',
reportDate: '2026-08-13',
@@ -514,7 +514,7 @@ describe('daily report controls', () => {
id: 'model-info',
contactId: 'group-md5',
contactName: '测试群',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-13T10:00:00.000Z',
reportDate: '2026-08-13',
@@ -582,7 +582,7 @@ describe('daily report controls', () => {
id: 'report-send',
contactId: groupContact.md5,
contactName: groupContact.m_nsNickName,
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-17T10:00:00.000Z',
reportDate: '2026-08-17',
@@ -621,7 +621,7 @@ describe('daily report controls', () => {
id: 'report-send-disabled',
contactId: groupContact.md5,
contactName: groupContact.m_nsNickName,
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-17T10:00:00.000Z',
reportDate: '2026-08-17',
@@ -657,7 +657,7 @@ describe('daily report controls', () => {
id: 'report-switch',
contactId: 'group-md5',
contactName: '测试群',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-12T10:00:00.000Z',
reportDate: '2026-08-12',
@@ -753,7 +753,7 @@ describe('daily report controls', () => {
id: 'report-delete-cancel',
contactId: 'group-md5',
contactName: '测试群',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-17T10:00:00.000Z',
reportDate: '2026-08-17',
@@ -823,7 +823,7 @@ describe('daily report controls', () => {
id: 'report-delete-result',
contactId: 'group-md5',
contactName: '测试群',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-17T10:00:00.000Z',
reportDate: '2026-08-17',
@@ -128,6 +128,26 @@ describe('ScheduledReportsWorkspace', () => {
)
})
it('keeps scheduled report range labels readable in compact layouts', async () => {
vi.mocked(window.api.listScheduledReports).mockResolvedValue([])
render(
<ScheduledReportsWorkspace
contacts={[group]}
onNotice={onNotice}
onOpenWechatSettings={onOpenWechatSettings}
onOpenAgentHub={onOpenAgentHub}
/>
)
await waitFor(() => expect(screen.getByText('还没有定时日报')).toBeVisible())
fireEvent.click(screen.getAllByRole('button', { name: /新建定时日报/ })[0])
const range = screen.getByRole('radiogroup', { name: '总结范围' })
expect(range).toHaveClass('grid-cols-2', 'sm:grid-cols-5')
expect(screen.getByText('自定义', { exact: true })).toHaveClass('whitespace-nowrap')
expect(screen.getByText('即将支持', { exact: true })).toHaveClass('whitespace-nowrap')
})
it('keeps the notification switch off by default and loads the persisted setting', async () => {
render(
<ScheduledReportsWorkspace
+11 -2
View File
@@ -32,6 +32,15 @@ test('SCHEDULED-REPORT-UI-01 opens the scheduled report dialog without viewport
await expect(dialog.getByPlaceholder('搜索群聊')).toBeVisible()
await expect(dialog.getByRole('button', { name: '创建定时日报' })).toBeVisible()
const customRange = dialog.locator('[aria-disabled="true"]')
await expect(customRange).toHaveCount(1)
const customLabel = customRange.getByText('自定义', { exact: true })
const customHint = customRange.getByText('即将支持', { exact: true })
await expect(customLabel).toHaveCSS('white-space', 'nowrap')
await expect(customHint).toHaveCSS('white-space', 'nowrap')
expect((await customLabel.boundingBox())?.height).toBeLessThanOrEqual(20)
expect((await customHint.boundingBox())?.height).toBeLessThanOrEqual(20)
const selects = dialog.getByRole('combobox')
await expect(selects).toHaveCount(2)
await selects.nth(0).click()
@@ -55,11 +64,11 @@ test('SCHEDULED-REPORT-UI-01 opens the scheduled report dialog without viewport
expect(bounds!.y + bounds!.height).toBeLessThanOrEqual(600)
await dialog.getByPlaceholder('例如:技术交流 · 每日日报').fill('E2E 定时日报')
await dialog.getByRole('radio', { name: '今天' }).click()
await dialog.getByRole('radio', { name: '今日' }).click()
await dialog.getByRole('button', { name: '创建定时日报' }).click()
await expect(dialog).toHaveCount(0)
await expect(fixture.page.getByText('E2E 定时日报', { exact: true })).toBeVisible()
await expect(fixture.page.getByText('今天', { exact: true })).toBeVisible()
await expect(fixture.page.getByText('今日', { exact: true })).toBeVisible()
await fixture.page.getByRole('button', { name: '设置' }).click()
await fixture.page.getByRole('button', { name: '微信发送', exact: true }).click()
+10
View File
@@ -345,4 +345,14 @@ describe('summary date ranges', () => {
endTime: now.getTime() / 1000
})
})
it('keeps a scheduled 20:00 today report on the current local calendar day', () => {
const now = new Date(2026, 7, 27, 20, 0, 0)
const startOfToday = new Date(2026, 7, 27, 0, 0, 0)
expect(getSummaryDateRangeAt('today', now)).toEqual({
startTime: startOfToday.getTime() / 1000,
endTime: now.getTime() / 1000
})
})
})
+5 -5
View File
@@ -41,7 +41,7 @@ const reportSnapshot = {
const reportMetadata = {
groupName: '测试群',
reportDate: '2026-08-12',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
activeUsers: 3,
timeSpan: '09:00–18:00',
@@ -68,7 +68,7 @@ describe('generated report template history', () => {
const saved = await saveGeneratedReport({
contactId: 'group-md5',
contactName: '测试群',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-12T10:00:00.000Z',
reportDate: '2026-08-11',
@@ -114,7 +114,7 @@ describe('generated report template history', () => {
const saved = await saveGeneratedReport({
contactId: 'legacy-group',
contactName: '旧报告',
dateRange: '今天',
dateRange: '今日',
messageCount: 5,
generatedAt: '2026-08-12T11:00:00.000Z',
generatedImage: `data:image/png;base64,${Buffer.from('legacy').toString('base64')}`,
@@ -142,7 +142,7 @@ describe('generated report template history', () => {
const saved = await saveGeneratedReport({
contactId: 'legacy-snapshot-group',
contactName: '旧报告快照',
dateRange: '今天',
dateRange: '今日',
messageCount: 8,
generatedAt: '2026-08-12T12:00:00.000Z',
generatedImage: `data:image/png;base64,${Buffer.from('legacy-snapshot').toString('base64')}`,
@@ -172,7 +172,7 @@ describe('generated report template history', () => {
const saved = await saveGeneratedReport({
contactId: 'classic-group',
contactName: '经典日报群',
dateRange: '今天',
dateRange: '今日',
messageCount: 6,
generatedAt: '2026-08-12T13:00:00.000Z',
generatedImage: `data:image/png;base64,${Buffer.from('classic').toString('base64')}`,
+1 -1
View File
@@ -6,7 +6,7 @@ const structuredReport = {
id: 'report-1',
contactId: 'group-1',
contactName: '测试群',
dateRange: '今天',
dateRange: '今日',
messageCount: 10,
generatedAt: '2026-08-12T10:00:00.000Z',
reportDate: '2026-08-12',
@@ -254,6 +254,42 @@ describe('scheduled report scheduling', () => {
).toContain('微信发送成功')
})
it('passes a selected today range through a scheduled 20:00 execution', async () => {
const storageDir = await mkdtemp(join(tmpdir(), 'tracememo-scheduled-report-today-'))
let currentTime = new Date(2026, 7, 27, 19, 59, 0)
const generateReport = vi.fn(async () => ({
success: true,
groupName: '研发群',
pngPath: '/tmp/generated.png',
messageCount: 1
}))
const service = new ScheduledReportService({
storageDir,
now: () => currentTime,
getCapability: async () => capability,
generateReport,
saveGeneratedReport: async () => ({ success: true, record: reportRecord('/tmp/saved.png') }),
send: async () => ({ success: true, status: capability.senderStatus }),
isDatabaseReady: () => true
})
const created = await service.createTask({
name: '今日日报',
group: '研发群',
target: '研发群@chatroom',
scheduleTime: '20:00',
reportRange: 'today'
})
expect(created.success).toBe(true)
currentTime = new Date(2026, 7, 27, 20, 0, 0)
const execution = await runScheduled(service, created.data!.id)
expect(execution.status).toBe('success')
expect(generateReport).toHaveBeenCalledWith(
expect.objectContaining({ group: '研发群', range: 'today' })
)
})
it('does not send a generated report when history persistence fails', async () => {
const storageDir = await mkdtemp(join(tmpdir(), 'tracememo-scheduled-report-history-'))
const generatedPath = join(storageDir, 'report.png')