@pautena/react-design-system 0.1.1 → 0.1.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/package.json +1 -1
- package/.eslintrc.js +0 -26
- package/.github/workflows/ci.yml +0 -23
- package/.github/workflows/deploy-storybook.yaml +0 -23
- package/.github/workflows/publish.yml +0 -31
- package/.husky/pre-commit +0 -5
- package/.prettierignore +0 -5
- package/.storybook/main.js +0 -10
- package/.storybook/preview.js +0 -36
- package/babel.config.js +0 -13
- package/jest.config.js +0 -17
- package/jest.setup.ts +0 -5
- package/rollup.config.js +0 -52
- package/src/components/app-bar/app-bar.stories.tsx +0 -54
- package/src/components/app-bar/app-bar.test.tsx +0 -142
- package/src/components/app-bar/app-bar.tsx +0 -150
- package/src/components/app-bar/app-bar.types.ts +0 -17
- package/src/components/app-bar/index.ts +0 -3
- package/src/components/app-bar/mini-app-bar/index.ts +0 -1
- package/src/components/app-bar/mini-app-bar/mini-app-bar.tsx +0 -31
- package/src/components/bullet/bullet.stories.tsx +0 -43
- package/src/components/bullet/bullet.test.tsx +0 -24
- package/src/components/bullet/bullet.tsx +0 -30
- package/src/components/bullet/index.ts +0 -1
- package/src/components/center-container/center-container.stories.tsx +0 -50
- package/src/components/center-container/center-container.test.tsx +0 -16
- package/src/components/center-container/center-container.tsx +0 -32
- package/src/components/center-container/index.ts +0 -1
- package/src/components/content/content.stories.tsx +0 -23
- package/src/components/content/content.test.tsx +0 -26
- package/src/components/content/content.tsx +0 -11
- package/src/components/content/content.types.ts +0 -5
- package/src/components/content/index.ts +0 -2
- package/src/components/drawer/__snapshots__/drawer.test.tsx.snap +0 -20
- package/src/components/drawer/drawer.context.ts +0 -20
- package/src/components/drawer/drawer.mixins.ts +0 -24
- package/src/components/drawer/drawer.mock.tsx +0 -100
- package/src/components/drawer/drawer.provider.tsx +0 -23
- package/src/components/drawer/drawer.test.tsx +0 -97
- package/src/components/drawer/drawer.tsx +0 -30
- package/src/components/drawer/drawer.types.ts +0 -53
- package/src/components/drawer/index.ts +0 -5
- package/src/components/drawer/mini-drawer/index.ts +0 -1
- package/src/components/drawer/mini-drawer/mini-drawer.stories.tsx +0 -34
- package/src/components/drawer/mini-drawer/mini-drawer.tsx +0 -67
- package/src/components/drawer-content/drawer-content.stories.tsx +0 -29
- package/src/components/drawer-content/drawer-content.test.tsx +0 -34
- package/src/components/drawer-content/drawer-content.tsx +0 -18
- package/src/components/drawer-content/index.ts +0 -1
- package/src/components/drawer-item/drawer-item.stories.tsx +0 -62
- package/src/components/drawer-item/drawer-item.test.tsx +0 -119
- package/src/components/drawer-item/drawer-item.tsx +0 -71
- package/src/components/drawer-item/index.ts +0 -1
- package/src/components/drawer-section/drawer-section.mock.tsx +0 -39
- package/src/components/drawer-section/drawer-section.stories.tsx +0 -28
- package/src/components/drawer-section/drawer-section.test.tsx +0 -44
- package/src/components/drawer-section/drawer-section.tsx +0 -40
- package/src/components/drawer-section/index.ts +0 -1
- package/src/components/header/header.dummy.ts +0 -55
- package/src/components/header/header.stories.tsx +0 -116
- package/src/components/header/header.test.tsx +0 -169
- package/src/components/header/header.tsx +0 -121
- package/src/components/header/header.types.ts +0 -61
- package/src/components/header/index.ts +0 -2
- package/src/components/index.ts +0 -18
- package/src/components/label/index.ts +0 -1
- package/src/components/label/label.stories.tsx +0 -49
- package/src/components/label/label.test.tsx +0 -30
- package/src/components/label/label.tsx +0 -60
- package/src/components/link/index.ts +0 -1
- package/src/components/link/link.tsx +0 -17
- package/src/components/loading-area/index.ts +0 -1
- package/src/components/loading-area/loading-area.stories.tsx +0 -17
- package/src/components/loading-area/loading-area.test.tsx +0 -11
- package/src/components/loading-area/loading-area.tsx +0 -13
- package/src/components/placeholder/index.ts +0 -1
- package/src/components/placeholder/placeholder.mock.ts +0 -15
- package/src/components/placeholder/placeholder.stories.tsx +0 -44
- package/src/components/placeholder/placeholder.test.tsx +0 -76
- package/src/components/placeholder/placeholder.tsx +0 -75
- package/src/components/query-container/index.ts +0 -1
- package/src/components/query-container/query-container.stories.tsx +0 -68
- package/src/components/query-container/query-container.test.tsx +0 -95
- package/src/components/query-container/query-container.tsx +0 -71
- package/src/components/sign-in/index.ts +0 -1
- package/src/components/sign-in/sign-in.stories.tsx +0 -36
- package/src/components/sign-in/sign-in.test.tsx +0 -95
- package/src/components/sign-in/sign-in.tsx +0 -97
- package/src/components/tab/index.ts +0 -2
- package/src/components/tab/tab-card/index.ts +0 -1
- package/src/components/tab/tab-card/tab-card.dummy.tsx +0 -30
- package/src/components/tab/tab-card/tab-card.stories.tsx +0 -22
- package/src/components/tab/tab-card/tab-card.test.tsx +0 -53
- package/src/components/tab/tab-card/tab-card.tsx +0 -27
- package/src/components/tab/tab-panel/index.ts +0 -1
- package/src/components/tab/tab-panel/tab-panel.test.tsx +0 -26
- package/src/components/tab/tab-panel/tab-panel.tsx +0 -27
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.mock.tsx +0 -27
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.stories.tsx +0 -24
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.test.tsx +0 -77
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.tsx +0 -74
- package/src/components/table/enhanced-remote-table/index.ts +0 -1
- package/src/components/table/enhanced-table/enhanced-table-head.tsx +0 -58
- package/src/components/table/enhanced-table/enhanced-table.mock.tsx +0 -93
- package/src/components/table/enhanced-table/enhanced-table.stories.tsx +0 -21
- package/src/components/table/enhanced-table/enhanced-table.test.tsx +0 -107
- package/src/components/table/enhanced-table/enhanced-table.tsx +0 -136
- package/src/components/table/enhanced-table/index.ts +0 -2
- package/src/components/table/index.ts +0 -2
- package/src/components/table-list/index.ts +0 -1
- package/src/components/table-list/table-list.stories.tsx +0 -75
- package/src/components/table-list/table-list.test.tsx +0 -284
- package/src/components/table-list/table-list.tsx +0 -127
- package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +0 -35
- package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +0 -26
- package/src/components/value-displays/group-value-card/group-value-card.test.tsx +0 -58
- package/src/components/value-displays/group-value-card/group-value-card.tsx +0 -63
- package/src/components/value-displays/group-value-card/index.ts +0 -1
- package/src/components/value-displays/index.ts +0 -4
- package/src/components/value-displays/value-boolean/index.ts +0 -1
- package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +0 -25
- package/src/components/value-displays/value-boolean/value-boolean.test.tsx +0 -27
- package/src/components/value-displays/value-boolean/value-boolean.tsx +0 -33
- package/src/components/value-displays/value-card/index.ts +0 -1
- package/src/components/value-displays/value-card/value-card.stories.tsx +0 -22
- package/src/components/value-displays/value-card/value-card.test.tsx +0 -18
- package/src/components/value-displays/value-card/value-card.tsx +0 -12
- package/src/components/value-displays/value-text/index.ts +0 -1
- package/src/components/value-displays/value-text/value-test.test.tsx +0 -21
- package/src/components/value-displays/value-text/value-text.stories.tsx +0 -26
- package/src/components/value-displays/value-text/value-text.tsx +0 -32
- package/src/generators/generators.mock.ts +0 -238
- package/src/generators/generators.model.ts +0 -46
- package/src/generators/index.ts +0 -4
- package/src/generators/model-form/index.ts +0 -1
- package/src/generators/model-form/model-form.stories.tsx +0 -30
- package/src/generators/model-form/model-form.test.tsx +0 -100
- package/src/generators/model-form/model-form.tsx +0 -97
- package/src/generators/model-router/index.ts +0 -1
- package/src/generators/model-router/model-router.test.tsx +0 -666
- package/src/generators/model-router/model-router.tsx +0 -29
- package/src/generators/model-router/model-router.types.ts +0 -14
- package/src/generators/model-router/screens/add-screen.tsx +0 -69
- package/src/generators/model-router/screens/details-screen.tsx +0 -62
- package/src/generators/model-router/screens/index.ts +0 -4
- package/src/generators/model-router/screens/list-screen.tsx +0 -110
- package/src/generators/model-router/screens/screens.types.ts +0 -13
- package/src/generators/model-router/screens/update-screen.tsx +0 -96
- package/src/generators/model-router/stories/details-screen.stories.tsx +0 -38
- package/src/generators/model-router/stories/list-screen.stories.tsx +0 -45
- package/src/generators/model-router/stories/model-router.stories.tsx +0 -164
- package/src/generators/model-router/stories/templates.tsx +0 -39
- package/src/generators/object-details/index.ts +0 -1
- package/src/generators/object-details/object-details.stories.tsx +0 -20
- package/src/generators/object-details/object-details.test.tsx +0 -21
- package/src/generators/object-details/object-details.tsx +0 -76
- package/src/index.ts +0 -4
- package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.stories.tsx +0 -28
- package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.test.tsx +0 -30
- package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.tsx +0 -37
- package/src/layouts/app-bar-with-drawer-layout/index.ts +0 -1
- package/src/layouts/header-layout/header-layout.stories.tsx +0 -204
- package/src/layouts/header-layout/header-layout.test.tsx +0 -37
- package/src/layouts/header-layout/header-layout.tsx +0 -23
- package/src/layouts/header-layout/index.ts +0 -1
- package/src/layouts/index.ts +0 -2
- package/src/providers/index.ts +0 -2
- package/src/providers/notification-center/index.ts +0 -2
- package/src/providers/notification-center/notification-center.context.ts +0 -37
- package/src/providers/notification-center/notification-center.provider.tsx +0 -51
- package/src/providers/notification-center/notification-center.stories.tsx +0 -52
- package/src/providers/notification-center/notification-center.test.tsx +0 -112
- package/src/providers/tab-provider/index.ts +0 -2
- package/src/providers/tab-provider/tab-provider.context.ts +0 -8
- package/src/providers/tab-provider/tab-provider.provider.tsx +0 -13
- package/src/storybook.tsx +0 -90
- package/src/tests/assertions.ts +0 -76
- package/src/tests/components.tsx +0 -60
- package/src/tests/content-placeholder.stories.tsx +0 -16
- package/src/tests/index.ts +0 -3
- package/src/tests/skeleton-card.stories.tsx +0 -18
- package/src/tests/testing-library.tsx +0 -65
- package/src/utils/arrays.test.ts +0 -9
- package/src/utils/arrays.ts +0 -7
- package/src/utils/index.ts +0 -2
- package/src/utils/theme.ts +0 -11
- package/tsconfig.json +0 -25
- package/tsconfig.rollup.json +0 -28
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { expectProgressIndicator, render } from "../../../tests";
|
|
3
|
-
import { screen } from "@testing-library/react";
|
|
4
|
-
import userEvents from "@testing-library/user-event";
|
|
5
|
-
import { TestTable, columns, data } from "./enhanced-table.mock";
|
|
6
|
-
|
|
7
|
-
function renderInstance({
|
|
8
|
-
defaultSort = "startDate",
|
|
9
|
-
loading = false,
|
|
10
|
-
}: { defaultSort?: string; loading?: boolean } = {}) {
|
|
11
|
-
return render(
|
|
12
|
-
<TestTable
|
|
13
|
-
data={data}
|
|
14
|
-
columns={columns}
|
|
15
|
-
defaultSort={defaultSort}
|
|
16
|
-
defaultOrder="asc"
|
|
17
|
-
loading={loading}
|
|
18
|
-
/>,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe("EnhancedTable", () => {
|
|
23
|
-
it("all items are rendered in the correct order", async () => {
|
|
24
|
-
renderInstance();
|
|
25
|
-
|
|
26
|
-
expect(screen.getByText("Tabata")).toBeInTheDocument();
|
|
27
|
-
expect(screen.getByText("AMRAPx2")).toBeInTheDocument();
|
|
28
|
-
expect(screen.getByText("HIIT")).toBeInTheDocument();
|
|
29
|
-
expect(screen.getByText("on/off x 1")).toBeInTheDocument();
|
|
30
|
-
expect(screen.getByText("EMOM 30'")).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("loading is true a loading indicator is displayed", () => {
|
|
34
|
-
renderInstance({ loading: true });
|
|
35
|
-
|
|
36
|
-
expectProgressIndicator();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("all items are sorted by the default sort field", () => {
|
|
40
|
-
renderInstance({ defaultSort: "startDate" });
|
|
41
|
-
|
|
42
|
-
const rows = screen.queryAllByRole("row");
|
|
43
|
-
expect(rows[1]).toHaveTextContent("on/off x 1105/04/2022");
|
|
44
|
-
expect(rows[2]).toHaveTextContent("EMOM 30'307/04/2022");
|
|
45
|
-
expect(rows[3]).toHaveTextContent("Tabata409/04/2022");
|
|
46
|
-
expect(rows[4]).toHaveTextContent("AMRAPx2510/04/2022");
|
|
47
|
-
expect(rows[5]).toHaveTextContent("HIIT211/04/2022");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe("if I search an 'a'", () => {
|
|
51
|
-
it("only the Tabata and AMRAPx2 items appear", async () => {
|
|
52
|
-
renderInstance();
|
|
53
|
-
|
|
54
|
-
await userEvents.type(screen.getByPlaceholderText(/search/i), "a");
|
|
55
|
-
|
|
56
|
-
expect(screen.getByText("Tabata")).toBeInTheDocument();
|
|
57
|
-
expect(screen.getByText("AMRAPx2")).toBeInTheDocument();
|
|
58
|
-
|
|
59
|
-
expect(screen.queryByText("HIIT")).not.toBeInTheDocument();
|
|
60
|
-
expect(screen.queryByText("on/off x 1")).not.toBeInTheDocument();
|
|
61
|
-
expect(screen.queryByText("EMOM 30'")).not.toBeInTheDocument();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("and remove the search all items appear", async () => {
|
|
65
|
-
renderInstance();
|
|
66
|
-
|
|
67
|
-
const search = screen.getByPlaceholderText(/search/i);
|
|
68
|
-
await userEvents.type(search, "a");
|
|
69
|
-
await userEvents.clear(search);
|
|
70
|
-
|
|
71
|
-
expect(screen.getByText("Tabata")).toBeInTheDocument();
|
|
72
|
-
expect(screen.getByText("AMRAPx2")).toBeInTheDocument();
|
|
73
|
-
expect(screen.getByText("HIIT")).toBeInTheDocument();
|
|
74
|
-
expect(screen.getByText("on/off x 1")).toBeInTheDocument();
|
|
75
|
-
expect(screen.getByText("EMOM 30'")).toBeInTheDocument();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("If I click 'Garmin ID'", () => {
|
|
80
|
-
it("once it will be asc sorted", async () => {
|
|
81
|
-
renderInstance();
|
|
82
|
-
|
|
83
|
-
await userEvents.click(screen.getByText(/garmin id/i));
|
|
84
|
-
|
|
85
|
-
const rows = screen.queryAllByRole("row");
|
|
86
|
-
expect(rows[1]).toHaveTextContent("on/off x 1105/04/2022");
|
|
87
|
-
expect(rows[2]).toHaveTextContent("HIIT211/04/2022");
|
|
88
|
-
expect(rows[3]).toHaveTextContent("EMOM 30'307/04/2022");
|
|
89
|
-
expect(rows[4]).toHaveTextContent("Tabata409/04/2022");
|
|
90
|
-
expect(rows[5]).toHaveTextContent("AMRAPx2510/04/2022");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("two times it will be desc sorted", async () => {
|
|
94
|
-
renderInstance();
|
|
95
|
-
|
|
96
|
-
await userEvents.click(screen.getByText(/garmin id/i));
|
|
97
|
-
await userEvents.click(screen.getByText(/garmin id/i));
|
|
98
|
-
|
|
99
|
-
const rows = screen.queryAllByRole("row");
|
|
100
|
-
expect(rows[1]).toHaveTextContent("AMRAPx2510/04/2022");
|
|
101
|
-
expect(rows[2]).toHaveTextContent("Tabata409/04/2022");
|
|
102
|
-
expect(rows[3]).toHaveTextContent("EMOM 30'307/04/2022");
|
|
103
|
-
expect(rows[4]).toHaveTextContent("HIIT211/04/2022");
|
|
104
|
-
expect(rows[5]).toHaveTextContent("on/off x 1105/04/2022");
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import React, { ChangeEvent } from "react";
|
|
3
|
-
import { ReactNode, useState } from "react";
|
|
4
|
-
import {
|
|
5
|
-
Box,
|
|
6
|
-
TableContainer,
|
|
7
|
-
TextField,
|
|
8
|
-
TableBody,
|
|
9
|
-
InputAdornment,
|
|
10
|
-
Table,
|
|
11
|
-
CircularProgress,
|
|
12
|
-
TableCell,
|
|
13
|
-
TableRow,
|
|
14
|
-
} from "@mui/material";
|
|
15
|
-
import Search from "@mui/icons-material/Search";
|
|
16
|
-
import { EnhancedTableHead, HeadCell, Order } from "./enhanced-table-head";
|
|
17
|
-
|
|
18
|
-
function getFilter<T>(columns: HeadCell[], search: string) {
|
|
19
|
-
return (d: T) => {
|
|
20
|
-
return (
|
|
21
|
-
!search ||
|
|
22
|
-
columns.some((col) => {
|
|
23
|
-
let value = (d as any)[col.id];
|
|
24
|
-
if (value?.toLowerCase) {
|
|
25
|
-
value = value.toLowerCase();
|
|
26
|
-
}
|
|
27
|
-
return value?.toString().includes(search.toLowerCase());
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function getComparator(order: Order, orderBy: any): (a: any, b: any) => number {
|
|
34
|
-
return order === "desc"
|
|
35
|
-
? (a, b) => descendingComparator(a, b, orderBy)
|
|
36
|
-
: (a, b) => -descendingComparator(a, b, orderBy);
|
|
37
|
-
}
|
|
38
|
-
function descendingComparator<T>(a: T, b: T, orderBy: keyof T) {
|
|
39
|
-
if (b[orderBy] < a[orderBy]) {
|
|
40
|
-
return -1;
|
|
41
|
-
}
|
|
42
|
-
if (b[orderBy] > a[orderBy]) {
|
|
43
|
-
return 1;
|
|
44
|
-
}
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface Props<T> {
|
|
49
|
-
readonly data: T[];
|
|
50
|
-
search?: boolean;
|
|
51
|
-
defaultSort: string;
|
|
52
|
-
defaultOrder?: Order;
|
|
53
|
-
loading?: boolean;
|
|
54
|
-
columns: HeadCell[];
|
|
55
|
-
children: (data: T[]) => ReactNode;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const EnhancedTable = <T,>({
|
|
59
|
-
children,
|
|
60
|
-
data,
|
|
61
|
-
search,
|
|
62
|
-
columns,
|
|
63
|
-
defaultSort,
|
|
64
|
-
defaultOrder = "asc",
|
|
65
|
-
loading = false,
|
|
66
|
-
}: Props<T>) => {
|
|
67
|
-
const [searchFilter, setSearchFilter] = useState<string>("");
|
|
68
|
-
const [order, setOrder] = useState<Order>(defaultOrder);
|
|
69
|
-
const [orderBy, setOrderBy] = useState(defaultSort);
|
|
70
|
-
|
|
71
|
-
const handleRequestSort = (property: string) => {
|
|
72
|
-
const isAsc = orderBy === property && order === "asc";
|
|
73
|
-
setOrder(isAsc ? "desc" : "asc");
|
|
74
|
-
setOrderBy(property);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const filteredData = data
|
|
78
|
-
.slice()
|
|
79
|
-
.filter(getFilter<T>(columns, searchFilter))
|
|
80
|
-
.sort(getComparator(order, orderBy));
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<>
|
|
84
|
-
<Box sx={{ paddingX: 1, paddingBottom: 2 }}>
|
|
85
|
-
{search && (
|
|
86
|
-
<Box paddingY={2}>
|
|
87
|
-
<TextField
|
|
88
|
-
fullWidth
|
|
89
|
-
placeholder="Search"
|
|
90
|
-
InputProps={{
|
|
91
|
-
role: "search",
|
|
92
|
-
startAdornment: (
|
|
93
|
-
<InputAdornment position="start">
|
|
94
|
-
<Search />
|
|
95
|
-
</InputAdornment>
|
|
96
|
-
),
|
|
97
|
-
}}
|
|
98
|
-
onChange={(e: ChangeEvent<any>) => setSearchFilter(e.target.value)}
|
|
99
|
-
/>
|
|
100
|
-
</Box>
|
|
101
|
-
)}
|
|
102
|
-
<TableContainer>
|
|
103
|
-
<Table>
|
|
104
|
-
<EnhancedTableHead
|
|
105
|
-
order={order}
|
|
106
|
-
orderBy={orderBy}
|
|
107
|
-
headCells={columns}
|
|
108
|
-
onRequestSort={handleRequestSort}
|
|
109
|
-
/>
|
|
110
|
-
<TableBody>
|
|
111
|
-
{loading ? (
|
|
112
|
-
<TableRow>
|
|
113
|
-
<TableCell colSpan={columns.length} sx={{ textAlign: "center" }}>
|
|
114
|
-
<CircularProgress />
|
|
115
|
-
</TableCell>
|
|
116
|
-
</TableRow>
|
|
117
|
-
) : filteredData.length === 0 ? (
|
|
118
|
-
<TableRow>
|
|
119
|
-
<TableCell colSpan={columns.length} sx={{ textAlign: "center" }}>
|
|
120
|
-
No data
|
|
121
|
-
</TableCell>
|
|
122
|
-
</TableRow>
|
|
123
|
-
) : (
|
|
124
|
-
children(filteredData)
|
|
125
|
-
)}
|
|
126
|
-
</TableBody>
|
|
127
|
-
</Table>
|
|
128
|
-
</TableContainer>
|
|
129
|
-
</Box>
|
|
130
|
-
</>
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
EnhancedTable.defaultProps = {
|
|
135
|
-
defaultOrder: "asc",
|
|
136
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./table-list";
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { useDemoData } from "@mui/x-data-grid-generator";
|
|
3
|
-
import { ComponentMeta } from "@storybook/react";
|
|
4
|
-
import { createTemplate } from "../../storybook";
|
|
5
|
-
import { TableList } from "./table-list";
|
|
6
|
-
import { action } from "@storybook/addon-actions";
|
|
7
|
-
|
|
8
|
-
const maxColumns = 3;
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
title: "Tables/TableList",
|
|
12
|
-
component: TableList,
|
|
13
|
-
parameters: {
|
|
14
|
-
layout: "fullscreen",
|
|
15
|
-
},
|
|
16
|
-
} as ComponentMeta<typeof TableList>;
|
|
17
|
-
|
|
18
|
-
const Template = createTemplate(({ dataSetType, size, ...rest }) => {
|
|
19
|
-
const { data } = useDemoData({
|
|
20
|
-
dataSet: dataSetType,
|
|
21
|
-
rowLength: size,
|
|
22
|
-
maxColumns,
|
|
23
|
-
});
|
|
24
|
-
const { rows } = data;
|
|
25
|
-
const columns = data.columns.map(({ field, headerName }) => ({
|
|
26
|
-
id: field,
|
|
27
|
-
label: headerName,
|
|
28
|
-
sort: true,
|
|
29
|
-
disablePadding: false,
|
|
30
|
-
numeric: false,
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
return <TableList {...rest} columns={columns} data={rows} onClick={action("onClick row")} />;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
export const Default = Template.bind({});
|
|
37
|
-
Default.args = {
|
|
38
|
-
size: 40,
|
|
39
|
-
dataSetType: "Commodity",
|
|
40
|
-
search: true,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const Loading = Template.bind({});
|
|
44
|
-
Loading.args = {
|
|
45
|
-
size: 40,
|
|
46
|
-
dataSetType: "Commodity",
|
|
47
|
-
search: true,
|
|
48
|
-
loading: true,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const WihtoutSearch = Template.bind({});
|
|
52
|
-
WihtoutSearch.args = {
|
|
53
|
-
size: 40,
|
|
54
|
-
dataSetType: "Commodity",
|
|
55
|
-
search: false,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const WithOptions = Template.bind({});
|
|
59
|
-
WithOptions.args = {
|
|
60
|
-
size: 40,
|
|
61
|
-
dataSetType: "Commodity",
|
|
62
|
-
search: false,
|
|
63
|
-
options: [
|
|
64
|
-
{
|
|
65
|
-
id: "edit",
|
|
66
|
-
label: "Edit",
|
|
67
|
-
onClick: action("Option edit"),
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: "remove",
|
|
71
|
-
label: "Remove",
|
|
72
|
-
onClick: action("Option remove"),
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
};
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { expectProgressIndicator, render } from "../../tests";
|
|
3
|
-
import { screen } from "@testing-library/react";
|
|
4
|
-
import userEvents from "@testing-library/user-event";
|
|
5
|
-
import { TableRowOption, TableList } from "./table-list";
|
|
6
|
-
import { HeadCell } from "../table/enhanced-table";
|
|
7
|
-
import { BasicModelInstance } from "../../generators";
|
|
8
|
-
|
|
9
|
-
const columns: HeadCell[] = [
|
|
10
|
-
{
|
|
11
|
-
id: "id",
|
|
12
|
-
numeric: true,
|
|
13
|
-
disablePadding: false,
|
|
14
|
-
label: "Item ID",
|
|
15
|
-
sort: false,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: "name",
|
|
19
|
-
numeric: false,
|
|
20
|
-
disablePadding: false,
|
|
21
|
-
label: "Name",
|
|
22
|
-
sort: true,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
id: "value",
|
|
26
|
-
numeric: true,
|
|
27
|
-
disablePadding: false,
|
|
28
|
-
label: "Value",
|
|
29
|
-
sort: true,
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
const data: BasicModelInstance[] = [
|
|
33
|
-
{
|
|
34
|
-
id: "item-c",
|
|
35
|
-
name: "fg Item 1",
|
|
36
|
-
value: 1,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
id: "item-a",
|
|
40
|
-
name: "aa Item 2",
|
|
41
|
-
value: 2,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
id: "item-l",
|
|
45
|
-
name: "ba Item 3",
|
|
46
|
-
value: 3,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
id: "item-j",
|
|
50
|
-
name: "aa Item 4",
|
|
51
|
-
value: 4,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: "item-w",
|
|
55
|
-
name: "cd Item 5",
|
|
56
|
-
value: 5,
|
|
57
|
-
},
|
|
58
|
-
];
|
|
59
|
-
|
|
60
|
-
const options = [
|
|
61
|
-
{
|
|
62
|
-
id: "edit",
|
|
63
|
-
label: "Edit",
|
|
64
|
-
onClick: jest.fn(),
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: "remove",
|
|
68
|
-
label: "Remove",
|
|
69
|
-
onClick: jest.fn(),
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
describe("TableList", () => {
|
|
74
|
-
const renderInstance = ({
|
|
75
|
-
search = false,
|
|
76
|
-
defaultSort = "value",
|
|
77
|
-
loading = false,
|
|
78
|
-
options = undefined,
|
|
79
|
-
}: {
|
|
80
|
-
defaultSort?: string;
|
|
81
|
-
loading?: boolean;
|
|
82
|
-
search?: boolean;
|
|
83
|
-
options?: TableRowOption<any>[];
|
|
84
|
-
} = {}) => {
|
|
85
|
-
const onClick = jest.fn();
|
|
86
|
-
const instance = render(
|
|
87
|
-
<TableList
|
|
88
|
-
search={search}
|
|
89
|
-
data={data}
|
|
90
|
-
columns={columns}
|
|
91
|
-
defaultSort={defaultSort}
|
|
92
|
-
defaultOrder="asc"
|
|
93
|
-
loading={loading}
|
|
94
|
-
options={options}
|
|
95
|
-
onClick={onClick}
|
|
96
|
-
/>,
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
return { ...instance, onClick };
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const openOptionsMenu = async (index = 0) => {
|
|
103
|
-
await userEvents.click(screen.getAllByTestId("MoreVertIcon")[index]);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
it("would render all items and its values", () => {
|
|
107
|
-
renderInstance();
|
|
108
|
-
|
|
109
|
-
data.forEach(({ id, name, value }) => {
|
|
110
|
-
expect(screen.getByRole("cell", { name: id })).toBeInTheDocument();
|
|
111
|
-
expect(screen.getByRole("cell", { name: name })).toBeInTheDocument();
|
|
112
|
-
expect(screen.getByRole("cell", { name: value })).toBeInTheDocument();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("all items are rendered in the correct default order", async () => {
|
|
117
|
-
renderInstance();
|
|
118
|
-
|
|
119
|
-
[/item 1/i, /item 2/i, /item 3/i, /item 4/i, /item 5/i].forEach((item, index) => {
|
|
120
|
-
expect(screen.getByRole("cell", { name: item })).toHaveAttribute(
|
|
121
|
-
"aria-rowindex",
|
|
122
|
-
index.toString(),
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("loading is true a loading indicator is displayed", () => {
|
|
128
|
-
renderInstance({ loading: true });
|
|
129
|
-
|
|
130
|
-
expectProgressIndicator();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe("search", () => {
|
|
134
|
-
it("would render a search input if search is true", () => {
|
|
135
|
-
renderInstance({ search: true });
|
|
136
|
-
|
|
137
|
-
expect(screen.getByRole("search")).toBeInTheDocument();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("wouldn't render a search input if search is false", () => {
|
|
141
|
-
renderInstance({ search: false });
|
|
142
|
-
|
|
143
|
-
expect(screen.queryByRole("search")).not.toBeInTheDocument();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe("if I search an 'a'", () => {
|
|
148
|
-
it("would render the items 2,3 and 4", async () => {
|
|
149
|
-
renderInstance({ search: true });
|
|
150
|
-
|
|
151
|
-
await userEvents.type(screen.getByPlaceholderText(/search/i), "a");
|
|
152
|
-
|
|
153
|
-
expect(screen.getByText(/item 2/i)).toBeInTheDocument();
|
|
154
|
-
expect(screen.getByText(/item 3/i)).toBeInTheDocument();
|
|
155
|
-
expect(screen.getByText(/item 4/i)).toBeInTheDocument();
|
|
156
|
-
|
|
157
|
-
expect(screen.queryByText(/item 1/i)).not.toBeInTheDocument();
|
|
158
|
-
expect(screen.queryByText(/item 5/i)).not.toBeInTheDocument();
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("would render all the items if I remove the search", async () => {
|
|
162
|
-
renderInstance({ search: true });
|
|
163
|
-
|
|
164
|
-
const search = screen.getByPlaceholderText(/search/i);
|
|
165
|
-
await userEvents.type(search, "a");
|
|
166
|
-
await userEvents.clear(search);
|
|
167
|
-
|
|
168
|
-
expect(screen.getByText(/item 1/i)).toBeInTheDocument();
|
|
169
|
-
expect(screen.getByText(/item 2/i)).toBeInTheDocument();
|
|
170
|
-
expect(screen.getByText(/item 3/i)).toBeInTheDocument();
|
|
171
|
-
expect(screen.getByText(/item 4/i)).toBeInTheDocument();
|
|
172
|
-
expect(screen.getByText(/item 5/i)).toBeInTheDocument();
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe("sort by a sortable column", () => {
|
|
177
|
-
it("once it will be asc sorted", async () => {
|
|
178
|
-
renderInstance();
|
|
179
|
-
|
|
180
|
-
await userEvents.click(screen.getByText(/name/i));
|
|
181
|
-
|
|
182
|
-
expect(screen.getByRole("cell", { name: /item 2/i })).toHaveAttribute("aria-rowindex", "0");
|
|
183
|
-
expect(screen.getByRole("cell", { name: /item 4/i })).toHaveAttribute("aria-rowindex", "1");
|
|
184
|
-
expect(screen.getByRole("cell", { name: /item 3/i })).toHaveAttribute("aria-rowindex", "2");
|
|
185
|
-
expect(screen.getByRole("cell", { name: /item 5/i })).toHaveAttribute("aria-rowindex", "3");
|
|
186
|
-
expect(screen.getByRole("cell", { name: /item 1/i })).toHaveAttribute("aria-rowindex", "4");
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("two times it will be desc sorted", async () => {
|
|
190
|
-
renderInstance();
|
|
191
|
-
|
|
192
|
-
await userEvents.click(screen.getByText(/name/i));
|
|
193
|
-
await userEvents.click(screen.getByText(/name/i));
|
|
194
|
-
|
|
195
|
-
expect(screen.getByRole("cell", { name: /item 1/i })).toHaveAttribute("aria-rowindex", "0");
|
|
196
|
-
expect(screen.getByRole("cell", { name: /item 5/i })).toHaveAttribute("aria-rowindex", "1");
|
|
197
|
-
expect(screen.getByRole("cell", { name: /item 3/i })).toHaveAttribute("aria-rowindex", "2");
|
|
198
|
-
expect(screen.getByRole("cell", { name: /item 4/i })).toHaveAttribute("aria-rowindex", "3");
|
|
199
|
-
expect(screen.getByRole("cell", { name: /item 2/i })).toHaveAttribute("aria-rowindex", "4");
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("sort a non sortable column", async () => {
|
|
204
|
-
renderInstance();
|
|
205
|
-
|
|
206
|
-
await userEvents.click(screen.getByText(/id/i));
|
|
207
|
-
|
|
208
|
-
expect(screen.getByRole("cell", { name: /item 1/i })).toHaveAttribute("aria-rowindex", "0");
|
|
209
|
-
expect(screen.getByRole("cell", { name: /item 2/i })).toHaveAttribute("aria-rowindex", "1");
|
|
210
|
-
expect(screen.getByRole("cell", { name: /item 3/i })).toHaveAttribute("aria-rowindex", "2");
|
|
211
|
-
expect(screen.getByRole("cell", { name: /item 4/i })).toHaveAttribute("aria-rowindex", "3");
|
|
212
|
-
expect(screen.getByRole("cell", { name: /item 5/i })).toHaveAttribute("aria-rowindex", "4");
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("would call onClick if a row is clicked", async () => {
|
|
216
|
-
const { onClick } = renderInstance();
|
|
217
|
-
|
|
218
|
-
await userEvents.click(screen.getByRole("row", { name: /item 3/i }));
|
|
219
|
-
|
|
220
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
221
|
-
expect(onClick).toHaveBeenCalledWith(data[2]);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe("options menu", () => {
|
|
225
|
-
it("would render a button to open the menu if doesn't have options", () => {
|
|
226
|
-
renderInstance({ options: undefined });
|
|
227
|
-
|
|
228
|
-
expect(screen.queryByTestId("MoreVertIcon")).not.toBeInTheDocument();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("would render a button to open the menu if has options", () => {
|
|
232
|
-
renderInstance({ options });
|
|
233
|
-
|
|
234
|
-
screen.getAllByTestId("MoreVertIcon");
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("would render a menu if has options", async () => {
|
|
238
|
-
renderInstance({ options });
|
|
239
|
-
|
|
240
|
-
await openOptionsMenu();
|
|
241
|
-
|
|
242
|
-
expect(await screen.findByRole("menu")).toBeInTheDocument();
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it.each([
|
|
246
|
-
[/edit/i, 0],
|
|
247
|
-
[/remove/i, 1],
|
|
248
|
-
])("would call the option onClick with the row if %s option is clicked", async (name, i) => {
|
|
249
|
-
const index = 1;
|
|
250
|
-
const item = data[index];
|
|
251
|
-
const option = options[i];
|
|
252
|
-
|
|
253
|
-
renderInstance({ options });
|
|
254
|
-
|
|
255
|
-
await openOptionsMenu(index);
|
|
256
|
-
|
|
257
|
-
await userEvents.click(screen.getByRole("menuitem", { name }));
|
|
258
|
-
|
|
259
|
-
expect(option.onClick).toHaveBeenCalledTimes(1);
|
|
260
|
-
expect(option.onClick).toHaveBeenCalledWith(item);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("would close the menu when an option is clicked", async () => {
|
|
264
|
-
const index = 1;
|
|
265
|
-
|
|
266
|
-
renderInstance({ options });
|
|
267
|
-
|
|
268
|
-
await openOptionsMenu(index);
|
|
269
|
-
await userEvents.click(screen.getByRole("menuitem", { name: /edit/i }));
|
|
270
|
-
|
|
271
|
-
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it("wouldn't call the component onClick if an option if clicked", async () => {
|
|
275
|
-
const { onClick } = renderInstance({ options });
|
|
276
|
-
|
|
277
|
-
await openOptionsMenu();
|
|
278
|
-
|
|
279
|
-
await userEvents.click(screen.getByRole("menuitem", { name: /edit/i }));
|
|
280
|
-
|
|
281
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
});
|