Skip to content

Commit 8a1689c

Browse files
committed
test(calendar): fold the scrollIntoView case into index.test.js
Review feedback: keep one unit test file per component instead of adding a new file per scenario. The scrollIntoView case now lives in index.test.js under its own describe block, and scroll-into-view.test.js is gone. No behaviour change.
1 parent 62d56ce commit 8a1689c

2 files changed

Lines changed: 45 additions & 49 deletions

File tree

‎packages/components/calendar/__test__/index.test.js‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,49 @@ describe('calendar', () => {
187187

188188
expect(instance.data.currentMonth[0].months[0].suffix).toBe('updated');
189189
});
190+
191+
describe('scrollIntoView', () => {
192+
const minDate = new Date(2016, 10, 1).getTime();
193+
const maxDate = new Date(2026, 11, 1).getTime();
194+
const rangeValue = [new Date(2022, 11, 5).getTime(), new Date(2022, 11, 10).getTime()];
195+
196+
let component;
197+
const renderRange = (props = {}) => {
198+
component = simulate.render(calendar, {
199+
minDate,
200+
maxDate,
201+
value: rangeValue,
202+
type: 'range',
203+
usePopup: true,
204+
visible: false,
205+
...props,
206+
});
207+
component.attach(document.createElement('parent-wrapper'));
208+
return component;
209+
};
210+
211+
afterEach(() => component?.detach());
212+
213+
it('positions on the selected month when opened (issue #4718)', async () => {
214+
renderRange();
215+
await simulate.sleep(20);
216+
217+
const inst = component.instance;
218+
219+
// 打开弹窗
220+
inst.setData({ visible: true });
221+
await simulate.sleep(30);
222+
223+
const { currentMonth, scrollIntoView } = inst.data;
224+
225+
// 选中区间在 2022 年 12 月,面板必须定位到该月
226+
expect(currentMonth[0]).toEqual(expect.objectContaining({ year: 2022, month: 11 }));
227+
expect(scrollIntoView).toBe('year_2022_month_11');
228+
229+
// 区间标记也要落在正确的日期上,否则定位到月份但高亮仍然错位
230+
const days = currentMonth[0].months;
231+
expect(days.find((d) => d.type === 'start')?.day).toBe(5);
232+
expect(days.find((d) => d.type === 'end')?.day).toBe(10);
233+
});
234+
});
190235
});

‎packages/components/calendar/__test__/scroll-into-view.test.js‎

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)