• 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

69.13
/src/js/components/deployments/report.js
1
// Copyright 2015 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

17
// material ui
18
import {
19
  Block as BlockIcon,
20
  CheckCircleOutline as CheckCircleOutlineIcon,
21
  Close as CloseIcon,
22
  Link as LinkIcon,
23
  Refresh as RefreshIcon
24
} from '@mui/icons-material';
25
import { Button, Divider, Drawer, IconButton, Tooltip } from '@mui/material';
26
import { makeStyles } from 'tss-react/mui';
27

28
import copy from 'copy-to-clipboard';
29
import moment from 'moment';
30
import momentDurationFormatSetup from 'moment-duration-format';
31

32
import { setSnackbar } from '../../actions/appActions';
33
import { getDeploymentDevices, getDeviceLog, getSingleDeployment, updateDeploymentControlMap } from '../../actions/deploymentActions';
34
import { getAuditLogs } from '../../actions/organizationActions';
35
import { getRelease } from '../../actions/releaseActions';
36
import { TIMEOUTS } from '../../constants/appConstants';
37
import { DEPLOYMENT_STATES, DEPLOYMENT_TYPES, deploymentStatesToSubstates } from '../../constants/deploymentConstants';
38
import { AUDIT_LOGS_TYPES } from '../../constants/organizationConstants';
39
import { statCollector, toggle } from '../../helpers';
40
import { getDeploymentRelease, getDevicesById, getIdAttribute, getTenantCapabilities, getUserCapabilities } from '../../selectors';
41
import ConfigurationObject from '../common/configurationobject';
42
import Confirm from '../common/confirm';
43
import LogDialog from '../common/dialogs/log';
44
import LinedHeader from '../common/lined-header';
45
import DeploymentStatus, { DeploymentPhaseNotification } from './deployment-report/deploymentstatus';
46
import DeviceList from './deployment-report/devicelist';
47
import DeploymentOverview from './deployment-report/overview';
48
import RolloutSchedule from './deployment-report/rolloutschedule';
49

50
momentDurationFormatSetup(moment);
11✔
51

52
const useStyles = makeStyles()(theme => ({
11✔
53
  divider: { marginTop: theme.spacing(2) },
54
  header: {
55
    ['&.dashboard-header span']: {
56
      backgroundColor: theme.palette.background.paper,
57
      backgroundImage: 'linear-gradient(rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.15))'
58
    }
59
  }
60
}));
61

62
export const defaultColumnDataProps = {
11✔
63
  chipLikeKey: false,
64
  style: { alignItems: 'center', alignSelf: 'flex-start', gridTemplateColumns: 'minmax(140px, 1fr) minmax(220px, 1fr)', maxWidth: '25vw' }
65
};
66

67
export const DeploymentAbortButton = ({ abort, deployment }) => {
11✔
68
  const [aborting, setAborting] = useState(false);
4✔
69

70
  const toggleAborting = () => setAborting(toggle);
4✔
71

72
  return aborting ? (
4!
73
    <Confirm cancel={toggleAborting} action={() => abort(deployment.id)} type="abort" />
×
74
  ) : (
75
    <Tooltip
76
      title="Devices that have not yet started the deployment will not start the deployment.&#10;Devices that have already completed the deployment are not affected by the abort.&#10;Devices that are in the middle of the deployment at the time of abort will finish deployment normally, but will perform a rollback."
77
      placement="bottom"
78
    >
79
      <Button color="secondary" startIcon={<BlockIcon fontSize="small" />} onClick={toggleAborting}>
80
        {deployment.filters?.length ? 'Stop' : 'Abort'} deployment
4!
81
      </Button>
82
    </Tooltip>
83
  );
84
};
85

86
export const DeploymentReport = ({ abort, open, onClose, past, retry, type }) => {
11✔
87
  const [deviceId, setDeviceId] = useState('');
354✔
88
  const rolloutSchedule = useRef();
354✔
89
  const timer = useRef();
354✔
90
  const { classes } = useStyles();
354✔
91
  const dispatch = useDispatch();
354✔
92
  const { deployment, selectedDevices } = useSelector(state => {
354✔
93
    const deployment = state.deployments.byId[state.deployments.selectionState.selectedId] || {};
644✔
94
    const { devices = {} } = deployment;
644✔
95
    const { selectedDeviceIds } = state.deployments;
644✔
96
    return {
644✔
97
      deployment,
98
      selectedDevices: selectedDeviceIds.map(deviceId => ({ ...state.devices.byId[deviceId], ...devices[deviceId] }))
2✔
99
    };
100
  });
101
  const devicesById = useSelector(getDevicesById);
354✔
102
  const { attribute: idAttribute } = useSelector(getIdAttribute);
354✔
103
  const release = useSelector(getDeploymentRelease);
354✔
104
  const tenantCapabilities = useSelector(getTenantCapabilities);
354✔
105
  const userCapabilities = useSelector(getUserCapabilities);
354✔
106
  // we can't filter by auditlog action via the api, so
107
  // - fall back to the following filter
108
  // - hope the deployment creation event is retrieved with the call to auditlogs api on report open
109
  // - otherwise no creator will be shown
110
  const { actor = {} } =
354✔
111
    useSelector(state =>
354✔
112
      state.organization.auditlog.events.find(event => event.object.id === state.deployments.selectionState.selectedId && event.action === 'create')
1,932!
113
    ) || {};
114
  const creator = actor.email;
354✔
115

116
  const { canAuditlog } = userCapabilities;
354✔
117
  const { hasAuditlogs } = tenantCapabilities;
354✔
118
  const { devices = {}, device_count = 0, totalDeviceCount: totalDevices, statistics = {}, type: deploymentType } = deployment;
354✔
119
  const { status: stats = {} } = statistics;
354✔
120
  const totalDeviceCount = totalDevices ?? device_count;
354✔
121

122
  useEffect(() => {
354✔
123
    if (!open) {
13✔
124
      return;
11✔
125
    }
126
    clearInterval(timer.current);
2✔
127
    if (!(deployment.finished || deployment.status === DEPLOYMENT_STATES.finished)) {
2!
128
      timer.current = past ? null : setInterval(refreshDeployment, TIMEOUTS.fiveSeconds);
2!
129
    }
130
    if ((deployment.type === DEPLOYMENT_TYPES.software || !release.device_types_compatible.length) && deployment.artifact_name) {
2!
131
      dispatch(getRelease(deployment.artifact_name));
×
132
    }
133
    if (hasAuditlogs && canAuditlog) {
2!
134
      dispatch(
×
135
        getAuditLogs({
136
          page: 1,
137
          perPage: 100,
138
          startDate: undefined,
139
          endDate: undefined,
140
          user: undefined,
141
          type: AUDIT_LOGS_TYPES.find(item => item.value === 'deployment'),
×
142
          detail: deployment.name
143
        })
144
      );
145
    }
146
    return () => {
2✔
147
      clearInterval(timer.current);
2✔
148
    };
149
  }, [deployment.id, open]);
150

151
  useEffect(() => {
354✔
152
    const progressCount =
153
      statCollector(deploymentStatesToSubstates.paused, stats) +
13✔
154
      statCollector(deploymentStatesToSubstates.pending, stats) +
155
      statCollector(deploymentStatesToSubstates.inprogress, stats);
156

157
    if (!!device_count && progressCount <= 0 && timer.current) {
13!
158
      // if no more devices in "progress" statuses, deployment has finished, stop counter
159
      clearInterval(timer.current);
×
160
      timer.current = setTimeout(refreshDeployment, TIMEOUTS.oneSecond);
×
161
      return () => {
×
162
        clearTimeout(timer.current);
×
163
      };
164
    }
165
  }, [deployment.id, device_count, JSON.stringify(stats)]);
166

167
  const scrollToBottom = () => {
354✔
168
    rolloutSchedule.current?.scrollIntoView({ behavior: 'smooth' });
×
169
  };
170

171
  const refreshDeployment = () => {
354✔
172
    if (!deployment.id) {
1!
173
      return;
×
174
    }
175
    return dispatch(getSingleDeployment(deployment.id));
1✔
176
  };
177

178
  const viewLog = id => dispatch(getDeviceLog(deployment.id, id)).then(() => setDeviceId(id));
354✔
179

180
  const copyLinkToClipboard = () => {
354✔
181
    const location = window.location.href.substring(0, window.location.href.indexOf('/deployments') + '/deployments'.length);
×
182
    copy(`${location}?open=true&id=${deployment.id}`);
×
183
    dispatch(setSnackbar('Link copied to clipboard'));
×
184
  };
185

186
  const { log: logData } = devices[deviceId] || {};
354✔
187
  const finished = deployment.finished || deployment.status === DEPLOYMENT_STATES.finished;
354✔
188
  const isConfigurationDeployment = deploymentType === DEPLOYMENT_TYPES.configuration;
354✔
189
  let config = {};
354✔
190
  if (isConfigurationDeployment) {
354!
191
    try {
×
192
      config = JSON.parse(atob(deployment.configuration));
×
193
    } catch (error) {
194
      config = {};
×
195
    }
196
  }
197

198
  const onUpdateControlChange = (updatedMap = {}) => {
354!
199
    const { id, update_control_map = {} } = deployment;
×
200
    const { states } = update_control_map;
×
201
    const { states: updatedStates } = updatedMap;
×
202
    dispatch(updateDeploymentControlMap(id, { states: { ...states, ...updatedStates } }));
×
203
  };
204

205
  const props = {
354✔
206
    deployment,
207
    getDeploymentDevices: (id, options) => dispatch(getDeploymentDevices(id, options)),
2✔
208
    idAttribute,
209
    selectedDevices,
210
    userCapabilities,
211
    totalDeviceCount,
212
    viewLog
213
  };
214

215
  return (
354✔
216
    <Drawer className={`${open ? 'fadeIn' : 'fadeOut'}`} anchor="right" open={open} onClose={onClose} PaperProps={{ style: { minWidth: '75vw' } }}>
354✔
217
      <div className="flexbox margin-bottom-small space-between">
218
        <div className="flexbox">
219
          <h3>{`Deployment ${type !== DEPLOYMENT_STATES.scheduled ? 'details' : 'report'}`}</h3>
354!
220
          <h4 className="margin-left-small margin-right-small">ID: {deployment.id}</h4>
221
          <IconButton onClick={copyLinkToClipboard} style={{ alignSelf: 'center' }} size="large">
222
            <LinkIcon />
223
          </IconButton>
224
        </div>
225
        <div className="flexbox center-aligned">
226
          {!finished ? (
354!
227
            <DeploymentAbortButton abort={abort} deployment={deployment} />
228
          ) : (stats.failure || stats.aborted) && !isConfigurationDeployment ? (
×
229
            <Tooltip
230
              title="This will create a new deployment with the same device group and Release.&#10;Devices with this Release already installed will be skipped, all others will be updated."
231
              placement="bottom"
232
            >
233
              <Button color="secondary" startIcon={<RefreshIcon fontSize="small" />} onClick={() => retry(deployment, Object.keys(devices))}>
×
234
                Recreate deployment?
235
              </Button>
236
            </Tooltip>
237
          ) : (
238
            <div className="flexbox centered margin-right">
239
              <CheckCircleOutlineIcon fontSize="small" className="green margin-right-small" />
240
              <h3>Finished</h3>
241
            </div>
242
          )}
243
          <IconButton onClick={onClose} aria-label="close" size="large">
244
            <CloseIcon />
245
          </IconButton>
246
        </div>
247
      </div>
248
      <Divider />
249
      <div>
250
        <DeploymentPhaseNotification deployment={deployment} onReviewClick={scrollToBottom} />
251
        <DeploymentOverview
252
          creator={creator}
253
          deployment={deployment}
254
          devicesById={devicesById}
255
          onScheduleClick={scrollToBottom}
256
          tenantCapabilities={tenantCapabilities}
257
        />
258
        {isConfigurationDeployment && (
354!
259
          <>
260
            <LinedHeader className={classes.header} heading="Configuration" />
261
            <ConfigurationObject className="margin-top-small margin-bottom-large" config={config} />
262
          </>
263
        )}
264
        <LinedHeader className={classes.header} heading="Status" />
265
        <DeploymentStatus deployment={deployment} />
266
        {!!totalDeviceCount && (
361✔
267
          <>
268
            <LinedHeader className={classes.header} heading="Devices" />
269
            <DeviceList {...props} viewLog={viewLog} />
270
          </>
271
        )}
272
        <RolloutSchedule
273
          deployment={deployment}
274
          headerClass={classes.header}
275
          onUpdateControlChange={onUpdateControlChange}
276
          onAbort={abort}
277
          innerRef={rolloutSchedule}
278
        />
279
        {Boolean(deviceId.length) && <LogDialog logData={logData} onClose={() => setDeviceId('')} />}
×
280
      </div>
281
      <Divider className={classes.divider} light />
282
    </Drawer>
283
  );
284
};
285
export default DeploymentReport;
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