|
|
@@ -84,10 +84,10 @@ describe('FunnelPage — fixed funnel + period selection', () => {
|
|
|
for (const label of ['近 7 天', '近 30 天']) {
|
|
|
expect(screen.getByRole('button', { name: label })).toBeInTheDocument();
|
|
|
}
|
|
|
- // 单日 segment opens the calendar (aria-label) and shows "单日".
|
|
|
+ // 单日 segment opens the calendar (aria-label) and shows the date (默认昨日).
|
|
|
const picker = screen.getByRole('button', { name: '选择历史日期' });
|
|
|
expect(picker).toBeInTheDocument();
|
|
|
- expect(picker).toHaveTextContent('单日');
|
|
|
+ expect(picker).toHaveTextContent(yesterdayParam());
|
|
|
});
|
|
|
|
|
|
/** Last request body the spy was invoked with. */
|
|
|
@@ -101,14 +101,22 @@ describe('FunnelPage — fixed funnel + period selection', () => {
|
|
|
return lastReq()?.period;
|
|
|
}
|
|
|
|
|
|
- it('auto-queries with default 单日 (latest available day) on first render', async () => {
|
|
|
+ /** 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 () => {
|
|
|
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' });
|
|
|
+ expect(lastReq()).toEqual({ period: 'day', snapshot_dt: yesterdayParam() });
|
|
|
expect(queryFunnelMock).toHaveBeenCalledTimes(1);
|
|
|
});
|
|
|
|
|
|
@@ -180,44 +188,26 @@ describe('FunnelPage — fixed funnel + period selection', () => {
|
|
|
await waitFor(() => expect(lastPeriod()).toBe('day'));
|
|
|
});
|
|
|
|
|
|
- it('单日 segment defaults to 最新 (latest available day)', async () => {
|
|
|
+ it('单日 segment defaults to yesterday', async () => {
|
|
|
queryFunnelMock.mockResolvedValue(readyResponse());
|
|
|
renderPage();
|
|
|
|
|
|
await waitFor(() => expect(lastPeriod()).toBe('day'));
|
|
|
const picker = screen.getByRole('button', { name: '选择历史日期' });
|
|
|
expect(picker).toBeInTheDocument();
|
|
|
- expect(picker).toHaveTextContent('最新');
|
|
|
+ expect(picker).toHaveTextContent(yesterdayParam());
|
|
|
});
|
|
|
|
|
|
- it('default day omits snapshot_dt; a picked date sends it, then 最新 clears it', async () => {
|
|
|
+ it('default day sends snapshot_dt = yesterday; rolling periods omit it', async () => {
|
|
|
queryFunnelMock.mockResolvedValue(readyResponse());
|
|
|
const user = userEvent.setup();
|
|
|
renderPage();
|
|
|
|
|
|
- // default 单日 (latest) omits snapshot_dt
|
|
|
+ // default 单日 sends snapshot_dt = yesterday
|
|
|
await waitFor(() => expect(lastPeriod()).toBe('day'));
|
|
|
- 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();
|
|
|
+ expect(lastReq()).toEqual({ period: 'day', snapshot_dt: yesterdayParam() });
|
|
|
|
|
|
+ // 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' });
|