• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / gui / 951400782

pending completion
951400782

Pull #3900

gitlab-ci

web-flow
chore: bump @testing-library/jest-dom from 5.16.5 to 5.17.0

Bumps [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) from 5.16.5 to 5.17.0.
- [Release notes](https://github.com/testing-library/jest-dom/releases)
- [Changelog](https://github.com/testing-library/jest-dom/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testing-library/jest-dom/compare/v5.16.5...v5.17.0)

---
updated-dependencies:
- dependency-name: "@testing-library/jest-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #3900: chore: bump @testing-library/jest-dom from 5.16.5 to 5.17.0

4446 of 6414 branches covered (69.32%)

8342 of 10084 relevant lines covered (82.73%)

186.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.76
/src/js/components/settings/user-management/usermanagement.js
1
// Copyright 2017 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import React, { useEffect, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { Button, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material';
19

20
import { setSnackbar } from '../../../actions/appActions';
21
import { createUser, editUser, getUserList, passwordResetStart, removeUser } from '../../../actions/userActions';
22
import { getCurrentUser, getFeatures, getIsEnterprise, getRolesById, getUserCapabilities } from '../../../selectors';
23
import { UserDefinition } from './userdefinition';
24
import UserForm from './userform';
25
import UserList from './userlist';
26

27
const actions = {
5✔
28
  create: 'createUser',
29
  edit: 'editUser',
30
  remove: 'removeUser'
31
};
32

33
export const UserManagement = () => {
5✔
34
  const [showCreate, setShowCreate] = useState(false);
15✔
35
  const [removeDialog, setRemoveDialog] = useState(false);
14✔
36
  const [user, setUser] = useState({});
14✔
37
  const dispatch = useDispatch();
14✔
38

39
  const { canManageUsers } = useSelector(getUserCapabilities);
14✔
40
  const { isHosted } = useSelector(getFeatures);
14✔
41
  const isEnterprise = useSelector(getIsEnterprise);
14✔
42
  const currentUser = useSelector(getCurrentUser);
14✔
43
  const roles = useSelector(getRolesById);
14✔
44
  const users = useSelector(state => Object.values(state.users.byId));
26✔
45
  const props = {
14✔
46
    canManageUsers,
47
    createUser: userData => dispatch(createUser(userData)),
1✔
48
    currentUser,
49
    editUser: (id, userData) => dispatch(editUser(id, userData)),
1✔
50
    isEnterprise,
51
    isHosted,
52
    removeUser: id => dispatch(removeUser(id)),
×
53
    roles,
54
    users
55
  };
56

57
  useEffect(() => {
14✔
58
    dispatch(getUserList());
4✔
59
  }, []);
60

61
  useEffect(() => {
14✔
62
    dispatch(getUserList());
5✔
63
  }, [currentUser.id, users.length]);
64

65
  const openEdit = user => {
14✔
66
    setUser(user);
3✔
67
    setRemoveDialog(false);
3✔
68
    dispatch(setSnackbar(''));
3✔
69
  };
70

71
  const openRemove = () => {
14✔
72
    dispatch(setSnackbar(''));
1✔
73
    setRemoveDialog(true);
1✔
74
  };
75

76
  const dialogDismiss = () => {
14✔
77
    setUser({});
2✔
78
    setShowCreate(false);
2✔
79
    setRemoveDialog(false);
2✔
80
  };
81

82
  const submit = (userData, type, id, passwordResetEmail) => {
14✔
83
    if (userData) {
2!
84
      let request = null;
2✔
85
      if (id) {
2✔
86
        request = props[actions[type]](id, userData);
1✔
87
      } else {
88
        request = props[actions[type]](userData);
1✔
89
      }
90
      return request.then(() => {
2✔
91
        if (passwordResetEmail) {
1!
92
          dispatch(passwordResetStart(passwordResetEmail));
×
93
        }
94
        dialogDismiss();
1✔
95
      });
96
    }
97
    if (passwordResetEmail) {
×
98
      dispatch(passwordResetStart(passwordResetEmail));
×
99
    }
100
    return dialogDismiss();
×
101
  };
102

103
  return (
14✔
104
    <div>
105
      <div className="flexbox centered space-between" style={{ marginLeft: '20px' }}>
106
        <h2>Users</h2>
107
        <Button variant="contained" color="primary" onClick={setShowCreate}>
108
          Create new user
109
        </Button>
110
      </div>
111

112
      <UserList {...props} editUser={openEdit} />
113
      {showCreate && <UserForm {...props} closeDialog={dialogDismiss} submit={submit} />}
19✔
114
      <UserDefinition
115
        currentUser={currentUser}
116
        isEnterprise={isEnterprise}
117
        onRemove={openRemove}
118
        onCancel={dialogDismiss}
119
        onSubmit={submit}
120
        roles={roles}
121
        selectedUser={user}
122
      />
123
      {removeDialog && (
15✔
124
        <Dialog open>
125
          <DialogTitle>Remove user?</DialogTitle>
126
          <DialogContent style={{ overflow: 'hidden' }}>
127
            Are you sure you want to remove the user with email{' '}
128
            <b>
129
              <i>{user.email}</i>
130
            </b>
131
            ?
132
          </DialogContent>
133
          <DialogActions>
134
            <Button style={{ marginRight: 10 }} onClick={dialogDismiss}>
135
              Cancel
136
            </Button>
137
            <Button variant="contained" color="primary" onClick={() => submit(user, 'remove', user.id)}>
×
138
              Remove user
139
            </Button>
140
          </DialogActions>
141
        </Dialog>
142
      )}
143
    </div>
144
  );
145
};
146

147
export default UserManagement;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc