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

mendersoftware / gui / 951400782

pending completion
951400782

Pull #3900

gitlab-ci

web-flow
chore: bump @testing-library/jest-dom from 5.16.5 to 5.17.0

Bumps [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) from 5.16.5 to 5.17.0.
- [Release notes](https://github.com/testing-library/jest-dom/releases)
- [Changelog](https://github.com/testing-library/jest-dom/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testing-library/jest-dom/compare/v5.16.5...v5.17.0)

---
updated-dependencies:
- dependency-name: "@testing-library/jest-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #3900: chore: bump @testing-library/jest-dom from 5.16.5 to 5.17.0

4446 of 6414 branches covered (69.32%)

8342 of 10084 relevant lines covered (82.73%)

186.0 hits per line

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

90.0
/src/js/components/dashboard/widgets/chart-addition.js
1
// Copyright 2020 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, { useCallback, useState } from 'react';
15

16
import { Add as AddIcon } from '@mui/icons-material';
17
import { Button, FormControl, IconButton, InputLabel, ListSubheader, MenuItem, Select, iconButtonClasses, selectClasses } from '@mui/material';
18
import { makeStyles } from 'tss-react/mui';
19

20
import { chartTypes, emptyChartSelection } from '../../../constants/appConstants';
21
import { toggle } from '../../../helpers';
22
import Confirm from '../../common/confirm';
23
import { Header } from './distribution';
24

25
const fontSize = 'smaller';
7✔
26

27
const useStyles = makeStyles()(theme => ({
7✔
28
  additionButton: { fontSize: '1rem', cursor: 'pointer' },
29
  button: { marginLeft: theme.spacing(2), padding: '6px 8px', fontSize },
30
  buttonWrapper: { display: 'flex', justifyContent: 'flex-end', alignContent: 'center' },
31
  iconButton: {
32
    [`&.${iconButtonClasses.root}`]: {
33
      borderRadius: 5,
34
      border: `1px solid ${theme.palette.primary.main}`,
35
      marginRight: theme.spacing(),
36
      '&.selected': {
37
        background: theme.palette.primary.main,
38
        color: theme.palette.background.paper
39
      }
40
    }
41
  },
42
  formWrapper: {
43
    alignItems: 'baseline',
44
    columnGap: theme.spacing(3),
45
    display: 'grid',
46
    fontSize,
47
    gridTemplateColumns: 'max-content 1fr',
48
    gridTemplateRows: 'auto',
49
    rowGap: theme.spacing(0.5),
50
    marginTop: theme.spacing(),
51
    [`.${selectClasses.select}`]: { paddingBottom: theme.spacing(0.5), paddingTop: 0, fontSize }
52
  }
53
}));
54

55
const GroupSelect = ({ groups, selection, setSelection }) => (
7✔
56
  <FormControl className="margin-top-none">
2✔
57
    <InputLabel id="group-select-label">Device group</InputLabel>
58
    <Select labelId="group-select-label" value={selection.group || true} onChange={e => setSelection({ group: e.target.value })}>
1✔
59
      <MenuItem value={true}>
60
        <em>All Devices</em>
61
      </MenuItem>
62
      {Object.keys(groups).map(group => (
63
        <MenuItem key={group} value={group}>
4✔
64
          {group}
65
        </MenuItem>
66
      ))}
67
    </Select>
68
  </FormControl>
69
);
70

71
const themeSpacing = 8;
7✔
72
const basePadding = 2 * themeSpacing;
7✔
73
const getIndentation = level => ({ paddingLeft: basePadding + level * themeSpacing });
7✔
74

75
const SoftwareSelect = ({ selection, setSelection, software }) => (
7✔
76
  <FormControl className="margin-top-none">
2✔
77
    <InputLabel id="software-select-label">Software</InputLabel>
78
    <Select labelId="software-select-label" value={selection.software} onBlur={undefined} onChange={e => setSelection({ software: e.target.value })}>
×
79
      {software.map(({ subheader, title, value, nestingLevel }) =>
80
        subheader ? (
6✔
81
          <ListSubheader key={value} style={getIndentation(nestingLevel)}>
82
            {subheader}
83
          </ListSubheader>
84
        ) : (
85
          <MenuItem key={value} style={getIndentation(nestingLevel)} value={value}>
86
            {title}
87
          </MenuItem>
88
        )
89
      )}
90
    </Select>
91
  </FormControl>
92
);
93

94
const ChartSelect = ({ classes, selection, setSelection }) => (
7✔
95
  <div>
2✔
96
    {Object.values(chartTypes).map(type => {
97
      const { Icon, key } = type;
4✔
98
      return (
4✔
99
        <IconButton
100
          className={`${classes.iconButton} ${selection.chartType === key ? 'selected' : ''}`}
4✔
101
          key={key}
102
          size="small"
103
          onClick={() => setSelection({ chartType: key })}
×
104
        >
105
          <Icon fontSize="small" />
106
        </IconButton>
107
      );
108
    })}
109
  </div>
110
);
111

112
const chartOptions = [
7✔
113
  { key: 'software', title: 'Software', Selector: SoftwareSelect },
114
  { key: 'group', title: 'Device group', Selector: GroupSelect },
115
  { key: 'type', title: 'Display', Selector: ChartSelect }
116
];
117

118
export const ChartEditWidget = ({ groups, onSave, onCancel, selection: selectionProp = {}, software = [] }) => {
7!
119
  const [selection, setSelection] = useState({ ...emptyChartSelection, ...selectionProp });
2✔
120
  const { classes } = useStyles();
2✔
121

122
  const addCurrentSelection = useCallback(
2✔
123
    () => onSave({ ...emptyChartSelection, ...selection, group: typeof selection.group === 'string' ? selection.group : null }),
1!
124
    [JSON.stringify(selection), onSave]
125
  );
126

127
  const onSelectionChange = changedSelection => setSelection(current => ({ ...current, ...changedSelection }));
2✔
128

129
  return (
2✔
130
    <div className="widget chart-widget">
131
      <Header chartType={selection.chartType} />
132
      <div className={classes.formWrapper}>
133
        {chartOptions.map(({ key, title, Selector }) => (
134
          <React.Fragment key={key}>
6✔
135
            <div>{title}</div>
136
            <Selector classes={classes} groups={groups} software={software} selection={selection} setSelection={onSelectionChange} />
137
          </React.Fragment>
138
        ))}
139
      </div>
140
      <div className={classes.buttonWrapper}>
141
        <Button className={classes.button} size="small" onClick={onCancel}>
142
          Cancel
143
        </Button>
144
        <Button className={classes.button} size="small" onClick={addCurrentSelection} variant="contained" disabled={!selection}>
145
          Save
146
        </Button>
147
      </div>
148
    </div>
149
  );
150
};
151

152
export const RemovalWidget = ({ onCancel, onClick }) => (
7✔
153
  <div className="widget chart-widget">
×
154
    <Confirm classes="flexbox centered confirmation-overlay" cancel={onCancel} action={onClick} style={{ justifyContent: 'center' }} type="chartRemoval" />
155
  </div>
156
);
157

158
export const WidgetAdditionWidget = ({ onAdditionClick, ...remainder }) => {
7✔
159
  const [adding, setAdding] = useState(false);
17✔
160
  const { classes } = useStyles();
17✔
161

162
  const addCurrentSelection = selection => {
17✔
163
    onAdditionClick(selection);
1✔
164
    setAdding(false);
1✔
165
  };
166

167
  const onCancelClick = () => setAdding(toggle);
17✔
168

169
  return adding ? (
17✔
170
    <ChartEditWidget {...remainder} onSave={addCurrentSelection} onCancel={onCancelClick} />
171
  ) : (
172
    <div className="widget">
173
      <div></div>
174
      <div className={`flexbox centered muted ${classes.additionButton}`} onClick={() => setAdding(true)}>
1✔
175
        <AddIcon />
176
        <span className={classes.additionButton}>add a widget</span>
177
      </div>
178
    </div>
179
  );
180
};
181

182
export default WidgetAdditionWidget;
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