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

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

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

55.26
/src/js/components/devices/device-details/authsets/authsets.js
1
// Copyright 2021 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, { useState } from 'react';
15
import { connect } from 'react-redux';
16

17
// material ui
18
import { Button } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import pluralize from 'pluralize';
22

23
import { deleteAuthset, updateDeviceAuth } from '../../../../actions/deviceActions';
24
import { DEVICE_DISMISSAL_STATE, DEVICE_STATES } from '../../../../constants/deviceConstants';
25
import { getLimitMaxed, getUserCapabilities } from '../../../../selectors';
26
import { DeviceLimitWarning } from '../../dialogs/preauth-dialog';
27
import Confirm from './../../../common/confirm';
28
import Authsetlist from './authsetlist';
29

30
const useStyles = makeStyles()(theme => ({
12✔
31
  decommission: { justifyContent: 'flex-end', marginTop: theme.spacing(2) },
32
  wrapper: {
33
    backgroundColor: theme.palette.grey[400],
34
    borderColor: theme.palette.grey[500],
35
    borderStyle: 'solid',
36
    borderWidth: 1,
37
    marginBottom: theme.spacing(2),
38
    minWidth: 700,
39
    padding: theme.spacing(2)
40
  }
41
}));
42

43
export const Authsets = ({
12✔
44
  acceptedDevices,
45
  decommission,
46
  deleteAuthset,
47
  device,
48
  deviceLimit,
49
  deviceListRefresh,
50
  limitMaxed,
51
  showHelptips,
52
  updateDeviceAuth,
53
  userCapabilities
54
}) => {
55
  const [confirmDecommission, setConfirmDecomission] = useState(false);
3✔
56
  const [loading, setLoading] = useState(false);
3✔
57
  const { auth_sets = [], status = DEVICE_STATES.accepted } = device;
3!
58

59
  const updateDeviceAuthStatus = (device_id, auth_id, status) => {
3✔
60
    setLoading(auth_id);
×
61
    const postUpdateSteps = () => {
×
62
      deviceListRefresh();
×
63
      setLoading(null);
×
64
    };
65

66
    if (status === DEVICE_DISMISSAL_STATE) {
×
67
      return (
×
68
        deleteAuthset(device_id, auth_id)
69
          // on finish, change "loading" back to null
70
          .finally(postUpdateSteps)
71
      );
72
    } else {
73
      // call API to update authset
74
      return (
×
75
        updateDeviceAuth(device_id, auth_id, status)
76
          // on finish, change "loading" back to null
77
          .finally(postUpdateSteps)
78
      );
79
    }
80
  };
81

82
  const { canManageDevices } = userCapabilities;
3✔
83
  const { classes } = useStyles();
3✔
84
  return (
3✔
85
    <div className={classes.wrapper}>
86
      <div className="margin-bottom-small">
87
        {status === DEVICE_STATES.pending ? `Authorization ${pluralize('request', auth_sets.length)}` : 'Authorization sets'}
3!
88
      </div>
89
      <Authsetlist
90
        limitMaxed={limitMaxed}
91
        total={auth_sets.length}
92
        confirm={updateDeviceAuthStatus}
93
        loading={loading}
94
        device={device}
95
        showHelptips={showHelptips}
96
        userCapabilities={userCapabilities}
97
      />
98
      {limitMaxed && <DeviceLimitWarning acceptedDevices={acceptedDevices} deviceLimit={deviceLimit} hasContactInfo />}
3!
99
      {![DEVICE_STATES.preauth, DEVICE_STATES.pending].includes(device.status) && canManageDevices && (
9✔
100
        <div className={`flexbox ${classes.decommission}`}>
101
          {confirmDecommission ? (
3!
102
            <Confirm action={() => decommission(device.id)} cancel={() => setConfirmDecomission(false)} type="decommissioning" />
×
103
          ) : (
104
            <Button color="secondary" onClick={setConfirmDecomission}>
105
              Decommission device
106
            </Button>
107
          )}
108
        </div>
109
      )}
110
    </div>
111
  );
112
};
113

114
const actionCreators = { deleteAuthset, updateDeviceAuth };
12✔
115

116
const mapStateToProps = (state, ownProps) => {
12✔
117
  const device = state.devices.byId[ownProps.device.id] || {};
3!
118
  return {
3✔
119
    acceptedCount: state.devices.byStatus.accepted.total || 0,
3!
120
    device,
121
    deviceLimit: state.devices.limit,
122
    limitMaxed: getLimitMaxed(state),
123
    userCapabilities: getUserCapabilities(state)
124
  };
125
};
126

127
export default connect(mapStateToProps, actionCreators)(Authsets);
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