• 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

72.73
/src/js/components/devices/widgets/deviceadditionwidget.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

16
import { ArrowDropDown as ArrowDropDownIcon, Launch as LaunchIcon } from '@mui/icons-material';
17
import { Button, ButtonGroup, Menu, MenuItem } from '@mui/material';
18
import { makeStyles } from 'tss-react/mui';
19

20
const useStyles = makeStyles()(() => ({
5✔
21
  buttonStyle: { textTransform: 'none' }
22
}));
23

24
export const DeviceAdditionWidget = ({ docsVersion, features, onConnectClick, onMakeGatewayClick, onPreauthClick, tenantCapabilities }) => {
5✔
25
  const [anchorEl, setAnchorEl] = useState();
3✔
26
  const [selectedIndex, setSelectedIndex] = useState(0);
3✔
27
  const { classes } = useStyles();
3✔
28

29
  const options = [
3✔
30
    { action: onConnectClick, title: 'Connect a new device', value: 'connect', canAccess: () => true },
3✔
31
    { action: onPreauthClick, title: 'Preauthorize a device', value: 'preauth', canAccess: () => true },
3✔
32
    {
33
      action: onMakeGatewayClick,
34
      title: 'Promote a device to gateway',
35
      value: 'makegateway',
36
      canAccess: ({ features, tenantCapabilities }) => features.isHosted && tenantCapabilities.isEnterprise
3!
37
    },
38
    {
39
      href: `https://docs.mender.io/${docsVersion}client-installation/overview`,
40
      rel: 'noopener noreferrer',
41
      target: '_blank',
42
      title: 'Learn how to connect devices',
43
      value: 'learntoconnect',
44
      canAccess: () => true
3✔
45
    }
46
  ];
47

48
  const handleToggle = event => {
3✔
49
    const anchor = anchorEl ? null : event?.currentTarget.parentElement;
×
50
    setAnchorEl(anchor);
×
51
  };
52

53
  const handleSelection = index => {
3✔
54
    setSelectedIndex(index);
×
55
    handleToggle();
×
56
    options[index].action(true);
×
57
  };
58

59
  return (
3✔
60
    <>
61
      <ButtonGroup className="muted device-addition-widget">
62
        <Button className={classes.buttonStyle} onClick={options[selectedIndex].action} variant="text">
63
          {options[selectedIndex].title}
64
        </Button>
65
        <Button className={classes.buttonStyle} size="small" onClick={handleToggle} variant="text">
66
          <ArrowDropDownIcon />
67
        </Button>
68
      </ButtonGroup>
69
      <Menu id="device-connection-menu" anchorEl={anchorEl} keepMounted open={Boolean(anchorEl)} onClose={handleToggle} variant="menu">
70
        {options.reduce((accu, option, index) => {
71
          if (!option.canAccess({ features, tenantCapabilities })) {
12✔
72
            return accu;
3✔
73
          }
74
          // eslint-disable-next-line no-unused-vars
75
          const { canAccess, href, title, value, ...optionProps } = option;
9✔
76
          const item = href ? (
9✔
77
            <MenuItem {...optionProps} key={value} href={href} component="a">
78
              {title}
79
              <LaunchIcon style={{ fontSize: '10pt' }} />
80
            </MenuItem>
81
          ) : (
82
            <MenuItem className={classes.buttonStyle} key={value} onClick={() => handleSelection(index)}>
×
83
              {title}
84
            </MenuItem>
85
          );
86
          accu.push(item);
9✔
87
          return accu;
9✔
88
        }, [])}
89
      </Menu>
90
    </>
91
  );
92
};
93

94
export default DeviceAdditionWidget;
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