Skip to content

Commit 5b03506

Browse files
committed
update test cases
1 parent a0eb149 commit 5b03506

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

tests/__snapshots__/listy.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ exports[`Listy should match snapshot 1`] = `
66
class="rc-listy"
77
>
88
<div
9-
class="rc-virtual-list"
9+
class="rc-listy"
1010
style="position: relative;"
1111
>
1212
<div
13-
class="rc-virtual-list-holder"
13+
class="rc-listy-holder"
1414
>
1515
<div>
1616
<div
17-
class="rc-virtual-list-holder-inner"
17+
class="rc-listy-holder-inner"
1818
style="display: flex; flex-direction: column;"
1919
>
2020
<div>

tests/hooks.test.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type { ExtraRenderInfo } from 'rc-virtual-list/lib/interface';
66
import { useGroupSegments, useStickyGroupHeader } from '../src/hooks';
77
import type { StickyHeaderParams } from '../src/hooks/useStickyGroupHeader';
88

9+
const PREFIX_CLS = 'rc-listy';
10+
911
interface GroupedItem {
1012
id: number;
1113
group: string;
@@ -173,14 +175,14 @@ describe('useStickyGroupHeader', () => {
173175
nativeElement: container,
174176
getScrollInfo: () => ({ x: 0, y: info.start }),
175177
}),
176-
prefixCls: 'rc-listy',
178+
prefixCls: PREFIX_CLS,
177179
};
178180

179181
const { unmount } = render(
180182
<StickyHeaderTester params={params} info={info} />,
181183
);
182184

183-
const stickyHeader = container.querySelector('.rc-listy-sticky-header');
185+
const stickyHeader = container.querySelector(`.${PREFIX_CLS}-sticky-header`);
184186
expect(stickyHeader).not.toBeNull();
185187
expect(stickyHeader).toHaveTextContent('Group 2-3');
186188
expect(title).toHaveBeenCalledWith('Group 2', baseItems.slice(3, 6));
@@ -205,12 +207,12 @@ describe('useStickyGroupHeader', () => {
205207
groupKeyToItems: baseItemsMap,
206208
containerRef,
207209
listRef: createListRef({ nativeElement: container }),
208-
prefixCls: 'rc-listy',
210+
prefixCls: PREFIX_CLS,
209211
};
210212

211213
const { unmount } = render(<StickyHeaderTester params={params} info={info} />);
212214

213-
const stickyHeader = container.querySelector('.rc-listy-sticky-header');
215+
const stickyHeader = container.querySelector(`.${PREFIX_CLS}-sticky-header`);
214216
expect(stickyHeader).toBeNull();
215217

216218
unmount();
@@ -250,14 +252,14 @@ describe('useStickyGroupHeader', () => {
250252
groupKeyToItems: baseItemsMap,
251253
containerRef,
252254
listRef,
253-
prefixCls: 'rc-listy',
255+
prefixCls: PREFIX_CLS,
254256
};
255257

256258
const { unmount } = render(
257259
<StickyHeaderTester params={params} info={info} />,
258260
);
259261

260-
const stickyHeader = container.querySelector('.rc-listy-sticky-header');
262+
const stickyHeader = container.querySelector(`.${PREFIX_CLS}-sticky-header`);
261263
expect(stickyHeader).not.toBeNull();
262264
expect(stickyHeader).toHaveTextContent('Group 2');
263265
expect(title).toHaveBeenCalledWith('Group 2', baseItems.slice(3, 6));
@@ -268,7 +270,7 @@ describe('useStickyGroupHeader', () => {
268270

269271
it('prefers holder scrollTop over virtual start', () => {
270272
const holder = document.createElement('div');
271-
holder.className = 'rc-virtual-list-holder';
273+
holder.className = `${PREFIX_CLS}-holder`;
272274
holder.scrollTop = 80;
273275

274276
const container = document.createElement('div');
@@ -308,14 +310,14 @@ describe('useStickyGroupHeader', () => {
308310
groupKeyToItems: baseItemsMap,
309311
containerRef,
310312
listRef,
311-
prefixCls: 'rc-listy',
313+
prefixCls: PREFIX_CLS,
312314
};
313315

314316
const { unmount } = render(
315317
<StickyHeaderTester params={params} info={info} />,
316318
);
317319

318-
const stickyHeader = container.querySelector('.rc-listy-sticky-header');
320+
const stickyHeader = container.querySelector(`.${PREFIX_CLS}-sticky-header`);
319321
expect(stickyHeader).not.toBeNull();
320322
expect(stickyHeader).toHaveTextContent('Group 2');
321323

tests/onEndReached.test.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Listy, { type ListyRef } from '@rc-component/listy';
44

55
const DEFAULT_HEIGHT = 200;
66
const DEFAULT_ITEM_HEIGHT = 30;
7+
const PREFIX_CLS = 'rc-listy';
78

89
const createItems = (count: number) =>
910
Array.from({ length: count }, (_, i) => ({ id: i }));
@@ -62,7 +63,7 @@ describe('Listy - onEndReached', () => {
6263
);
6364

6465
const scrollContainer = container.querySelector(
65-
'.rc-virtual-list-holder',
66+
`.${PREFIX_CLS}-holder`,
6667
)!;
6768

6869
scrollToBottom(scrollContainer, items.length);
@@ -86,7 +87,7 @@ describe('Listy - onEndReached', () => {
8687
);
8788

8889
const scrollContainer = container.querySelector(
89-
'.rc-virtual-list-holder',
90+
`.${PREFIX_CLS}-holder`,
9091
)!;
9192

9293
// Not at bottom: scrollTop + clientHeight < scrollHeight
@@ -115,7 +116,7 @@ describe('Listy - onEndReached', () => {
115116
);
116117

117118
const scrollContainer = container.querySelector(
118-
'.rc-virtual-list-holder',
119+
`.${PREFIX_CLS}-holder`,
119120
)!;
120121

121122
// Should not throw error
@@ -148,7 +149,7 @@ describe('Listy - onEndReached', () => {
148149
);
149150

150151
const scrollContainer = container.querySelector(
151-
'.rc-virtual-list-holder',
152+
`.${PREFIX_CLS}-holder`,
152153
)!;
153154

154155
// Scroll to bottom
@@ -183,7 +184,7 @@ describe('Listy - onEndReached', () => {
183184

184185
const { container, rerender } = render(renderList(itemCount));
185186
const scrollContainer = container.querySelector(
186-
'.rc-virtual-list-holder',
187+
`.${PREFIX_CLS}-holder`,
187188
)!;
188189

189190
const scrollToBottomWithCount = () => {
@@ -229,7 +230,7 @@ describe('Listy - onEndReached', () => {
229230

230231
const { container, rerender } = render(renderList(itemCount));
231232
const scrollContainer = container.querySelector(
232-
'.rc-virtual-list-holder',
233+
`.${PREFIX_CLS}-holder`,
233234
)!;
234235

235236
const scrollToBottomWithCount = () => {
@@ -284,7 +285,7 @@ describe('Listy - onEndReached', () => {
284285

285286
const { container, getByTestId } = render(<LoadMoreComponent />);
286287
const scrollContainer = container.querySelector(
287-
'.rc-virtual-list-holder',
288+
`.${PREFIX_CLS}-holder`,
288289
)!;
289290

290291
// Initial state
@@ -352,7 +353,7 @@ describe('Listy - onEndReached', () => {
352353
<ScrollToEndComponent />,
353354
);
354355
const scrollContainer = container.querySelector(
355-
'.rc-virtual-list-holder',
356+
`.${PREFIX_CLS}-holder`,
356357
)!;
357358
const scrollButton = getByRole('button', { name: /scroll to end/i });
358359

@@ -402,7 +403,7 @@ describe('Listy - onEndReached', () => {
402403
);
403404

404405
const scrollContainer = container.querySelector(
405-
'.rc-virtual-list-holder',
406+
`.${PREFIX_CLS}-holder`,
406407
)!;
407408

408409
// Content height equals container height (already at bottom)
@@ -432,7 +433,7 @@ describe('Listy - onEndReached', () => {
432433
);
433434

434435
const scrollContainer = container.querySelector(
435-
'.rc-virtual-list-holder',
436+
`.${PREFIX_CLS}-holder`,
436437
)!;
437438

438439
mockScroll(scrollContainer, 0, 0, DEFAULT_HEIGHT);
@@ -458,7 +459,7 @@ describe('Listy - onEndReached', () => {
458459
);
459460

460461
const scrollContainer = container.querySelector(
461-
'.rc-virtual-list-holder',
462+
`.${PREFIX_CLS}-holder`,
462463
)!;
463464

464465
// Slightly past bottom (can happen during animation)
@@ -494,7 +495,7 @@ describe('Listy - onEndReached', () => {
494495

495496
const { container, rerender } = render(renderList(itemCount));
496497
const scrollContainer = container.querySelector(
497-
'.rc-virtual-list-holder',
498+
`.${PREFIX_CLS}-holder`,
498499
)!;
499500

500501
const scrollTo = (scrollTop: number) => {
@@ -556,7 +557,7 @@ describe('Listy - onEndReached', () => {
556557
);
557558

558559
const scrollContainer = container.querySelector(
559-
'.rc-virtual-list-holder',
560+
`.${PREFIX_CLS}-holder`,
560561
)!;
561562

562563
// Scroll to bottom with groups (items + headers)

0 commit comments

Comments
 (0)