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

mendersoftware / gui / 1350829378

27 Jun 2024 01:46PM UTC coverage: 83.494% (-16.5%) from 99.965%
1350829378

Pull #4465

gitlab-ci

mzedel
chore: test fixes

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4465: MEN-7169 - feat: added multi sorting capabilities to devices view

4506 of 6430 branches covered (70.08%)

81 of 100 new or added lines in 14 files covered. (81.0%)

1661 existing lines in 163 files now uncovered.

8574 of 10269 relevant lines covered (83.49%)

160.6 hits per line

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

77.78
/src/js/components/leftnav.js
1
// Copyright 2018 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 { useDispatch, useSelector } from 'react-redux';
16
import { Link, NavLink } from 'react-router-dom';
17

18
// material ui
19
import { List, ListItem, ListItemText, Tooltip } from '@mui/material';
20
import { makeStyles } from 'tss-react/mui';
21

22
import copy from 'copy-to-clipboard';
23

24
import { setSnackbar, setVersionInfo } from '../actions/appActions';
25
import { TIMEOUTS, canAccess } from '../constants/appConstants';
26
import { getFeatures, getUserCapabilities, getVersionInformation } from '../selectors';
27
import DocsLink from './common/docslink';
28

29
const listItems = [
2✔
30
  { route: '/', text: 'Dashboard', canAccess },
31
  { route: '/devices', text: 'Devices', canAccess: ({ userCapabilities: { canReadDevices } }) => canReadDevices },
16✔
32
  { route: '/releases', text: 'Releases', canAccess: ({ userCapabilities: { canReadReleases, canUploadReleases } }) => canReadReleases || canUploadReleases },
16✔
33
  { route: '/deployments', text: 'Deployments', canAccess: ({ userCapabilities: { canDeploy, canReadDeployments } }) => canReadDeployments || canDeploy },
16✔
34
  { route: '/auditlog', text: 'Audit log', canAccess: ({ userCapabilities: { canAuditlog } }) => canAuditlog }
16✔
35
];
36

37
const useStyles = makeStyles()(theme => ({
32✔
38
  licenseLink: { fontSize: '13px', position: 'relative', top: '6px', color: theme.palette.primary.main },
39
  infoList: { padding: 0, position: 'absolute', bottom: 30, left: 0, right: 0 },
40
  list: {
41
    backgroundColor: theme.palette.background.lightgrey,
42
    borderRight: `1px solid ${theme.palette.grey[300]}`
43
  },
44
  navLink: { padding: '22px 16px 22px 42px' },
45
  listItem: { padding: '16px 16px 16px 42px' },
46
  versions: { display: 'grid', gridTemplateColumns: 'max-content 60px', columnGap: theme.spacing(), '>a': { color: theme.palette.grey[100] } }
47
}));
48

49
const linkables = {
2✔
50
  'Integration': 'integration',
51
  'Mender-Client': 'mender',
52
  'Mender-Artifact': 'mender-artifact',
53
  'GUI': 'gui'
54
};
55

56
const VersionInfo = () => {
2✔
57
  const [clicks, setClicks] = useState(0);
16✔
58
  const timer = useRef();
16✔
59
  const { classes } = useStyles();
16✔
60

61
  const dispatch = useDispatch();
16✔
62
  const { isHosted } = useSelector(getFeatures);
16✔
63
  // eslint-disable-next-line no-unused-vars
64
  const { latestRelease, ...versionInformation } = useSelector(getVersionInformation);
16✔
65

66
  useEffect(() => {
16✔
67
    return () => {
6✔
68
      clearTimeout(timer.current);
6✔
69
    };
70
  }, []);
71

72
  const onVersionClick = () => {
16✔
UNCOV
73
    copy(JSON.stringify(versionInformation));
×
UNCOV
74
    dispatch(setSnackbar('Version information copied to clipboard'));
×
75
  };
76

77
  const versions = (
78
    <div className={classes.versions}>
16✔
79
      {Object.entries(versionInformation).reduce((accu, [key, version]) => {
80
        if (version) {
100✔
81
          accu.push(
45✔
82
            <React.Fragment key={key}>
83
              {linkables[key] ? (
45✔
84
                <a href={`https://github.com/mendersoftware/${linkables[key]}/tree/${version}`} target="_blank" rel="noopener noreferrer">
85
                  {key}
86
                </a>
87
              ) : (
88
                <div>{key}</div>
89
              )}
90
              <div className="align-right text-overflow" title={version}>
91
                {version}
92
              </div>
93
            </React.Fragment>
94
          );
95
        }
96
        return accu;
100✔
97
      }, [])}
98
    </div>
99
  );
100

101
  const onClick = () => {
16✔
UNCOV
102
    setClicks(clicks + 1);
×
UNCOV
103
    clearTimeout(timer.current);
×
UNCOV
104
    timer.current = setTimeout(() => {
×
UNCOV
105
      setClicks(0);
×
106
    }, TIMEOUTS.threeSeconds);
UNCOV
107
    if (clicks > 5) {
×
UNCOV
108
      dispatch(setVersionInfo({ Integration: 'next' }));
×
109
    }
UNCOV
110
    onVersionClick();
×
111
  };
112

113
  let title = versionInformation.Integration ? `Version: ${versionInformation.Integration}` : '';
16✔
114
  if (isHosted && versionInformation.Integration !== 'next') {
16!
UNCOV
115
    title = 'Version: latest';
×
116
  }
117
  return (
16✔
118
    <Tooltip title={versions} placement="top">
119
      <div className="clickable slightly-smaller" onClick={onClick}>
120
        {title}
121
      </div>
122
    </Tooltip>
123
  );
124
};
125

126
export const LeftNav = () => {
2✔
127
  const releasesRef = useRef();
16✔
128
  const { classes } = useStyles();
16✔
129

130
  const userCapabilities = useSelector(getUserCapabilities);
16✔
131
  return (
16✔
132
    <div className={`leftFixed leftNav ${classes.list}`}>
133
      <List style={{ padding: 0 }}>
134
        {listItems.reduce((accu, item, index) => {
135
          if (!item.canAccess({ userCapabilities })) {
80✔
136
            return accu;
8✔
137
          }
138
          accu.push(
72✔
139
            <ListItem
140
              className={`navLink leftNav ${classes.navLink}`}
141
              component={NavLink}
142
              end={item.route === '/'}
143
              key={index}
144
              ref={item.route === '/releases' ? releasesRef : null}
72✔
145
              to={item.route}
146
            >
147
              <ListItemText primary={item.text} style={{ textTransform: 'uppercase' }} />
148
            </ListItem>
149
          );
150
          return accu;
72✔
151
        }, [])}
152
      </List>
153
      <List className={classes.infoList}>
154
        <ListItem className={`navLink leftNav ${classes.listItem}`} component={Link} to="/help">
155
          <ListItemText primary="Help & support" />
156
        </ListItem>
157
        <ListItem className={classes.listItem}>
158
          <ListItemText
159
            primary={<VersionInfo />}
160
            secondary={<DocsLink className={classes.licenseLink} path="release-information/open-source-licenses" title="License information" />}
161
          />
162
        </ListItem>
163
      </List>
164
    </div>
165
  );
166
};
167

168
export default LeftNav;
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