• 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

83.22
/src/js/components/deployments/pastdeployments.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 { Autocomplete, TextField } from '@mui/material';
19
import { makeStyles } from 'tss-react/mui';
20

21
import historyImage from '../../../assets/img/history.png';
22
import { setSnackbar } from '../../actions/appActions';
23
import { getDeploymentsByStatus, setDeploymentsState } from '../../actions/deploymentActions';
24
import { advanceOnboarding } from '../../actions/onboardingActions';
25
import { BEGINNING_OF_TIME, SORTING_OPTIONS, TIMEOUTS } from '../../constants/appConstants';
26
import { DEPLOYMENT_STATES, DEPLOYMENT_TYPES } from '../../constants/deploymentConstants';
27
import { onboardingSteps } from '../../constants/onboardingConstants';
28
import { getISOStringBoundaries } from '../../helpers';
29
import {
30
  getDeploymentsSelectionState,
31
  getDevicesById,
32
  getGroupNames,
33
  getIdAttribute,
34
  getMappedDeploymentSelection,
35
  getOnboardingState,
36
  getUserCapabilities
37
} from '../../selectors';
38
import { useDebounce } from '../../utils/debouncehook';
39
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
40
import useWindowSize from '../../utils/resizehook';
41
import { clearAllRetryTimers, clearRetryTimer, setRetryTimer } from '../../utils/retrytimer';
42
import TimeframePicker from '../common/timeframe-picker';
43
import TimerangePicker from '../common/timerange-picker';
44
import { DeploymentSize, DeploymentStatus } from './deploymentitem';
45
import { defaultRefreshDeploymentsLength as refreshDeploymentsLength } from './deployments';
46
import DeploymentsList, { defaultHeaders } from './deploymentslist';
47

48
const headers = [
7✔
49
  ...defaultHeaders.slice(0, defaultHeaders.length - 1),
50
  { title: 'Status', renderer: DeploymentStatus },
51
  { title: 'Data downloaded', renderer: DeploymentSize }
52
];
53

54
const type = DEPLOYMENT_STATES.finished;
7✔
55

56
const useStyles = makeStyles()(theme => ({
7✔
57
  datepickerContainer: {
58
    backgroundColor: theme.palette.background.lightgrey
59
  }
60
}));
61

62
export const Past = props => {
7✔
63
  const { createClick, isShowingDetails } = props;
69✔
64
  // eslint-disable-next-line no-unused-vars
65
  const size = useWindowSize();
68✔
66
  const [tonight] = useState(getISOStringBoundaries(new Date()).end);
68✔
67
  const [loading, setLoading] = useState(false);
68✔
68
  const deploymentsRef = useRef();
68✔
69
  const timer = useRef();
68✔
70
  const [searchValue, setSearchValue] = useState('');
68✔
71
  const [typeValue, setTypeValue] = useState('');
68✔
72
  const { classes } = useStyles();
68✔
73

74
  const dispatch = useDispatch();
68✔
75
  const dispatchedSetSnackbar = (...args) => dispatch(setSnackbar(...args));
68✔
76

77
  const { finished: pastSelectionState } = useSelector(getDeploymentsSelectionState);
68✔
78
  const past = useSelector(state => getMappedDeploymentSelection(state, type));
126✔
79
  const { canConfigure, canDeploy } = useSelector(getUserCapabilities);
68✔
80
  const { attribute: idAttribute } = useSelector(getIdAttribute);
68✔
81
  const onboardingState = useSelector(getOnboardingState);
68✔
82
  const devices = useSelector(getDevicesById);
68✔
83
  const groupNames = useSelector(getGroupNames);
68✔
84

85
  const debouncedSearch = useDebounce(searchValue, TIMEOUTS.debounceDefault);
68✔
86
  const debouncedType = useDebounce(typeValue, TIMEOUTS.debounceDefault);
68✔
87

88
  const { endDate, page, perPage, search: deviceGroup, startDate, total: count, type: deploymentType } = pastSelectionState;
68✔
89

90
  useEffect(() => {
68✔
91
    const roundedStartDate = Math.round(Date.parse(startDate || BEGINNING_OF_TIME) / 1000);
3✔
92
    const roundedEndDate = Math.round(Date.parse(endDate) / 1000);
3✔
93
    setLoading(true);
3✔
94
    dispatch(getDeploymentsByStatus(type, page, perPage, roundedStartDate, roundedEndDate, deviceGroup, deploymentType, true, SORTING_OPTIONS.desc))
3✔
95
      .then(deploymentsAction => {
96
        const deploymentsList = deploymentsAction ? Object.values(deploymentsAction[0].deployments) : [];
2!
97
        if (deploymentsList.length) {
2!
98
          let newStartDate = new Date(deploymentsList[deploymentsList.length - 1].created);
2✔
99
          const { start: startDate } = getISOStringBoundaries(newStartDate);
2✔
100
          dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { startDate } }));
2✔
101
        }
102
      })
103
      .finally(() => setLoading(false));
2✔
104
    return () => {
3✔
105
      clearAllRetryTimers(dispatchedSetSnackbar);
3✔
106
    };
107
  }, []);
108

109
  useEffect(() => {
68✔
110
    clearInterval(timer.current);
4✔
111
    timer.current = setInterval(refreshPast, refreshDeploymentsLength);
4✔
112
    refreshPast();
4✔
113
    return () => {
4✔
114
      clearInterval(timer.current);
4✔
115
    };
116
  }, [page, perPage, startDate, endDate, deviceGroup, deploymentType]);
117

118
  useEffect(() => {
68✔
119
    if (!past.length || onboardingState.complete) {
4✔
120
      return;
1✔
121
    }
122
    const pastDeploymentsFailed = past.reduce(
3✔
123
      (accu, item) =>
124
        item.status === 'failed' ||
4✔
125
        (item.statistics?.status &&
126
          item.statistics.status.noartifact + item.statistics.status.failure + item.statistics.status['already-installed'] + item.statistics.status.aborted >
127
            0) ||
128
        accu,
129
      false
130
    );
131
    let onboardingStep = onboardingSteps.DEPLOYMENTS_PAST_COMPLETED_NOTIFICATION;
3✔
132
    if (pastDeploymentsFailed) {
3!
133
      onboardingStep = onboardingSteps.DEPLOYMENTS_PAST_COMPLETED_FAILURE;
×
134
    }
135
    dispatch(advanceOnboarding(onboardingStep));
3✔
136
    setTimeout(() => {
3✔
137
      let notification = getOnboardingComponentFor(onboardingSteps.DEPLOYMENTS_PAST_COMPLETED_NOTIFICATION, onboardingState, {
2✔
138
        setSnackbar: dispatchedSetSnackbar
139
      });
140
      // the following extra check is needed since this component will still be mounted if a user returns to the initial tab after the first
141
      // onboarding deployment & thus the effects will still run, so only ever consider the notification for the second deployment
142
      notification =
2✔
143
        past.length > 1
2✔
144
          ? getOnboardingComponentFor(onboardingSteps.ONBOARDING_FINISHED_NOTIFICATION, onboardingState, { setSnackbar: dispatchedSetSnackbar }, notification)
145
          : notification;
146
      !!notification && dispatch(setSnackbar('open', TIMEOUTS.refreshDefault, '', notification, () => {}, true));
2!
147
    }, TIMEOUTS.debounceDefault);
148
  }, [past.length, onboardingState.complete]);
149

150
  useEffect(() => {
68✔
151
    dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page: 1, search: debouncedSearch, type: debouncedType } }));
3✔
152
  }, [debouncedSearch, debouncedType]);
153

154
  /*
155
  / refresh only finished deployments
156
  /
157
  */
158
  const refreshPast = (
68✔
159
    currentPage = page,
4✔
160
    currentPerPage = perPage,
4✔
161
    currentStartDate = startDate,
4✔
162
    currentEndDate = endDate,
4✔
163
    currentDeviceGroup = deviceGroup,
4✔
164
    currentType = deploymentType
4✔
165
  ) => {
166
    const roundedStartDate = Math.round(Date.parse(currentStartDate) / 1000);
4✔
167
    const roundedEndDate = Math.round(Date.parse(currentEndDate) / 1000);
4✔
168
    setLoading(true);
4✔
169
    return dispatch(getDeploymentsByStatus(type, currentPage, currentPerPage, roundedStartDate, roundedEndDate, currentDeviceGroup, currentType))
4✔
170
      .then(deploymentsAction => {
171
        setLoading(false);
3✔
172
        clearRetryTimer(type, dispatchedSetSnackbar);
3✔
173
        const { total, deploymentIds } = deploymentsAction[deploymentsAction.length - 1];
3✔
174
        if (total && !deploymentIds.length) {
3!
175
          return refreshPast(currentPage, currentPerPage, currentStartDate, currentEndDate, currentDeviceGroup);
×
176
        }
177
      })
178
      .catch(err => setRetryTimer(err, 'deployments', `Couldn't load deployments.`, refreshDeploymentsLength, dispatchedSetSnackbar));
×
179
  };
180

181
  let onboardingComponent = null;
68✔
182
  if (deploymentsRef.current) {
68✔
183
    const detailsButtons = deploymentsRef.current.getElementsByClassName('MuiButton-contained');
36✔
184
    const left = detailsButtons.length
36!
185
      ? deploymentsRef.current.offsetLeft + detailsButtons[0].offsetLeft + detailsButtons[0].offsetWidth / 2 + 15
186
      : deploymentsRef.current.offsetWidth;
187
    let anchor = { left: deploymentsRef.current.offsetWidth / 2, top: deploymentsRef.current.offsetTop };
36✔
188
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.DEPLOYMENTS_PAST_COMPLETED, onboardingState, {
36✔
189
      anchor,
190
      setSnackbar: dispatchedSetSnackbar
191
    });
192
    onboardingComponent = getOnboardingComponentFor(
36✔
193
      onboardingSteps.DEPLOYMENTS_PAST_COMPLETED_FAILURE,
194
      onboardingState,
195
      { anchor: { left, top: detailsButtons[0].parentElement.offsetTop + detailsButtons[0].parentElement.offsetHeight } },
196
      onboardingComponent
197
    );
198
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.ONBOARDING_FINISHED, onboardingState, { anchor }, onboardingComponent);
36✔
199
  }
200

201
  const onGroupFilterChange = (e, value) => {
68✔
202
    if (!e) {
×
203
      return;
×
204
    }
205
    setSearchValue(value);
×
206
  };
207

208
  const onTypeFilterChange = (e, value) => {
68✔
209
    if (!e) {
×
210
      return;
×
211
    }
212
    setTypeValue(value);
×
213
  };
214

215
  const onTimeFilterChange = (startDate, endDate) => dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page: 1, startDate, endDate } }));
68✔
216

217
  return (
68✔
218
    <div className="fadeIn margin-left margin-top-large">
219
      <div className={`datepicker-container ${classes.datepickerContainer}`}>
220
        <TimerangePicker endDate={endDate} onChange={onTimeFilterChange} startDate={startDate} />
221
        <TimeframePicker onChange={onTimeFilterChange} endDate={endDate} startDate={startDate} tonight={tonight} />
222
        <Autocomplete
223
          id="device-group-selection"
224
          autoHighlight
225
          autoSelect
226
          filterSelectedOptions
227
          freeSolo
228
          handleHomeEndKeys
229
          inputValue={deviceGroup}
230
          options={groupNames}
231
          onInputChange={onGroupFilterChange}
232
          renderInput={params => (
233
            <TextField {...params} label="Filter by device group" placeholder="Select a group" InputProps={{ ...params.InputProps }} style={{ marginTop: 0 }} />
67✔
234
          )}
235
        />
236
        <Autocomplete
237
          id="deployment-type-selection"
238
          autoHighlight
239
          autoSelect
240
          filterSelectedOptions
241
          handleHomeEndKeys
242
          classes={{ input: deploymentType ? 'capitalized' : '', option: 'capitalized' }}
68!
243
          inputValue={deploymentType}
244
          onInputChange={onTypeFilterChange}
245
          options={Object.keys(DEPLOYMENT_TYPES)}
246
          renderInput={params => (
247
            <TextField {...params} label="Filter by type" placeholder="Select a type" InputProps={{ ...params.InputProps }} style={{ marginTop: 0 }} />
67✔
248
          )}
249
        />
250
      </div>
251
      <div className="deploy-table-contain">
252
        {/* TODO: fix status retrieval for past deployments to decide what to show here - */}
253
        {!loading && !!past.length && !!onboardingComponent && !isShowingDetails && onboardingComponent}
129!
254
        {!!past.length && (
107✔
255
          <DeploymentsList
256
            {...props}
257
            canConfigure={canConfigure}
258
            canDeploy={canDeploy}
259
            componentClass="margin-left-small"
260
            count={count}
261
            devices={devices}
262
            headers={headers}
263
            idAttribute={idAttribute}
264
            items={past}
265
            loading={loading}
266
            onChangePage={page => dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page } }))}
×
267
            onChangeRowsPerPage={perPage => dispatch(setDeploymentsState({ [DEPLOYMENT_STATES.finished]: { page: 1, perPage } }))}
×
268
            page={page}
269
            pageSize={perPage}
270
            rootRef={deploymentsRef}
271
            showPagination
272
            type={type}
273
          />
274
        )}
275
        {!(loading || past.length) && (
168✔
276
          <div className="dashboard-placeholder">
277
            <p>No finished deployments were found.</p>
278
            <p>
279
              Try adjusting the filters, or <a onClick={createClick}>Create a new deployment</a> to get started
280
            </p>
281
            <img src={historyImage} alt="Past" />
282
          </div>
283
        )}
284
      </div>
285
    </div>
286
  );
287
};
288

289
export default Past;
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