• 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

82.43
/src/js/components/common/dialogs/deviceconnectiondialog.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, useState } from 'react';
15
import { connect } from 'react-redux';
16
import { useNavigate } from 'react-router-dom';
17

18
import { Button, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import docker from '../../../../assets/img/docker.png';
22
import raspberryPi4 from '../../../../assets/img/raspberrypi4.png';
23
import raspberryPi from '../../../../assets/img/raspberrypi.png';
24
import { setDeviceListState } from '../../../actions/deviceActions';
25
import { advanceOnboarding } from '../../../actions/onboardingActions';
26
import { TIMEOUTS } from '../../../constants/appConstants';
27
import { DEVICE_STATES } from '../../../constants/deviceConstants';
28
import { onboardingSteps } from '../../../constants/onboardingConstants';
29
import { getDocsVersion, getTenantCapabilities } from '../../../selectors';
30
import InfoText from '../../common/infotext';
31
import { DeviceSupportTip } from '../../helptips/helptooltips';
32
import PhysicalDeviceOnboarding from './physicaldeviceonboarding';
33
import VirtualDeviceOnboarding from './virtualdeviceonboarding';
34

35
const useStyles = makeStyles()(theme => ({
3✔
36
  rpiQuickstart: {
37
    backgroundColor: theme.palette.background.lightgrey
38
  },
39
  virtualLogo: { height: 40, marginLeft: theme.spacing(2) }
40
}));
41

42
const DeviceConnectionExplainer = ({ docsVersion, hasMonitor, setOnDevice, setVirtualDevice }) => {
3✔
43
  const { classes } = useStyles();
3✔
44
  return (
3✔
45
    <>
46
      <p>
47
        You can connect almost any device and Linux OS with Mender, but to make things simple during evaluation we recommend you use a Raspberry Pi as a test
48
        device.
49
      </p>
50
      <div className={`padding-small padding-top-none rpi-quickstart ${classes.rpiQuickstart}`}>
51
        <h3>Raspberry Pi quick start</h3>
52
        <p>We&apos;ll walk you through the steps to connect a Raspberry Pi and deploy your first update with Mender.</p>
53
        <div className="flexbox column centered">
54
          <div className="flexbox centered os-list">
55
            {[raspberryPi, raspberryPi4].map((tile, index) => (
56
              <img key={`tile-${index}`} src={tile} />
6✔
57
            ))}
58
          </div>
59
          <Button variant="contained" color="secondary" onClick={() => setOnDevice(true)}>
1✔
60
            Get Started
61
          </Button>
62
        </div>
63
      </div>
64
      <div className="two-columns margin-top">
65
        <div className="padding-small padding-top-none">
66
          <div className="flexbox center-aligned">
67
            <h3>Use a virtual device</h3>
68
            <img src={docker} className={classes.virtualLogo} />
69
          </div>
70
          <p className="margin-top-none">Don&apos;t have a Raspberry Pi?</p>
71
          <p>You can use our Docker-run virtual device to go through the same tutorial.</p>
72
          {hasMonitor && (
3!
73
            <InfoText className="slightly-smaller">
74
              If you want to evaluate our commercial components such as mender-monitor, please use a physical device instead as the virtual client does not
75
              support these components at this time.
76
            </InfoText>
77
          )}
78
          <a onClick={() => setVirtualDevice(true)}>Try a virtual device</a>
1✔
79
        </div>
80
        <div className="padding-small padding-top-none">
81
          <h3>Other devices</h3>
82
          <div>See the documentation to integrate the following with Mender:</div>
83
          <ul>
84
            {[
85
              { key: 'debian', target: `https://docs.mender.io/${docsVersion}operating-system-updates-debian-family`, title: 'Debian family' },
86
              { key: 'yocto', target: `https://docs.mender.io/${docsVersion}operating-system-updates-yocto-project`, title: 'Yocto OSes' }
87
            ].map(item => (
88
              <li key={item.key}>
6✔
89
                <a href={item.target} target="_blank" rel="noopener noreferrer">
90
                  {item.title}
91
                </a>
92
              </li>
93
            ))}
94
          </ul>
95
          Or visit{' '}
96
          <a href="https://hub.mender.io/c/board-integrations" target="_blank" rel="noopener noreferrer">
97
            Mender Hub
98
          </a>{' '}
99
          and search integrations for your device and OS.
100
        </div>
101
      </div>
102
      <DeviceSupportTip />
103
    </>
104
  );
105
};
106

107
export const DeviceConnectionDialog = ({
3✔
108
  advanceOnboarding,
109
  docsVersion,
110
  hasMonitor,
111
  onboardingDeviceType,
112
  onboardingComplete,
113
  onCancel,
114
  pendingCount,
115
  setDeviceListState
116
}) => {
117
  const [onDevice, setOnDevice] = useState(false);
5✔
118
  const [progress, setProgress] = useState(1);
5✔
119
  const [virtualDevice, setVirtualDevice] = useState(false);
5✔
120
  const [pendingDevicesCount] = useState(pendingCount);
5✔
121
  const [hasMoreDevices, setHasMoreDevices] = useState(false);
5✔
122
  const navigate = useNavigate();
5✔
123

124
  useEffect(() => {
5✔
125
    setHasMoreDevices(pendingCount > pendingDevicesCount);
2✔
126
  }, [pendingDevicesCount, pendingCount]);
127

128
  useEffect(() => {
5✔
129
    if ((virtualDevice || progress >= 2) && hasMoreDevices && !window.location.hash.includes('pending')) {
3!
130
      advanceOnboarding(onboardingSteps.DASHBOARD_ONBOARDING_START);
×
131
      setDeviceListState({ state: DEVICE_STATES.pending });
×
132
      navigate('/devices/pending');
×
133
    }
134
  }, [advanceOnboarding, hasMoreDevices, progress, virtualDevice]);
135

136
  const onBackClick = () => {
5✔
137
    let updatedProgress = progress - 1;
1✔
138
    if (!updatedProgress) {
1!
139
      updatedProgress = 1;
1✔
140
      setOnDevice(false);
1✔
141
      setVirtualDevice(false);
1✔
142
    }
143
    setProgress(updatedProgress);
1✔
144
  };
145

146
  const onAdvance = () => {
5✔
147
    advanceOnboarding(onboardingSteps.DASHBOARD_ONBOARDING_START);
×
148
    setProgress(progress + 1);
×
149
  };
150

151
  let content = <DeviceConnectionExplainer docsVersion={docsVersion} hasMonitor={hasMonitor} setOnDevice={setOnDevice} setVirtualDevice={setVirtualDevice} />;
5✔
152
  if (onDevice) {
5✔
153
    content = <PhysicalDeviceOnboarding progress={progress} />;
1✔
154
  } else if (virtualDevice) {
4✔
155
    content = <VirtualDeviceOnboarding />;
1✔
156
  }
157

158
  if (hasMoreDevices && !onboardingComplete) {
5!
159
    setTimeout(onCancel, TIMEOUTS.twoSeconds);
×
160
  }
161

162
  return (
5✔
163
    <Dialog open={true} PaperProps={{ sx: { maxWidth: '720px' } }}>
164
      <DialogTitle>Connecting a device</DialogTitle>
165
      <DialogContent className="onboard-dialog" style={{ margin: '0 30px' }}>
166
        {content}
167
      </DialogContent>
168
      <DialogActions>
169
        <Button onClick={onCancel}>Cancel</Button>
170
        <div style={{ flexGrow: 1 }} />
171
        {(onDevice || virtualDevice) && (
11✔
172
          <div>
173
            <Button onClick={onBackClick}>Back</Button>
174
            {progress < 2 && (!virtualDevice || progress < 1) ? (
7✔
175
              <Button variant="contained" disabled={!(virtualDevice || (onDevice && onboardingDeviceType))} onClick={onAdvance}>
3✔
176
                Next
177
              </Button>
178
            ) : (
179
              <Button variant="contained" disabled={!onboardingComplete} onClick={onCancel}>
180
                {onboardingComplete ? 'Close' : 'Waiting for device'}
1!
181
              </Button>
182
            )}
183
          </div>
184
        )}
185
      </DialogActions>
186
    </Dialog>
187
  );
188
};
189

190
const actionCreators = { advanceOnboarding, setDeviceListState };
3✔
191

192
const mapStateToProps = state => {
3✔
193
  return {
2✔
194
    docsVersion: getDocsVersion(state),
195
    hasMonitor: getTenantCapabilities(state).hasMonitor,
196
    pendingCount: state.devices.byStatus.pending.total,
197
    onboardingComplete: state.onboarding.complete,
198
    onboardingDeviceType: state.onboarding.deviceType
199
  };
200
};
201

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