• 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

85.71
/src/js/components/help/help.js
1
// Copyright 2017 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 { Navigate, useLocation, useParams } from 'react-router-dom';
17

18
import { Launch as LaunchIcon } from '@mui/icons-material';
19
import { ListItemIcon, useTheme } from '@mui/material';
20

21
import { getDocsVersion } from '../../selectors';
22
import LeftNav from '../common/left-nav';
23
import Downloads from './downloads';
24
import GetStarted from './getting-started';
25
import MenderHub from './mender-hub';
26
import Support from './support';
27

28
const components = {
4✔
29
  'get-started': {
30
    title: 'Getting started',
31
    component: GetStarted
32
  },
33
  downloads: {
34
    title: 'Downloads',
35
    component: Downloads,
36
    hosted: true
37
  },
38
  support: {
39
    title: 'Contact support',
40
    component: Support
41
  },
42
  'mender-hub': {
43
    title: 'Mender Hub',
44
    component: MenderHub
45
  },
46
  documentation: {
47
    title: 'Documentation',
48
    url: `https://docs.mender.io/`
49
  }
50
};
51

52
const contentWidth = 780;
4✔
53

54
const LinkIcon = () => (
4✔
55
  <ListItemIcon style={{ 'verticalAlign': 'middle' }}>
×
56
    <LaunchIcon style={{ 'fontSize': '1rem' }} />
57
  </ListItemIcon>
58
);
59

60
// build array of link list components
61
const eachRecursive = (obj, path, level, accu, isHosted, spacing) =>
4✔
62
  Object.entries(obj).reduce((bag, [key, value]) => {
5✔
63
    if (!isHosted && value.hosted) {
13✔
64
      return bag;
1✔
65
    }
66
    if (typeof value == 'object' && value !== null && key !== 'component') {
12✔
67
      const this_path = `${path}/${key}`;
4✔
68
      bag.push({
4✔
69
        title: value.title,
70
        level,
71
        path: this_path,
72
        hosted: value.hosted,
73
        style: { paddingLeft: `calc(${level} * ${spacing})` },
74
        exact: true,
75
        secondaryAction: value.url ? <LinkIcon /> : null,
4✔
76
        url: value.url ? value.url : ''
4✔
77
      });
78
      bag = eachRecursive(value, this_path, level + 1, bag, isHosted, spacing);
4✔
79
    }
80
    return bag;
12✔
81
  }, accu);
82

83
const helpPath = 'help/';
4✔
84
export const Help = ({ docsVersion, isHosted }) => {
4✔
85
  const theme = useTheme();
2✔
86
  const [links, setLinks] = useState([]);
2✔
87
  const { pathname } = useLocation();
2✔
88
  const { section } = useParams();
2✔
89

90
  useEffect(() => {
2✔
91
    // generate sidebar links
92
    setLinks(eachRecursive(components, '/help', 1, [], isHosted, theme.spacing(2)));
1✔
93
  }, []);
94

95
  if (!section) {
2!
96
    return <Navigate replace to="/help/get-started" />;
×
97
  }
98

99
  let ComponentToShow = GetStarted;
2✔
100
  let breadcrumbs = '';
2✔
101
  let routeParams = pathname.includes(helpPath) ? pathname.substring(pathname.indexOf(helpPath) + helpPath.length) : '';
2!
102
  if (routeParams) {
2!
103
    let splitsplat = routeParams.split('/');
2✔
104
    let copyOfComponents = components;
2✔
105

106
    for (let i = 0; i < splitsplat.length; i++) {
2✔
107
      if (i === splitsplat.length - 1) {
2!
108
        ComponentToShow = copyOfComponents[splitsplat[i]].component;
2✔
109
      } else {
110
        copyOfComponents = copyOfComponents[splitsplat[i]];
×
111
      }
112
    }
113

114
    breadcrumbs = splitsplat[0] ? '  >  ' + components[splitsplat[0]].title : '';
2!
115
    breadcrumbs = splitsplat[1] ? breadcrumbs + '  >  ' + components[splitsplat[0]][splitsplat[1]].title : breadcrumbs;
2!
116
  }
117

118
  return (
2✔
119
    <div className="help-container">
120
      <LeftNav sections={[{ itemClass: 'helpNav', items: links, title: 'Help & support' }]} />
121
      <div style={{ maxWidth: contentWidth }}>
122
        <p className="muted">Help & support {breadcrumbs}</p>
123
        <div className="help-content relative margin-top-small">
124
          <ComponentToShow docsVersion={docsVersion} />
125
        </div>
126
      </div>
127
    </div>
128
  );
129
};
130

131
const mapStateToProps = state => {
4✔
132
  return {
1✔
133
    docsVersion: getDocsVersion(state),
134
    isHosted: state.app.features.isHosted
135
  };
136
};
137

138
export default connect(mapStateToProps)(Help);
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