• 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

92.16
/src/js/components/dashboard/devices.js
1
// Copyright 2019 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, useRef, useState } from 'react';
15
import { connect } from 'react-redux';
16
import { useNavigate } from 'react-router-dom';
17

18
import { getDeviceCount } from '../../actions/deviceActions';
19
import { getIssueCountsByType } from '../../actions/monitorActions';
20
import { advanceOnboarding } from '../../actions/onboardingActions';
21
import { setShowConnectingDialog } from '../../actions/userActions';
22
import { DEVICE_STATES } from '../../constants/deviceConstants';
23
import { onboardingSteps } from '../../constants/onboardingConstants';
24
import { getAvailableIssueOptionsByType, getOnboardingState, getUserCapabilities } from '../../selectors';
25
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
26
import useWindowSize from '../../utils/resizehook';
27
import AcceptedDevices from './widgets/accepteddevices';
28
import ActionableDevices from './widgets/actionabledevices';
29
import PendingDevices from './widgets/pendingdevices';
30
import RedirectionWidget from './widgets/redirectionwidget';
31

32
export const Devices = props => {
5✔
33
  const [loading, setLoading] = useState(false);
108✔
34
  // eslint-disable-next-line no-unused-vars
35
  const size = useWindowSize();
106✔
36
  const anchor = useRef();
106✔
37
  const pendingsRef = useRef();
106✔
38
  const navigate = useNavigate();
106✔
39

40
  const {
41
    acceptedDevicesCount,
42
    advanceOnboarding,
43
    availableIssueOptions,
44
    canManageDevices,
45
    clickHandle,
46
    getDeviceCount,
47
    getIssueCountsByType,
48
    onboardingState,
49
    pendingDevicesCount,
50
    setShowConnectingDialog,
51
    showHelptips
52
  } = props;
106✔
53

54
  useEffect(() => {
106✔
55
    // on render the store might not be updated so we resort to the API and let all later request go through the store
56
    // to be in sync with the rest of the UI
57
    refreshDevices();
10✔
58
  }, []);
59

60
  useEffect(() => {
106✔
61
    refreshDevices();
10✔
62
  }, [JSON.stringify(availableIssueOptions)]);
63

64
  const refreshDevices = () => {
106✔
65
    if (loading) {
20!
66
      return;
×
67
    }
68
    const issueRequests = Object.keys(availableIssueOptions).map(key => getIssueCountsByType(key, { filters: [], selectedIssues: [key] }));
20✔
69
    setLoading(true);
20✔
70
    return Promise.all([getDeviceCount(DEVICE_STATES.accepted), getDeviceCount(DEVICE_STATES.pending), ...issueRequests]).finally(() => setLoading(false));
20✔
71
  };
72

73
  const onConnectClick = () => {
106✔
74
    setShowConnectingDialog(true);
×
75
    navigate('/devices/accepted');
×
76
  };
77

78
  let onboardingComponent = null;
106✔
79
  if (anchor.current) {
106✔
80
    const element = anchor.current.children[anchor.current.children.length - 1];
93✔
81
    const deviceConnectionAnchor = { left: element.offsetLeft + element.offsetWidth / 2, top: element.offsetTop + element.offsetHeight - 50 };
93✔
82
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.DASHBOARD_ONBOARDING_START, onboardingState, { anchor: deviceConnectionAnchor });
93✔
83
    if (pendingsRef.current) {
93✔
84
      const element = pendingsRef.current.lastChild;
1✔
85
      const pendingsAnchor = {
1✔
86
        left: pendingsRef.current.offsetLeft + element.offsetWidth / 2,
87
        top: pendingsRef.current.offsetTop + element.offsetHeight
88
      };
89
      onboardingComponent = getOnboardingComponentFor(onboardingSteps.DASHBOARD_ONBOARDING_PENDINGS, onboardingState, { anchor: pendingsAnchor });
1✔
90
    }
91
  }
92
  return (
106✔
93
    <>
94
      <div className="dashboard" ref={anchor}>
95
        <AcceptedDevices devicesCount={acceptedDevicesCount} onClick={clickHandle} />
96
        {!!acceptedDevicesCount && <ActionableDevices issues={availableIssueOptions} />}
194✔
97
        {!!pendingDevicesCount && !acceptedDevicesCount && (
196✔
98
          <PendingDevices
99
            advanceOnboarding={advanceOnboarding}
100
            innerRef={pendingsRef}
101
            isActive={pendingDevicesCount > 0}
102
            onboardingState={onboardingState}
103
            onClick={clickHandle}
104
            pendingDevicesCount={pendingDevicesCount}
105
            showHelptips={showHelptips}
106
          />
107
        )}
108
        {canManageDevices && (
206✔
109
          <RedirectionWidget content={acceptedDevicesCount || pendingDevicesCount ? '+ connect more devices' : 'Connect a device'} onClick={onConnectClick} />
218✔
110
        )}
111
      </div>
112
      {onboardingComponent}
113
    </>
114
  );
115
};
116

117
const actionCreators = { advanceOnboarding, getDeviceCount, getIssueCountsByType, setShowConnectingDialog };
5✔
118

119
const mapStateToProps = state => {
5✔
120
  const { canManageDevices } = getUserCapabilities(state);
155✔
121
  return {
155✔
122
    canManageDevices,
123
    acceptedDevicesCount: state.devices.byStatus.accepted.total,
124
    availableIssueOptions: getAvailableIssueOptionsByType(state),
125
    onboardingState: getOnboardingState(state),
126
    pendingDevicesCount: state.devices.byStatus.pending.total,
127
    showHelptips: state.users.showHelptips
128
  };
129
};
130

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