|
|
@@ -101,22 +101,14 @@ describe('FunnelPage — fixed funnel + period selection', () => {
|
|
|
return lastReq()?.period;
|
|
|
}
|
|
|
|
|
|
- /** Yesterday as "yyyy-MM-dd" (the picker default + request snapshot_dt). */
|
|
|
- function yesterdayParam(): string {
|
|
|
- const d = new Date();
|
|
|
- d.setDate(d.getDate() - 1);
|
|
|
- const y = d.getFullYear();
|
|
|
- const m = String(d.getMonth() + 1).padStart(2, '0');
|
|
|
- const day = String(d.getDate()).padStart(2, '0');
|
|
|
- return `${y}-${m}-${day}`;
|
|
|
- }
|
|
|
-
|
|
|
- it('auto-queries with default 单日 (day = yesterday) on first render', async () => {
|
|
|
+ it('auto-queries with default 单日 (latest available day) on first render', async () => {
|
|
|
queryFunnelMock.mockResolvedValue(readyResponse());
|
|
|
renderPage();
|
|
|
|
|
|
+ // Data is T+1 and may lag, so the default omits snapshot_dt and the server
|
|
|
+ // returns MAX(dt) — no hard-coded yesterday that could be "数据缺失".
|
|
|
await waitFor(() => expect(lastPeriod()).toBe('day'));
|
|
|
- expect(lastReq()).toEqual({ period: 'day', snapshot_dt: yesterdayParam() });
|
|
|
+ expect(lastReq()).toEqual({ period: 'day' });
|
|
|
expect(queryFunnelMock).toHaveBeenCalledTimes(1);
|
|
|
});
|
|
|
|
|
|
@@ -188,26 +180,44 @@ describe('FunnelPage — fixed funnel + period selection', () => {
|
|
|
await waitFor(() => expect(lastPeriod()).toBe('day'));
|
|
|
});
|
|
|
|
|
|
- it('单日 segment defaults to yesterday', async () => {
|
|
|
+ it('单日 segment defaults to 最新 (latest available day)', async () => {
|
|
|
queryFunnelMock.mockResolvedValue(readyResponse());
|
|
|
renderPage();
|
|
|
|
|
|
await waitFor(() => expect(lastPeriod()).toBe('day'));
|
|
|
const picker = screen.getByRole('button', { name: '选择历史日期' });
|
|
|
expect(picker).toBeInTheDocument();
|
|
|
- expect(picker).toHaveTextContent(yesterdayParam());
|
|
|
+ expect(picker).toHaveTextContent('最新');
|
|
|
});
|
|
|
|
|
|
- it('default day sends snapshot_dt; rolling periods omit it', async () => {
|
|
|
+ it('default day omits snapshot_dt; a picked date sends it, then 最新 clears it', async () => {
|
|
|
queryFunnelMock.mockResolvedValue(readyResponse());
|
|
|
const user = userEvent.setup();
|
|
|
renderPage();
|
|
|
|
|
|
- // default 单日 sends snapshot_dt = yesterday
|
|
|
+ // default 单日 (latest) omits snapshot_dt
|
|
|
await waitFor(() => expect(lastPeriod()).toBe('day'));
|
|
|
- expect(lastReq()).toEqual({ period: 'day', snapshot_dt: yesterdayParam() });
|
|
|
+ expect(lastReq()).toEqual({ period: 'day' });
|
|
|
+
|
|
|
+ // picking a historical date sends that snapshot_dt
|
|
|
+ await pickFirstOfMonth(user, await openCalendar(user));
|
|
|
+ await waitFor(() => {
|
|
|
+ const req = lastReq();
|
|
|
+ expect(req?.period).toBe('day');
|
|
|
+ expect(req?.snapshot_dt).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 最新可用日 quick-pick clears snapshot_dt again
|
|
|
+ await user.click(screen.getByRole('button', { name: '选择历史日期' }));
|
|
|
+ await user.click(await screen.findByRole('button', { name: '最新可用日' }));
|
|
|
+ await waitFor(() => expect(lastReq()).toEqual({ period: 'day' }));
|
|
|
+ });
|
|
|
+
|
|
|
+ it('rolling periods omit snapshot_dt', async () => {
|
|
|
+ queryFunnelMock.mockResolvedValue(readyResponse());
|
|
|
+ const user = userEvent.setup();
|
|
|
+ renderPage();
|
|
|
|
|
|
- // rolling periods omit snapshot_dt
|
|
|
await user.click(screen.getByRole('button', { name: '近 7 天' }));
|
|
|
await waitFor(() => expect(lastPeriod()).toBe('last_7d'));
|
|
|
expect(lastReq()).toEqual({ period: 'last_7d' });
|