@tsed/react-formio 1.10.14 → 1.11.2
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/dist/components/card/card.component.d.ts +2 -1
- package/dist/components/loader/loader.component.d.ts +3 -3
- package/dist/components/loader/loader.stories.d.ts +15 -0
- package/dist/components/pagination/pagination.component.spec.d.ts +1 -0
- package/dist/components/pagination/pagination.stories.d.ts +0 -27
- package/dist/components/table/filters/selectColumnFilter.component.spec.d.ts +1 -0
- package/dist/index.js +18 -5
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +10 -3
- package/dist/index.modern.js.map +1 -1
- package/package.json +4 -4
- package/src/components/card/card.component.tsx +1 -0
- package/src/components/loader/loader.component.spec.tsx +7 -6
- package/src/components/loader/loader.component.tsx +3 -3
- package/src/components/loader/loader.stories.tsx +17 -0
- package/src/components/pagination/pagination.component.spec.tsx +137 -0
- package/src/components/pagination/pagination.component.tsx +2 -1
- package/src/components/pagination/pagination.stories.tsx +13 -29
- package/src/components/table/filters/selectColumnFilter.component.spec.tsx +54 -0
- package/src/components/table/filters/selectColumnFilter.component.tsx +8 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.2",
|
|
4
4
|
"description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.modern.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"prettier": "prettier '{src,test}/**/*.{ts,tsx}' --write"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tsed/redux-utils": "1.
|
|
17
|
+
"@tsed/redux-utils": "1.11.2",
|
|
18
18
|
"eventemitter2": "^6.4.3",
|
|
19
19
|
"prop-types": "^15.7.2"
|
|
20
20
|
},
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"tooltip.js": ">=1.3.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsed/tailwind": "1.
|
|
33
|
-
"@tsed/tailwind-formio": "1.
|
|
32
|
+
"@tsed/tailwind": "1.11.2",
|
|
33
|
+
"@tsed/tailwind-formio": "1.11.2",
|
|
34
34
|
"eslint-plugin-jsx-a11y": "^6.5.1"
|
|
35
35
|
},
|
|
36
36
|
"repository": "https://github.com/TypedProject/tsed-formio",
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { render } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { Sandbox } from "./loader.stories";
|
|
5
4
|
describe("Loader", () => {
|
|
6
|
-
it("should render a component (
|
|
7
|
-
const { getByTestId } = render(<
|
|
5
|
+
it("should render a component (when isActive = true)", () => {
|
|
6
|
+
const { getByTestId } = render(<Sandbox isActive={true} />);
|
|
8
7
|
|
|
9
8
|
const icon = getByTestId("icon_radio-circle");
|
|
10
9
|
|
|
11
10
|
expect(icon).toBeTruthy();
|
|
11
|
+
expect(icon).toBeInTheDocument();
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
it("should render a component (
|
|
15
|
-
const { queryByTestId } = render(<
|
|
14
|
+
it("should render a component (when isActive = false)", () => {
|
|
15
|
+
const { queryByTestId } = render(<Sandbox isActive={false} />);
|
|
16
16
|
|
|
17
17
|
const icon = queryByTestId("icon_radio-circle");
|
|
18
18
|
|
|
19
19
|
expect(icon).toBeFalsy();
|
|
20
|
+
expect(icon).not.toBeInTheDocument();
|
|
20
21
|
});
|
|
21
22
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import classnames from "classnames";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
|
-
import React from "react";
|
|
3
|
+
import React, { PropsWithChildren } from "react";
|
|
4
4
|
import { iconClass } from "../../utils/iconClass";
|
|
5
5
|
|
|
6
6
|
export interface LoaderProps {
|
|
@@ -15,7 +15,7 @@ export function Loader({
|
|
|
15
15
|
color = "blue",
|
|
16
16
|
icon = "radio-circle",
|
|
17
17
|
className = ""
|
|
18
|
-
}: LoaderProps) {
|
|
18
|
+
}: PropsWithChildren<LoaderProps>) {
|
|
19
19
|
if (isActive) {
|
|
20
20
|
return (
|
|
21
21
|
<div
|
|
@@ -37,7 +37,7 @@ export function Loader({
|
|
|
37
37
|
|
|
38
38
|
Loader.propTypes = {
|
|
39
39
|
isActive: PropTypes.bool,
|
|
40
|
-
icon: PropTypes.
|
|
40
|
+
icon: PropTypes.string,
|
|
41
41
|
color: PropTypes.string,
|
|
42
42
|
className: PropTypes.string
|
|
43
43
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Loader } from "./loader.component";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: "ReactFormio/Loader",
|
|
6
|
+
component: Loader,
|
|
7
|
+
argTypes: {},
|
|
8
|
+
parameters: {}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const Sandbox = (args: any) => {
|
|
12
|
+
return <Loader {...args} />;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
Sandbox.args = {
|
|
16
|
+
isActive: true
|
|
17
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Sandbox } from "./pagination.stories";
|
|
4
|
+
|
|
5
|
+
describe("Pagination", () => {
|
|
6
|
+
it("should render the pagination component", () => {
|
|
7
|
+
const { container, getByTestId, queryAllByTestId } = render(
|
|
8
|
+
<Sandbox {...Sandbox.args} />
|
|
9
|
+
);
|
|
10
|
+
const paginationBtn = queryAllByTestId("pagination-button");
|
|
11
|
+
const allBtnBlocks = paginationBtn.map((bloc) => bloc.textContent);
|
|
12
|
+
const select = getByTestId("select_page");
|
|
13
|
+
|
|
14
|
+
expect(container).toBeInTheDocument();
|
|
15
|
+
paginationBtn.forEach((child) => expect(child).toBeInTheDocument());
|
|
16
|
+
expect(select).toBeInTheDocument();
|
|
17
|
+
expect(allBtnBlocks[0]).toBe("Previous");
|
|
18
|
+
expect(allBtnBlocks[allBtnBlocks.length - 1]).toBe("Next");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should call previousPage() callback", () => {
|
|
22
|
+
const previousPageSpy = jest.fn();
|
|
23
|
+
const { queryAllByTestId } = render(
|
|
24
|
+
<Sandbox previousPage={previousPageSpy} canPreviousPage={true} />
|
|
25
|
+
);
|
|
26
|
+
const paginationBtn = queryAllByTestId("pagination-button");
|
|
27
|
+
const btnPreviousPage = paginationBtn.find(
|
|
28
|
+
(btn) => btn.textContent === "Previous"
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
fireEvent.click(btnPreviousPage);
|
|
32
|
+
|
|
33
|
+
expect(previousPageSpy).toHaveBeenCalledTimes(1);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should call nextPage() callback", () => {
|
|
37
|
+
const nextPageSpy = jest.fn();
|
|
38
|
+
render(<Sandbox nextPage={nextPageSpy} canNextPage={true} />);
|
|
39
|
+
|
|
40
|
+
fireEvent.click(screen.getByText(/Next/i));
|
|
41
|
+
|
|
42
|
+
expect(nextPageSpy).toHaveBeenCalledTimes(1);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should call gotoPage() callback when cliking on a button page", () => {
|
|
46
|
+
const gotoPageSpy = jest.fn();
|
|
47
|
+
let page: number;
|
|
48
|
+
|
|
49
|
+
const { queryAllByTestId } = render(
|
|
50
|
+
<Sandbox {...Sandbox.args} gotoPage={gotoPageSpy} />
|
|
51
|
+
);
|
|
52
|
+
const paginationBtn = queryAllByTestId("pagination-button");
|
|
53
|
+
const buttonsPage = paginationBtn.filter(
|
|
54
|
+
(btn) => btn.textContent !== "Previous" && btn.textContent !== "Next"
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
buttonsPage.forEach((btn) => {
|
|
58
|
+
if (btn.textContent !== "...") {
|
|
59
|
+
page = +btn.textContent;
|
|
60
|
+
fireEvent.click(btn);
|
|
61
|
+
expect(gotoPageSpy).toHaveBeenCalled();
|
|
62
|
+
expect(gotoPageSpy).toHaveBeenCalledWith(page - 1);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should have Previous button disabled and not clickable", () => {
|
|
68
|
+
const previousPageSpy = jest.fn();
|
|
69
|
+
const { getByText } = render(
|
|
70
|
+
<Sandbox
|
|
71
|
+
canPreviousPage={false}
|
|
72
|
+
previousPage={previousPageSpy}
|
|
73
|
+
{...Sandbox.args}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
const previousButton = getByText("Previous");
|
|
77
|
+
|
|
78
|
+
expect(previousButton).toHaveAttribute("disabled");
|
|
79
|
+
fireEvent.click(previousButton);
|
|
80
|
+
expect(previousPageSpy).not.toHaveBeenCalled();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should have Previous button NOT disabled and clickable", () => {
|
|
84
|
+
const previousPageSpy = jest.fn();
|
|
85
|
+
const { getByText } = render(
|
|
86
|
+
<Sandbox
|
|
87
|
+
{...Sandbox.args}
|
|
88
|
+
canPreviousPage={true}
|
|
89
|
+
previousPage={previousPageSpy}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const previousButton = getByText("Previous");
|
|
94
|
+
|
|
95
|
+
expect(previousButton).not.toHaveAttribute("disabled");
|
|
96
|
+
fireEvent.click(previousButton);
|
|
97
|
+
expect(previousPageSpy).toHaveBeenCalled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("should have Next button disabled and not clickable", () => {
|
|
101
|
+
const nextPageSpy = jest.fn();
|
|
102
|
+
const { getByText } = render(
|
|
103
|
+
<Sandbox canNextPage={false} nextPage={nextPageSpy} {...Sandbox.args} />
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const nextButton = getByText("Next");
|
|
107
|
+
expect(nextButton).toHaveAttribute("disabled");
|
|
108
|
+
fireEvent.click(nextButton);
|
|
109
|
+
expect(nextPageSpy).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should have Next button NOT disabled and clickable", () => {
|
|
113
|
+
const nextPageSpy = jest.fn();
|
|
114
|
+
const { getByText } = render(
|
|
115
|
+
<Sandbox canNextPage={true} nextPage={nextPageSpy} {...Sandbox.args} />
|
|
116
|
+
);
|
|
117
|
+
const nextButton = getByText("Next");
|
|
118
|
+
expect(nextButton).not.toHaveAttribute("disabled");
|
|
119
|
+
fireEvent.click(nextButton);
|
|
120
|
+
expect(nextPageSpy).toHaveBeenCalled();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should correctly render select component", () => {
|
|
124
|
+
const pageSizes = [10, 25, 50, 100, 200, 500];
|
|
125
|
+
|
|
126
|
+
const { getByTestId } = render(
|
|
127
|
+
<Sandbox {...Sandbox.args} pageSizes={pageSizes} />
|
|
128
|
+
);
|
|
129
|
+
const selectComp = getByTestId("select_page");
|
|
130
|
+
const selectChilds = Array.prototype.map.call(selectComp, function (child) {
|
|
131
|
+
return +child.textContent;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(selectComp).toBeInTheDocument();
|
|
135
|
+
expect(selectChilds.length === pageSizes.length).toBeTruthy();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -28,6 +28,7 @@ function PaginationButton(
|
|
|
28
28
|
return (
|
|
29
29
|
<Component
|
|
30
30
|
{...otherProps}
|
|
31
|
+
data-testid='pagination-button'
|
|
31
32
|
disabled={disabled}
|
|
32
33
|
className={classnames(
|
|
33
34
|
"page-link",
|
|
@@ -67,7 +68,7 @@ export function Pagination(props: PaginationProps) {
|
|
|
67
68
|
nextPage,
|
|
68
69
|
canNextPage,
|
|
69
70
|
pageCount,
|
|
70
|
-
pageIndex,
|
|
71
|
+
pageIndex = 1,
|
|
71
72
|
pageOptions,
|
|
72
73
|
pageSize,
|
|
73
74
|
setPageSize,
|
|
@@ -1,43 +1,27 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
2
|
import { Pagination } from "./pagination.component";
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
title: "ReactFormio/Pagination",
|
|
6
6
|
component: Pagination,
|
|
7
|
-
|
|
8
|
-
pageSizes: {
|
|
9
|
-
control: {
|
|
10
|
-
type: "object"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
pageCount: {
|
|
14
|
-
control: {
|
|
15
|
-
type: "number"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
pageIndex: {
|
|
19
|
-
control: {
|
|
20
|
-
type: "number"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
canPreviousPage: {
|
|
24
|
-
control: {
|
|
25
|
-
type: "boolean"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
canNextPage: {
|
|
29
|
-
control: {
|
|
30
|
-
type: "boolean"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
7
|
+
|
|
34
8
|
parameters: {}
|
|
35
9
|
};
|
|
36
10
|
|
|
37
11
|
export const Sandbox = (args: any) => {
|
|
12
|
+
const [currentPageIndex, setPageIndex] = useState(args.pageIndex);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
args.gotoPage && args.gotoPage(currentPageIndex);
|
|
16
|
+
}, [currentPageIndex]);
|
|
17
|
+
|
|
38
18
|
return (
|
|
39
19
|
<div>
|
|
40
|
-
<Pagination
|
|
20
|
+
<Pagination
|
|
21
|
+
{...args}
|
|
22
|
+
pageIndex={currentPageIndex}
|
|
23
|
+
gotoPage={setPageIndex}
|
|
24
|
+
/>
|
|
41
25
|
</div>
|
|
42
26
|
);
|
|
43
27
|
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import "@testing-library/jest-dom/extend-expect";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { SelectColumnFilter } from "./selectColumnFilter.component";
|
|
5
|
+
|
|
6
|
+
describe("SelectColumnFilter", () => {
|
|
7
|
+
it("should display select with choices", async () => {
|
|
8
|
+
const mockSetFilter = jest.fn();
|
|
9
|
+
const props = {
|
|
10
|
+
name: "data.id",
|
|
11
|
+
setFilter: mockSetFilter,
|
|
12
|
+
column: {
|
|
13
|
+
id: "id",
|
|
14
|
+
preFilteredRows: [
|
|
15
|
+
{ values: { id: "select-choice-1" } },
|
|
16
|
+
{ values: { id: "select-choice-2" } }
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const { getByText } = render(
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
<SelectColumnFilter {...props} />
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(getByText("select-choice-1")).toBeDefined();
|
|
28
|
+
expect(getByText("select-choice-2")).toBeDefined();
|
|
29
|
+
});
|
|
30
|
+
it("should display select with custom choices", async () => {
|
|
31
|
+
const mockSetFilter = jest.fn();
|
|
32
|
+
const props = {
|
|
33
|
+
name: "data.id",
|
|
34
|
+
setFilter: mockSetFilter,
|
|
35
|
+
column: {
|
|
36
|
+
id: "id",
|
|
37
|
+
preFilteredRows: [
|
|
38
|
+
{ values: { id: "select-choice-1" } },
|
|
39
|
+
{ values: { id: "select-choice-2" } }
|
|
40
|
+
],
|
|
41
|
+
choices: [{ label: "fake-choice", value: "fake-choice" }]
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const { queryByText, getByText } = render(
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
<SelectColumnFilter {...props} />
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(queryByText("select-choice-1")).toBeNull();
|
|
52
|
+
expect(getByText("fake-choice")).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -5,8 +5,14 @@ import { Select } from "../../select/select.component";
|
|
|
5
5
|
export function SelectColumnFilter<D extends Record<string, unknown> = {}>({
|
|
6
6
|
column
|
|
7
7
|
}: FilterProps<D>) {
|
|
8
|
-
const { filterValue, setFilter } = column;
|
|
9
|
-
const { choices
|
|
8
|
+
const { id, preFilteredRows, filterValue, setFilter } = column;
|
|
9
|
+
const { choices: customChoices } = column as any;
|
|
10
|
+
|
|
11
|
+
const choices =
|
|
12
|
+
customChoices ||
|
|
13
|
+
[...new Set(preFilteredRows.map((row) => row.values[id]))]
|
|
14
|
+
.filter((value) => value)
|
|
15
|
+
.map((value) => ({ label: value, value }));
|
|
10
16
|
|
|
11
17
|
return (
|
|
12
18
|
<Select
|