@truedat/auth 8.14.1 → 8.14.3

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.
Files changed (65) hide show
  1. package/package.json +4 -4
  2. package/src/groups/components/EditGroup.js +64 -20
  3. package/src/groups/components/Group.js +39 -41
  4. package/src/groups/components/GroupCard.js +51 -54
  5. package/src/groups/components/GroupCards.js +60 -25
  6. package/src/groups/components/GroupDeleteModal.js +98 -0
  7. package/src/groups/components/GroupDropdown.js +92 -0
  8. package/src/groups/components/GroupForm.js +165 -84
  9. package/src/groups/components/GroupFormModal.js +137 -0
  10. package/src/groups/components/GroupInfoModal.js +114 -0
  11. package/src/groups/components/GroupMemberPicker.js +364 -0
  12. package/src/groups/components/GroupRouteModal.js +46 -0
  13. package/src/groups/components/GroupUsers.js +31 -14
  14. package/src/groups/components/GroupUsersTable.js +136 -83
  15. package/src/groups/components/NewGroup.js +38 -10
  16. package/src/groups/components/__tests__/EditGroup.spec.js +105 -0
  17. package/src/groups/components/__tests__/Group.spec.js +29 -47
  18. package/src/groups/components/__tests__/GroupCard.spec.js +8 -20
  19. package/src/groups/components/__tests__/GroupDropdown.spec.js +27 -0
  20. package/src/groups/components/__tests__/GroupForm.spec.js +32 -5
  21. package/src/groups/components/__tests__/GroupMemberPicker.spec.js +378 -0
  22. package/src/groups/components/__tests__/GroupModals.spec.js +210 -0
  23. package/src/groups/components/__tests__/GroupUsers.spec.js +17 -2
  24. package/src/groups/components/__tests__/GroupUsersTable.spec.js +34 -2
  25. package/src/groups/components/__tests__/__snapshots__/Group.spec.js.snap +1 -0
  26. package/src/groups/components/__tests__/__snapshots__/GroupCard.spec.js.snap +32 -30
  27. package/src/groups/components/__tests__/__snapshots__/GroupCards.spec.js.snap +90 -77
  28. package/src/groups/components/__tests__/__snapshots__/GroupUsers.spec.js.snap +75 -11
  29. package/src/groups/components/__tests__/__snapshots__/GroupUsersTable.spec.js.snap +70 -13
  30. package/src/groups/components/index.js +0 -4
  31. package/src/groups/hooks/__tests__/useGroupOperation.spec.js +167 -0
  32. package/src/groups/hooks/__tests__/useGroups.spec.js +90 -0
  33. package/src/groups/hooks/useGroupOperation.js +83 -0
  34. package/src/groups/hooks/useGroups.js +64 -0
  35. package/src/groups/reducers/index.js +0 -4
  36. package/src/groups/routines.js +0 -7
  37. package/src/groups/sagas/index.js +2 -24
  38. package/src/hooks/useRoles.js +6 -3
  39. package/src/styles/Groups.less +1009 -0
  40. package/src/users/components/AdminUserRoutes.js +1 -14
  41. package/src/users/components/GroupUserCrumbs.js +7 -12
  42. package/src/users/components/UserRoutes.js +12 -35
  43. package/src/users/components/UsersAndGroups.js +3 -6
  44. package/src/users/components/__tests__/GroupUserCrumbs.spec.js +26 -30
  45. package/src/users/components/__tests__/UserRoutes.spec.js +4 -6
  46. package/src/users/components/__tests__/UsersAndGroups.spec.js +5 -7
  47. package/src/users/components/__tests__/__snapshots__/UserRoutes.spec.js.snap +9 -55
  48. package/src/groups/components/GroupLoader.js +0 -27
  49. package/src/groups/components/GroupsLoader.js +0 -30
  50. package/src/groups/components/__tests__/GroupLoader.spec.js +0 -71
  51. package/src/groups/components/__tests__/__snapshots__/GroupLoader.spec.js.snap +0 -11
  52. package/src/groups/reducers/__tests__/groupRedirect.spec.js +0 -51
  53. package/src/groups/reducers/__tests__/groupUsers.spec.js +0 -60
  54. package/src/groups/reducers/group.js +0 -56
  55. package/src/groups/reducers/groupRedirect.js +0 -20
  56. package/src/groups/reducers/groupUsers.js +0 -16
  57. package/src/groups/reducers/groups.js +0 -29
  58. package/src/groups/sagas/__tests__/deleteGroup.spec.js +0 -93
  59. package/src/groups/sagas/__tests__/deleteGroupUser.spec.js +0 -80
  60. package/src/groups/sagas/createGroup.js +0 -27
  61. package/src/groups/sagas/deleteGroup.js +0 -31
  62. package/src/groups/sagas/deleteGroupUser.js +0 -35
  63. package/src/groups/sagas/fetchGroup.js +0 -30
  64. package/src/groups/sagas/fetchGroups.js +0 -26
  65. package/src/groups/sagas/updateGroup.js +0 -28
@@ -15,8 +15,6 @@ import {
15
15
  USERS_NEW,
16
16
  USER_EDIT_PASSWORD,
17
17
  } from "@truedat/core/routes";
18
- import GroupsLoader from "../../groups/components/GroupsLoader";
19
- import GroupLoader from "../../groups/components/GroupLoader";
20
18
  import Group from "../../groups/components/Group";
21
19
  import GroupUsers from "../../groups/components/GroupUsers";
22
20
  import NewGroup from "../../groups/components/NewGroup";
@@ -30,13 +28,6 @@ import UsersAndGroups from "./UsersAndGroups";
30
28
  import UsersLoader from "./UsersLoader";
31
29
  import UserPassword from "./UserPassword";
32
30
 
33
- const UsersGroupsLoader = () => (
34
- <>
35
- <UsersLoader />
36
- <GroupsLoader />
37
- </>
38
- );
39
-
40
31
  const UserRoutes = () => (
41
32
  <Routes>
42
33
  <Route index element={<UsersAndGroups />} />
@@ -56,7 +47,6 @@ const GroupRoutes = () => (
56
47
  path={GROUP_EDIT}
57
48
  element={
58
49
  <>
59
- <GroupLoader />
60
50
  <EditGroup />
61
51
  </>
62
52
  }
@@ -67,7 +57,6 @@ const GroupRoutes = () => (
67
57
  <>
68
58
  <GroupUserCrumbs action="show" />
69
59
  <Segment>
70
- <GroupLoader />
71
60
  <Group />
72
61
  <Divider />
73
62
  <GroupUsers />
@@ -82,12 +71,10 @@ const GroupRoutes = () => (
82
71
 
83
72
  export const AdminUserRoutes = () => {
84
73
  const authorized = useAuthorized();
85
- const groupsActive = useActiveRoute(GROUPS);
86
74
  const usersActive = useActiveRoute(USERS);
87
- const active = groupsActive || usersActive;
88
75
  return (
89
76
  <>
90
- {authorized && active && <UsersGroupsLoader />}
77
+ {authorized && usersActive && <UsersLoader />}
91
78
  <Routes>
92
79
  <Route
93
80
  path={USERS}
@@ -1,12 +1,14 @@
1
1
  import PropTypes from "prop-types";
2
2
  import { Breadcrumb } from "semantic-ui-react";
3
- import { connect } from "react-redux";
4
- import { Link } from "react-router";
3
+ import { Link, useParams } from "react-router";
5
4
  import { FormattedMessage } from "react-intl";
6
5
  import { GROUPS, linkTo } from "@truedat/core/routes";
6
+ import { useGroup } from "../../groups/hooks/useGroups";
7
7
 
8
- export const GroupUserCrumbs = ({ group, groupLoading, action }) => {
9
- if (groupLoading) return null;
8
+ export const GroupUserCrumbs = ({ action }) => {
9
+ const { id } = useParams();
10
+ const { group, loading } = useGroup(id);
11
+ if (loading || !group) return null;
10
12
  return group.name ? (
11
13
  <Breadcrumb>
12
14
  <Breadcrumb.Section as={Link} to={GROUPS} active={false}>
@@ -37,14 +39,7 @@ export const GroupUserCrumbs = ({ group, groupLoading, action }) => {
37
39
  };
38
40
 
39
41
  GroupUserCrumbs.propTypes = {
40
- group: PropTypes.object,
41
- groupLoading: PropTypes.bool,
42
42
  action: PropTypes.string,
43
43
  };
44
44
 
45
- const mapStateToProps = ({ group, groupLoading }) => ({
46
- group,
47
- groupLoading,
48
- });
49
-
50
- export default connect(mapStateToProps)(GroupUserCrumbs);
45
+ export default GroupUserCrumbs;
@@ -1,16 +1,9 @@
1
- import { Routes, Route } from "react-router";
1
+ import { Routes, Route, Outlet } from "react-router";
2
2
  import { ProtectedRoute, Loader } from "@truedat/core/router";
3
- import { Divider, Segment } from "semantic-ui-react";
3
+ import GroupRouteModal from "../../groups/components/GroupRouteModal";
4
4
 
5
- import GroupsLoader from "../../groups/components/GroupsLoader";
6
- import GroupLoader from "../../groups/components/GroupLoader";
7
- import Group from "../../groups/components/Group";
8
- import GroupUsers from "../../groups/components/GroupUsers";
9
- import NewGroup from "../../groups/components/NewGroup";
10
- import EditGroup from "../../groups/components/EditGroup";
11
5
  import Password from "./Password";
12
6
  import EditUser from "./EditUser";
13
- import GroupUserCrumbs from "./GroupUserCrumbs";
14
7
  import NewUser from "./NewUser";
15
8
  import User from "./User";
16
9
  import UserLoader from "./UserLoader";
@@ -18,20 +11,13 @@ import UsersAndGroups from "./UsersAndGroups";
18
11
  import UsersLoader from "./UsersLoader";
19
12
  import UserPassword from "./UserPassword";
20
13
 
21
- const UsersGroupsLoader = () => (
22
- <>
23
- <UsersLoader />
24
- <GroupsLoader />
25
- </>
26
- );
27
-
28
14
  export const UserRoutes = () => (
29
15
  <Routes>
30
16
  <Route
31
17
  path={"users"}
32
18
  element={
33
19
  <ProtectedRoute>
34
- <Loader loaders={<UsersGroupsLoader />} />
20
+ <Loader loaders={<UsersLoader />} />
35
21
  </ProtectedRoute>
36
22
  }
37
23
  >
@@ -48,28 +34,19 @@ export const UserRoutes = () => (
48
34
  path={"groups"}
49
35
  element={
50
36
  <ProtectedRoute>
51
- <Loader loaders={<UsersGroupsLoader />} />
37
+ <>
38
+ <UsersAndGroups />
39
+ <Outlet />
40
+ </>
52
41
  </ProtectedRoute>
53
42
  }
54
43
  >
55
- <Route index element={<UsersAndGroups />} />
56
- <Route path={"new"} element={<NewGroup />} />
44
+ <Route index element={null} />
45
+ <Route path={"new"} element={<GroupRouteModal mode="new" />} />
57
46
 
58
- <Route path={":id"} element={<Loader loaders={<GroupLoader />} />}>
59
- <Route
60
- index
61
- element={
62
- <>
63
- <GroupUserCrumbs action="show" />
64
- <Segment>
65
- <Group />
66
- <Divider />
67
- <GroupUsers />
68
- </Segment>
69
- </>
70
- }
71
- />
72
- <Route path={"edit"} element={<EditGroup />} />
47
+ <Route path={":id"}>
48
+ <Route index element={<GroupRouteModal mode="info" />} />
49
+ <Route path={"edit"} element={<GroupRouteModal mode="edit" />} />
73
50
  </Route>
74
51
  </Route>
75
52
  <Route path={"password"} element={<Password />} />
@@ -1,10 +1,9 @@
1
- import { connect } from "react-redux";
2
1
  import { Route, Routes } from "react-router";
3
2
  import { Header, Icon, Segment } from "semantic-ui-react";
4
3
  import { FormattedMessage, useIntl } from "react-intl";
5
4
  import { usePath } from "@truedat/core/hooks";
6
5
  import { GROUPS, USERS } from "@truedat/core/routes";
7
- import GroupCards from "../../groups/components/GroupCards";
6
+ import { GroupsList } from "../../groups/components/GroupCards";
8
7
  import UserCards from "./UserCards";
9
8
  import UserTabs from "./UserTabs";
10
9
 
@@ -32,12 +31,10 @@ export const UsersAndGroups = () => {
32
31
  <UserTabs />
33
32
  <Segment attached="bottom">
34
33
  {path === USERS && <UserCards />}
35
- {path === GROUPS && <GroupCards />}
34
+ {(path === GROUPS || path.startsWith(`${GROUPS}/`)) && <GroupsList />}
36
35
  </Segment>
37
36
  </Segment>
38
37
  );
39
38
  };
40
39
 
41
- const mapStateToProps = ({ usersLoading }) => ({ usersLoading });
42
-
43
- export default connect(mapStateToProps)(UsersAndGroups);
40
+ export default UsersAndGroups;
@@ -1,6 +1,9 @@
1
1
  import { render } from "@truedat/test/render";
2
+ import { useGroup } from "../../../groups/hooks/useGroups";
2
3
  import { GroupUserCrumbs } from "../GroupUserCrumbs";
3
4
 
5
+ jest.mock("../../../groups/hooks/useGroups", () => ({ useGroup: jest.fn() }));
6
+
4
7
  describe("<GroupUserCrumbs />", () => {
5
8
  const group = {
6
9
  id: "1",
@@ -8,51 +11,46 @@ describe("<GroupUserCrumbs />", () => {
8
11
  alias: "Admins",
9
12
  };
10
13
 
14
+ beforeEach(() => {
15
+ useGroup.mockReturnValue({ group, loading: false });
16
+ });
17
+
11
18
  it("renders alias when action is show", () => {
12
- const rendered = render(
13
- <GroupUserCrumbs group={group} action="show" groupLoading={false} />,
14
- );
19
+ const rendered = render(<GroupUserCrumbs action="show" />);
15
20
 
16
21
  expect(rendered.getByText("Admins")).toBeInTheDocument();
17
22
  expect(rendered.queryByText("administrators")).not.toBeInTheDocument();
18
23
  });
19
24
 
20
25
  it("renders alias link when action is add", () => {
21
- const rendered = render(
22
- <GroupUserCrumbs group={group} action="add" groupLoading={false} />,
23
- );
26
+ const rendered = render(<GroupUserCrumbs action="add" />);
24
27
 
25
28
  expect(rendered.getByRole("link", { name: /Admins/i })).toBeInTheDocument();
26
29
  });
27
30
 
28
31
  it("renders nothing while group is loading", () => {
29
- const rendered = render(
30
- <GroupUserCrumbs group={group} action="show" groupLoading />,
31
- );
32
+ useGroup.mockReturnValue({ group, loading: true });
33
+ const rendered = render(<GroupUserCrumbs action="show" />);
32
34
 
33
35
  expect(rendered.container).toBeEmptyDOMElement();
34
36
  });
35
37
 
36
38
  it("renders nothing when group has no name", () => {
37
- const rendered = render(
38
- <GroupUserCrumbs
39
- group={{ id: "1", name: "", alias: "Admins" }}
40
- action="show"
41
- groupLoading={false}
42
- />,
43
- );
39
+ useGroup.mockReturnValue({
40
+ group: { id: "1", name: "", alias: "Admins" },
41
+ loading: false,
42
+ });
43
+ const rendered = render(<GroupUserCrumbs action="show" />);
44
44
 
45
45
  expect(rendered.container).toBeEmptyDOMElement();
46
46
  });
47
47
 
48
48
  it("renders group name when alias is missing", () => {
49
- const rendered = render(
50
- <GroupUserCrumbs
51
- group={{ id: "1", name: "administrators" }}
52
- action="add"
53
- groupLoading={false}
54
- />,
55
- );
49
+ useGroup.mockReturnValue({
50
+ group: { id: "1", name: "administrators" },
51
+ loading: false,
52
+ });
53
+ const rendered = render(<GroupUserCrumbs action="add" />);
56
54
 
57
55
  expect(
58
56
  rendered.getByRole("link", { name: /administrators/i }),
@@ -60,13 +58,11 @@ describe("<GroupUserCrumbs />", () => {
60
58
  });
61
59
 
62
60
  it("renders group name on show when alias is missing", () => {
63
- const rendered = render(
64
- <GroupUserCrumbs
65
- group={{ id: "1", name: "administrators" }}
66
- action="show"
67
- groupLoading={false}
68
- />,
69
- );
61
+ useGroup.mockReturnValue({
62
+ group: { id: "1", name: "administrators" },
63
+ loading: false,
64
+ });
65
+ const rendered = render(<GroupUserCrumbs action="show" />);
70
66
 
71
67
  expect(rendered.getByText(/administrators/i)).toBeInTheDocument();
72
68
  });
@@ -14,14 +14,12 @@ jest.mock("@truedat/core/hooks/useAuthorized", () => ({
14
14
  useAuthorized: jest.fn(() => true),
15
15
  }));
16
16
 
17
+ jest.mock("../../../groups/components/GroupRouteModal", () => ({ mode }) => (
18
+ <div>GroupRouteModal:{mode}</div>
19
+ ));
20
+
17
21
  // Mock all components used in UserRoutes
18
22
  jest.mock("../Password", () => () => <div>Password</div>);
19
- jest.mock("../../../groups/components/GroupsLoader", () => () => (
20
- <div>GroupsLoader</div>
21
- ));
22
- jest.mock("../../../groups/components/GroupLoader", () => () => (
23
- <div>GroupLoader</div>
24
- ));
25
23
  jest.mock("../../../groups/components/Group", () => () => <div>Group</div>);
26
24
  jest.mock("../../../groups/components/GroupUsers", () => () => (
27
25
  <div>GroupUsers</div>
@@ -17,13 +17,11 @@ jest.mock(
17
17
  return <div>UserTabs</div>;
18
18
  },
19
19
  );
20
- jest.mock(
21
- "../../../groups/components/GroupCards",
22
- () =>
23
- function GroupCards() {
24
- return <div>GroupCards</div>;
25
- },
26
- );
20
+ jest.mock("../../../groups/components/GroupCards", () => ({
21
+ GroupsList() {
22
+ return <div>GroupCards</div>;
23
+ },
24
+ }));
27
25
 
28
26
  describe("<UsersAndGroups />", () => {
29
27
  it("renders correctly with default route", async () => {
@@ -12,12 +12,6 @@ exports[`<UserRoutes /> renders correctly with default route 1`] = `<div />`;
12
12
 
13
13
  exports[`<UserRoutes /> renders correctly with groups route 1`] = `
14
14
  <div>
15
- <div>
16
- UsersLoader
17
- </div>
18
- <div>
19
- GroupsLoader
20
- </div>
21
15
  <div>
22
16
  UsersAndGroups
23
17
  </div>
@@ -27,29 +21,11 @@ exports[`<UserRoutes /> renders correctly with groups route 1`] = `
27
21
  exports[`<UserRoutes /> renders correctly with groups/:id route 1`] = `
28
22
  <div>
29
23
  <div>
30
- UsersLoader
31
- </div>
32
- <div>
33
- GroupsLoader
34
- </div>
35
- <div>
36
- GroupLoader
24
+ UsersAndGroups
37
25
  </div>
38
26
  <div>
39
- GroupUserCrumbs
40
- </div>
41
- <div
42
- class="ui segment"
43
- >
44
- <div>
45
- Group
46
- </div>
47
- <div
48
- class="ui divider"
49
- />
50
- <div>
51
- GroupUsers
52
- </div>
27
+ GroupRouteModal:
28
+ info
53
29
  </div>
54
30
  </div>
55
31
  `;
@@ -57,16 +33,11 @@ exports[`<UserRoutes /> renders correctly with groups/:id route 1`] = `
57
33
  exports[`<UserRoutes /> renders correctly with groups/:id/edit route 1`] = `
58
34
  <div>
59
35
  <div>
60
- UsersLoader
61
- </div>
62
- <div>
63
- GroupsLoader
64
- </div>
65
- <div>
66
- GroupLoader
36
+ UsersAndGroups
67
37
  </div>
68
38
  <div>
69
- EditGroup
39
+ GroupRouteModal:
40
+ edit
70
41
  </div>
71
42
  </div>
72
43
  `;
@@ -74,13 +45,11 @@ exports[`<UserRoutes /> renders correctly with groups/:id/edit route 1`] = `
74
45
  exports[`<UserRoutes /> renders correctly with groups/new route 1`] = `
75
46
  <div>
76
47
  <div>
77
- UsersLoader
78
- </div>
79
- <div>
80
- GroupsLoader
48
+ UsersAndGroups
81
49
  </div>
82
50
  <div>
83
- NewGroup
51
+ GroupRouteModal:
52
+ new
84
53
  </div>
85
54
  </div>
86
55
  `;
@@ -90,9 +59,6 @@ exports[`<UserRoutes /> renders correctly with users route 1`] = `
90
59
  <div>
91
60
  UsersLoader
92
61
  </div>
93
- <div>
94
- GroupsLoader
95
- </div>
96
62
  <div>
97
63
  UsersAndGroups
98
64
  </div>
@@ -104,9 +70,6 @@ exports[`<UserRoutes /> renders correctly with users/:id route 1`] = `
104
70
  <div>
105
71
  UsersLoader
106
72
  </div>
107
- <div>
108
- GroupsLoader
109
- </div>
110
73
  <div>
111
74
  UserLoader
112
75
  </div>
@@ -121,9 +84,6 @@ exports[`<UserRoutes /> renders correctly with users/:id/edit route 1`] = `
121
84
  <div>
122
85
  UsersLoader
123
86
  </div>
124
- <div>
125
- GroupsLoader
126
- </div>
127
87
  <div>
128
88
  UserLoader
129
89
  </div>
@@ -138,9 +98,6 @@ exports[`<UserRoutes /> renders correctly with users/:id/password route 1`] = `
138
98
  <div>
139
99
  UsersLoader
140
100
  </div>
141
- <div>
142
- GroupsLoader
143
- </div>
144
101
  <div>
145
102
  UserLoader
146
103
  </div>
@@ -155,9 +112,6 @@ exports[`<UserRoutes /> renders correctly with users/new route 1`] = `
155
112
  <div>
156
113
  UsersLoader
157
114
  </div>
158
- <div>
159
- GroupsLoader
160
- </div>
161
115
  <div>
162
116
  NewUser
163
117
  </div>
@@ -1,27 +0,0 @@
1
- import { useEffect } from "react";
2
- import { useParams } from "react-router";
3
- import { useDispatch, useSelector } from "react-redux";
4
- import Loading from "@truedat/core/components/Loading";
5
- import { clearGroup, fetchGroup } from "../routines";
6
-
7
- const GroupLoader = () => {
8
- const dispatch = useDispatch();
9
- const groupLoading = useSelector((state) => state.groupLoading);
10
- const { id } = useParams();
11
-
12
- useEffect(() => {
13
- if (id) {
14
- dispatch(fetchGroup({ id }));
15
- } else {
16
- dispatch(clearGroup());
17
- }
18
-
19
- return () => {
20
- dispatch(clearGroup());
21
- };
22
- }, [dispatch, id]);
23
-
24
- return groupLoading ? <Loading /> : null;
25
- };
26
-
27
- export default GroupLoader;
@@ -1,30 +0,0 @@
1
- import { Component } from "react";
2
- import PropTypes from "prop-types";
3
- import { connect } from "react-redux";
4
- import Loading from "@truedat/core/components/Loading";
5
- import { fetchGroups } from "../routines";
6
-
7
- class GroupsLoader extends Component {
8
- static propTypes = {
9
- fetchGroups: PropTypes.func,
10
- groupsLoading: PropTypes.bool,
11
- };
12
-
13
- componentDidMount() {
14
- const { fetchGroups } = this.props;
15
- fetchGroups();
16
- }
17
-
18
- render() {
19
- const { groupsLoading } = this.props;
20
- if (groupsLoading) {
21
- return <Loading />;
22
- } else {
23
- return null;
24
- }
25
- }
26
- }
27
-
28
- const mapStateToProps = ({ groupsLoading }) => ({ groupsLoading });
29
-
30
- export default connect(mapStateToProps, { fetchGroups })(GroupsLoader);
@@ -1,71 +0,0 @@
1
- import { render, waitForLoad } from "@truedat/test/render";
2
- import { useParams } from "react-router";
3
- import { clearGroup, fetchGroup } from "../../routines";
4
- import GroupLoader from "../GroupLoader";
5
-
6
- jest.mock("react-router", () => ({
7
- ...jest.requireActual("react-router"),
8
- useParams: jest.fn(),
9
- }));
10
-
11
- describe("GroupLoader", () => {
12
- const renderOpts = {
13
- dispatch: jest.fn(),
14
- state: {
15
- groupLoading: false,
16
- },
17
- };
18
-
19
- beforeEach(() => {
20
- jest.clearAllMocks();
21
- useParams.mockReturnValue({});
22
- });
23
-
24
- it("renders nothing when not loading", async () => {
25
- const rendered = render(<GroupLoader />, renderOpts);
26
- await waitForLoad(rendered);
27
-
28
- expect(rendered.container).toMatchSnapshot();
29
- expect(rendered.queryByTestId("loading")).not.toBeInTheDocument();
30
- });
31
-
32
- it("renders loading component when loading", async () => {
33
- const loadingRenderOpts = {
34
- ...renderOpts,
35
- state: {
36
- groupLoading: true,
37
- },
38
- };
39
-
40
- const rendered = render(<GroupLoader />, loadingRenderOpts);
41
-
42
- expect(rendered.container).toMatchSnapshot();
43
- });
44
-
45
- it("dispatches fetchGroup when id is present", async () => {
46
- useParams.mockReturnValue({ id: "123" });
47
-
48
- const rendered = render(<GroupLoader />, renderOpts);
49
- await waitForLoad(rendered);
50
-
51
- expect(renderOpts.dispatch).toHaveBeenCalledWith(fetchGroup({ id: "123" }));
52
- });
53
-
54
- it("dispatches clearGroup when id is not present", async () => {
55
- useParams.mockReturnValue({});
56
-
57
- const rendered = render(<GroupLoader />, renderOpts);
58
- await waitForLoad(rendered);
59
-
60
- expect(renderOpts.dispatch).toHaveBeenCalledWith(clearGroup());
61
- });
62
-
63
- it("dispatches clearGroup on unmount", async () => {
64
- const rendered = render(<GroupLoader />, renderOpts);
65
- await waitForLoad(rendered);
66
-
67
- rendered.unmount();
68
-
69
- expect(renderOpts.dispatch).toHaveBeenCalledWith(clearGroup());
70
- });
71
- });
@@ -1,11 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`GroupLoader renders loading component when loading 1`] = `
4
- <div>
5
- <div
6
- class="ui active loader"
7
- />
8
- </div>
9
- `;
10
-
11
- exports[`GroupLoader renders nothing when not loading 1`] = `<div />`;
@@ -1,51 +0,0 @@
1
- import { clearRedirect } from "@truedat/core/routines";
2
- import {
3
- createGroup,
4
- deleteGroup,
5
- deleteGroupUser,
6
- updateGroup,
7
- } from "../../routines";
8
- import { groupRedirect } from "..";
9
-
10
- describe("reducers: groupRedirect", () => {
11
- const payload = {};
12
- const initialState = "";
13
-
14
- it("should provide the initial state", () => {
15
- expect(groupRedirect(undefined, {})).toEqual("");
16
- });
17
-
18
- it("should handle the clearRedirect.TRIGGER action", () => {
19
- expect(groupRedirect("foo", { type: clearRedirect.TRIGGER })).toEqual(
20
- initialState,
21
- );
22
- });
23
-
24
- it("should handle the createGroup.SUCCESS action", () => {
25
- expect(groupRedirect("foo", { type: createGroup.SUCCESS })).toEqual(
26
- "/groups",
27
- );
28
- });
29
-
30
- it("should handle the deleteGroup.SUCCESS action", () => {
31
- expect(groupRedirect("foo", { type: deleteGroup.SUCCESS })).toEqual(
32
- "/groups",
33
- );
34
- });
35
-
36
- it("should handle the updateGroup.SUCCESS action", () => {
37
- expect(groupRedirect("foo", { type: updateGroup.SUCCESS })).toEqual(
38
- "/groups",
39
- );
40
- });
41
-
42
- it("should ignore deleteGroupUser.SUCCESS action", () => {
43
- expect(groupRedirect("foo", { type: deleteGroupUser.SUCCESS })).toEqual(
44
- "foo",
45
- );
46
- });
47
-
48
- it("should ignore unknown actions", () => {
49
- expect(groupRedirect("foo", { type: "bar", payload })).toEqual("foo");
50
- });
51
- });