• 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

75.76
/src/js/components/common/configurationobject.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, { Fragment, useState } from 'react';
15

16
// material ui
17
import { FileCopyOutlined as CopyToClipboardIcon } from '@mui/icons-material';
18
import { Tooltip } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

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

23
const useStyles = makeStyles()(theme => ({
184✔
24
  root: {
25
    ['.key > b']: {
26
      backgroundColor: theme.palette.grey[400],
27
      color: theme.palette.getContrastText(theme.palette.grey[400])
28
    }
29
  }
30
}));
31

32
const cutoffLength = 100;
184✔
33
const ValueColumn = ({ value = '', setSnackbar }) => {
184!
34
  const [tooltipVisible, setTooltipVisible] = useState(false);
243✔
35
  const isComponent = React.isValidElement(value);
243✔
36
  const onClick = () => {
243✔
UNCOV
37
    if (setSnackbar) {
×
UNCOV
38
      let copyable = value;
×
UNCOV
39
      if (isComponent) {
×
UNCOV
40
        copyable = value.props.value;
×
41
      }
UNCOV
42
      copy(copyable);
×
UNCOV
43
      setSnackbar('Value copied to clipboard');
×
44
    }
45
  };
46
  let shownValue = value;
243✔
47
  if (!isComponent) {
243✔
48
    shownValue = <div title={value}>{value.length > cutoffLength ? `${value.substring(0, cutoffLength - 3)}...` : value}</div>;
200!
49
  }
50
  return (
243✔
51
    <div
52
      className={`flexbox ${setSnackbar ? 'clickable' : ''}`}
243✔
53
      onClick={onClick}
UNCOV
54
      onMouseEnter={() => setTooltipVisible(true)}
×
UNCOV
55
      onMouseLeave={() => setTooltipVisible(false)}
×
56
    >
57
      {shownValue}
58
      {setSnackbar && (
277✔
59
        <Tooltip title={'Copy to clipboard'} placement="top" open={tooltipVisible}>
60
          <CopyToClipboardIcon color="primary" className={`margin-left-small ${tooltipVisible ? 'fadeIn' : 'fadeOut'}`} fontSize="small"></CopyToClipboardIcon>
34!
61
        </Tooltip>
62
      )}
63
    </div>
64
  );
65
};
66

67
const KeyColumn = ({ value, chipLikeKey }) => (
184✔
68
  <div className={`align-right ${chipLikeKey ? 'key' : ''} muted`}>
253✔
69
    <b>{value}</b>
70
  </div>
71
);
72

73
export const TwoColumns = ({
184✔
74
  className = '',
7✔
75
  children,
76
  chipLikeKey = true,
87✔
77
  compact,
78
  items = {},
×
79
  KeyComponent = KeyColumn,
123✔
80
  KeyProps = {},
123✔
81
  setSnackbar,
82
  style = {},
91✔
83
  ValueComponent = ValueColumn,
113✔
84
  ValueProps = {}
120✔
85
}) => {
86
  const { classes } = useStyles();
123✔
87
  return (
123✔
88
    <div className={`break-all two-columns ${classes.root} ${compact ? 'compact' : ''} ${className}`} style={style}>
123✔
89
      {children
123!
90
        ? children
91
        : Object.entries(items).map(([key, value]) => (
92
            <Fragment key={key}>
253✔
93
              <KeyComponent chipLikeKey={chipLikeKey} value={key} {...KeyProps} />
94
              <ValueComponent setSnackbar={setSnackbar} value={value} {...ValueProps} />
95
            </Fragment>
96
          ))}
97
    </div>
98
  );
99
};
100

101
export const TwoColumnData = ({ className = '', config, ...props }) => <TwoColumns className={`column-data ${className}`} items={config} {...props} />;
184✔
102

103
export const TwoColumnDataMultiple = ({ className = '', config, style, ...props }) => (
184✔
104
  <div className={`two-columns-multiple ${className}`} style={{ ...style }}>
2✔
105
    {Object.entries(config).map(([key, value]) => (
106
      <TwoColumnData className="multiple" config={{ [key]: value }} key={key} compact {...props} />
3✔
107
    ))}
108
  </div>
109
);
110

111
export const ConfigurationObject = ({ config, ...props }) => {
184✔
112
  const content = Object.entries(config).reduce((accu, [key, value]) => {
4✔
113
    accu[key] = `${value}`;
10✔
114
    return accu;
10✔
115
  }, {});
116
  return <TwoColumnData {...props} config={content} />;
4✔
117
};
118

119
export default ConfigurationObject;
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