@uxf/core-react 11.42.0 → 11.46.0
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.
- package/hooks/_use-simulated-button.js +3 -0
- package/hooks/use-pagination.test.d.ts +1 -0
- package/hooks/use-pagination.test.js +58 -0
- package/hooks/use-window-scroll.test.d.ts +1 -0
- package/hooks/use-window-scroll.test.js +47 -0
- package/hooks/use-window-size.test.d.ts +1 -0
- package/hooks/use-window-size.test.js +36 -0
- package/package.json +2 -2
- package/utils/compose-refs.test.d.ts +1 -0
- package/utils/compose-refs.test.js +41 -0
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports._useSimulatedButton = _useSimulatedButton;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, isSubmitType, }) {
|
|
6
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
6
7
|
const _onClick = (0, react_1.useCallback)((e) => {
|
|
7
8
|
var _a;
|
|
8
9
|
if ((isClickable || isHyperlink) && analyticsCallback) {
|
|
@@ -23,6 +24,7 @@ function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onCl
|
|
|
23
24
|
e.preventDefault();
|
|
24
25
|
}
|
|
25
26
|
}, [analyticsCallback, isClickable, isHyperlink, onClick, isSubmitType]);
|
|
27
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
26
28
|
const _onKeyUp = (0, react_1.useCallback)((e) => {
|
|
27
29
|
if (isClickable && (e.key === "Enter" || e.key === " ")) {
|
|
28
30
|
e.target.dispatchEvent(new MouseEvent("click", {
|
|
@@ -36,6 +38,7 @@ function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onCl
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
}, [isClickable, onKeyUp]);
|
|
41
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
39
42
|
const _onKeyDown = (0, react_1.useCallback)((e) => {
|
|
40
43
|
if (isClickable && e.key === " ") {
|
|
41
44
|
e.preventDefault();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("@testing-library/react");
|
|
4
|
+
const use_pagination_1 = require("./use-pagination");
|
|
5
|
+
describe("usePagination Hook", () => {
|
|
6
|
+
it("should return correct pagination items based on config", () => {
|
|
7
|
+
const mockConfig = {
|
|
8
|
+
showFirstButton: true,
|
|
9
|
+
hidePrevButton: false,
|
|
10
|
+
boundaryCount: 2,
|
|
11
|
+
siblingCount: 1,
|
|
12
|
+
hideNextButton: false,
|
|
13
|
+
showLastButton: true,
|
|
14
|
+
page: 11,
|
|
15
|
+
count: 100,
|
|
16
|
+
};
|
|
17
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_pagination_1.usePagination)(mockConfig));
|
|
18
|
+
const paginationItems = result.current;
|
|
19
|
+
expect(paginationItems[0]).toBe("first");
|
|
20
|
+
expect(paginationItems[1]).toBe("previous");
|
|
21
|
+
expect(paginationItems[2]).toBe(1);
|
|
22
|
+
expect(paginationItems[3]).toBe(2);
|
|
23
|
+
expect(paginationItems[4]).toBe("start-ellipsis");
|
|
24
|
+
expect(paginationItems[5]).toBe(10);
|
|
25
|
+
expect(paginationItems[6]).toBe(11);
|
|
26
|
+
expect(paginationItems[7]).toBe(12);
|
|
27
|
+
expect(paginationItems[8]).toBe("end-ellipsis");
|
|
28
|
+
expect(paginationItems[9]).toBe(99);
|
|
29
|
+
expect(paginationItems[10]).toBe(100);
|
|
30
|
+
expect(paginationItems[11]).toBe("next");
|
|
31
|
+
expect(paginationItems[12]).toBe("last");
|
|
32
|
+
});
|
|
33
|
+
it("should return correct pagination items with hidden 'Previous' and 'Next' buttons", () => {
|
|
34
|
+
const mockConfigHidePrevNext = {
|
|
35
|
+
showFirstButton: true,
|
|
36
|
+
hidePrevButton: true,
|
|
37
|
+
boundaryCount: 1,
|
|
38
|
+
siblingCount: 2,
|
|
39
|
+
hideNextButton: true,
|
|
40
|
+
showLastButton: true,
|
|
41
|
+
page: 4,
|
|
42
|
+
count: 20,
|
|
43
|
+
};
|
|
44
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_pagination_1.usePagination)(mockConfigHidePrevNext));
|
|
45
|
+
const paginationItems = result.current;
|
|
46
|
+
expect(paginationItems[0]).toBe("first");
|
|
47
|
+
expect(paginationItems[1]).toBe(1);
|
|
48
|
+
expect(paginationItems[2]).toBe(2);
|
|
49
|
+
expect(paginationItems[3]).toBe(3);
|
|
50
|
+
expect(paginationItems[4]).toBe(4);
|
|
51
|
+
expect(paginationItems[5]).toBe(5);
|
|
52
|
+
expect(paginationItems[6]).toBe(6);
|
|
53
|
+
expect(paginationItems[7]).toBe(7);
|
|
54
|
+
expect(paginationItems[8]).toBe("end-ellipsis");
|
|
55
|
+
expect(paginationItems[9]).toBe(20);
|
|
56
|
+
expect(paginationItems[10]).toBe("last");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("@testing-library/react");
|
|
4
|
+
const use_window_scroll_1 = require("./use-window-scroll");
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
window.scrollX = 0;
|
|
7
|
+
window.scrollY = 0;
|
|
8
|
+
window.addEventListener = jest.fn((event, callback) => {
|
|
9
|
+
if (event === "scroll") {
|
|
10
|
+
window.scrollHandler = callback;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
window.removeEventListener = jest.fn();
|
|
14
|
+
});
|
|
15
|
+
jest.mock("./use-raf-state", () => ({
|
|
16
|
+
useRafState: jest.fn().mockImplementation(() => {
|
|
17
|
+
const state = { x: window.scrollX, y: window.scrollY };
|
|
18
|
+
const setState = jest.fn((newState) => {
|
|
19
|
+
state.x = newState.x;
|
|
20
|
+
state.y = newState.y;
|
|
21
|
+
});
|
|
22
|
+
return [state, setState];
|
|
23
|
+
}),
|
|
24
|
+
}));
|
|
25
|
+
afterAll(() => {
|
|
26
|
+
jest.clearAllMocks();
|
|
27
|
+
});
|
|
28
|
+
describe("useWindowScroll", () => {
|
|
29
|
+
it("should return the initial scroll position", () => {
|
|
30
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_window_scroll_1.useWindowScroll)());
|
|
31
|
+
expect(result.current).toEqual({ x: 0, y: 0 });
|
|
32
|
+
});
|
|
33
|
+
it("should update scroll position on window scroll", () => {
|
|
34
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_window_scroll_1.useWindowScroll)());
|
|
35
|
+
(0, react_1.act)(() => {
|
|
36
|
+
window.scrollX = 100;
|
|
37
|
+
window.scrollY = 200;
|
|
38
|
+
window.scrollHandler();
|
|
39
|
+
});
|
|
40
|
+
expect(result.current).toEqual({ x: 100, y: 200 });
|
|
41
|
+
});
|
|
42
|
+
it("should clean up the event listener on unmount", () => {
|
|
43
|
+
const { unmount } = (0, react_1.renderHook)(() => (0, use_window_scroll_1.useWindowScroll)());
|
|
44
|
+
unmount();
|
|
45
|
+
expect(window.removeEventListener).toHaveBeenCalledWith("scroll", expect.any(Function));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("@testing-library/react");
|
|
4
|
+
const use_window_size_1 = require("./use-window-size");
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
window.innerWidth = 1024;
|
|
7
|
+
window.innerHeight = 768;
|
|
8
|
+
window.resizeHandler = null;
|
|
9
|
+
window.addEventListener = jest.fn((event, callback) => {
|
|
10
|
+
if (event === "resize") {
|
|
11
|
+
window.resizeHandler = callback;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
window.removeEventListener = jest.fn();
|
|
15
|
+
});
|
|
16
|
+
jest.mock("./use-raf-state", () => ({
|
|
17
|
+
useRafState: jest.fn().mockImplementation(() => {
|
|
18
|
+
const state = { width: window.innerWidth, height: window.innerHeight };
|
|
19
|
+
const setState = jest.fn();
|
|
20
|
+
return [state, setState];
|
|
21
|
+
}),
|
|
22
|
+
}));
|
|
23
|
+
afterAll(() => {
|
|
24
|
+
jest.clearAllMocks();
|
|
25
|
+
});
|
|
26
|
+
describe("useWindowSize", () => {
|
|
27
|
+
it("should return the initial window size", () => {
|
|
28
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_window_size_1.useWindowSize)());
|
|
29
|
+
expect(result.current).toEqual({ width: 1024, height: 768 });
|
|
30
|
+
});
|
|
31
|
+
it("should clean up the event listener on unmount", () => {
|
|
32
|
+
const { unmount } = (0, react_1.renderHook)(() => (0, use_window_size_1.useWindowSize)());
|
|
33
|
+
unmount();
|
|
34
|
+
expect(window.removeEventListener).toHaveBeenCalledWith("resize", expect.any(Function));
|
|
35
|
+
});
|
|
36
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/core-react",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.46.0",
|
|
4
4
|
"description": "UXF Core",
|
|
5
5
|
"author": "UX Fans s.r.o",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@uxf/core": "11.
|
|
15
|
+
"@uxf/core": "11.46.0"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react": ">=18.2.0"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const compose_refs_1 = require("./compose-refs");
|
|
4
|
+
describe("composeRefs", () => {
|
|
5
|
+
it("should call ref if it is a function", () => {
|
|
6
|
+
const refCallback = jest.fn();
|
|
7
|
+
const composedRef = (0, compose_refs_1.composeRefs)(refCallback);
|
|
8
|
+
composedRef("test-value");
|
|
9
|
+
expect(refCallback).toHaveBeenCalledWith("test-value");
|
|
10
|
+
});
|
|
11
|
+
it("should assign value to a MutableRefObject", () => {
|
|
12
|
+
const refObject = { current: null };
|
|
13
|
+
const composedRef = (0, compose_refs_1.composeRefs)(refObject);
|
|
14
|
+
composedRef("test-value");
|
|
15
|
+
expect(refObject.current).toBe("test-value");
|
|
16
|
+
});
|
|
17
|
+
it("should ignore undefined refs", () => {
|
|
18
|
+
const composedRef = (0, compose_refs_1.composeRefs)(undefined);
|
|
19
|
+
expect(() => composedRef("test-value")).not.toThrow();
|
|
20
|
+
});
|
|
21
|
+
it("should handle both function and MutableRefObject refs", () => {
|
|
22
|
+
const refCallback = jest.fn();
|
|
23
|
+
const refObject = { current: null };
|
|
24
|
+
const composedRef = (0, compose_refs_1.composeRefs)(refCallback, refObject);
|
|
25
|
+
composedRef("test-value");
|
|
26
|
+
expect(refCallback).toHaveBeenCalledWith("test-value");
|
|
27
|
+
expect(refObject.current).toBe("test-value");
|
|
28
|
+
});
|
|
29
|
+
it("should handle multiple refs", () => {
|
|
30
|
+
const refCallback1 = jest.fn();
|
|
31
|
+
const refCallback2 = jest.fn();
|
|
32
|
+
const refObject1 = { current: null };
|
|
33
|
+
const refObject2 = { current: null };
|
|
34
|
+
const composedRef = (0, compose_refs_1.composeRefs)(refCallback1, refObject1, refCallback2, refObject2);
|
|
35
|
+
composedRef("test-value");
|
|
36
|
+
expect(refCallback1).toHaveBeenCalledWith("test-value");
|
|
37
|
+
expect(refCallback2).toHaveBeenCalledWith("test-value");
|
|
38
|
+
expect(refObject1.current).toBe("test-value");
|
|
39
|
+
expect(refObject2.current).toBe("test-value");
|
|
40
|
+
});
|
|
41
|
+
});
|