@neovici/cosmoz-queue 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,7 +9,7 @@ export const useMore = ({ params: _params, list$, pageSize = 50, setTotalAvailab
|
|
|
9
9
|
const hasMore = pageSize > 0 &&
|
|
10
10
|
totalAvailable < Infinity &&
|
|
11
11
|
totalAvailable >= pageSize &&
|
|
12
|
-
page < Math.ceil(totalAvailable / pageSize);
|
|
12
|
+
page < Math.ceil(totalAvailable / pageSize) - 1;
|
|
13
13
|
const loadMore = useMemo(() => hasMore ? () => setData((s) => ({ ...s, page: s.page + 1 })) : undefined, [hasMore]);
|
|
14
14
|
useEffect(() => setData((d) => ({
|
|
15
15
|
...d,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-more.test.d.ts","sourceRoot":"","sources":["../../../src/list/more/use-more.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
describe('hasMore logic', () => {
|
|
3
|
+
const calcHasMore = (totalAvailable, pageSize, page) => pageSize > 0 &&
|
|
4
|
+
totalAvailable < Infinity &&
|
|
5
|
+
totalAvailable >= pageSize &&
|
|
6
|
+
page < Math.ceil(totalAvailable / pageSize) - 1;
|
|
7
|
+
describe('60 items, pageSize 50', () => {
|
|
8
|
+
it('hasMore is true on page 0', () => {
|
|
9
|
+
expect(calcHasMore(60, 50, 0)).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
it('hasMore is false on page 1 (last page)', () => {
|
|
12
|
+
expect(calcHasMore(60, 50, 1)).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
describe('50 items, pageSize 50 (exactly one page)', () => {
|
|
16
|
+
it('hasMore is false on page 0', () => {
|
|
17
|
+
expect(calcHasMore(50, 50, 0)).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('100 items, pageSize 50 (exactly two pages)', () => {
|
|
21
|
+
it('hasMore is true on page 0', () => {
|
|
22
|
+
expect(calcHasMore(100, 50, 0)).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it('hasMore is false on page 1 (last page)', () => {
|
|
25
|
+
expect(calcHasMore(100, 50, 1)).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe('10 items, pageSize 50 (fewer than pageSize)', () => {
|
|
29
|
+
it('hasMore is false on page 0', () => {
|
|
30
|
+
expect(calcHasMore(10, 50, 0)).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('edge cases', () => {
|
|
34
|
+
it('returns false when pageSize is 0', () => {
|
|
35
|
+
expect(calcHasMore(60, 0, 0)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
it('returns false when totalAvailable is Infinity', () => {
|
|
38
|
+
expect(calcHasMore(Infinity, 50, 0)).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|