• 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

78.41
/src/js/components/settings/artifactgeneration.js
1
// Copyright 2022 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, useMemo, useRef, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { InfoOutlined as InfoOutlinedIcon } from '@mui/icons-material';
19
import { Checkbox, FormControlLabel, TextField, Typography, formControlLabelClasses, textFieldClasses } from '@mui/material';
20
import { makeStyles } from 'tss-react/mui';
21

22
import DeltaIcon from '../../../assets/img/deltaicon.svg';
23
import { getDeploymentsConfig, saveDeltaDeploymentsConfig } from '../../actions/deploymentActions';
24
import { TIMEOUTS } from '../../constants/appConstants';
25
import { getIsEnterprise } from '../../selectors';
26
import { useDebounce } from '../../utils/debouncehook';
27
import EnterpriseNotification from '../common/enterpriseNotification';
28
import InfoText from '../common/infotext';
29

30
const useStyles = makeStyles()(theme => ({
6✔
31
  deviceLimitBar: { backgroundColor: theme.palette.grey[500], margin: '15px 0' },
32
  wrapper: {
33
    backgroundColor: theme.palette.background.lightgrey,
34
    display: 'flex',
35
    flexDirection: 'column',
36
    marginTop: theme.spacing(6),
37
    padding: theme.spacing(2),
38
    paddingTop: 0,
39
    '&>h5': { marginTop: 0, marginBottom: 0 },
40
    '.flexbox>span': { alignSelf: 'flex-end' },
41
    [`.${textFieldClasses.root}`]: { maxWidth: 200, minWidth: 100 },
42
    [`.${formControlLabelClasses.root}`]: { marginTop: theme.spacing() }
43
  }
44
}));
45

46
const numberFields = {
6✔
47
  compressionLevel: { key: 'compressionLevel', title: 'Compression level' },
48
  sourceWindow: { key: 'sourceWindow', title: 'Source window size' },
49
  inputWindow: { key: 'inputWindow', title: 'Input window size' },
50
  duplicatesWindow: { key: 'duplicatesWindow', title: 'Compression duplicates window' },
51
  instructionBuffer: { key: 'instructionBuffer', title: 'Instruction buffer size' }
52
};
53

54
const NumberInputLimited = ({ limit, onChange, value: propsValue, ...remainder }) => {
6✔
55
  const [value, setValue] = useState(propsValue);
12✔
56
  const debouncedValue = useDebounce(value, TIMEOUTS.oneSecond);
12✔
57
  const { default: defaultValue, max, min } = limit;
12✔
58

59
  useEffect(() => {
12✔
60
    const minimum = Math.max(min, debouncedValue);
6✔
61
    const allowedValue = Math.min(max ?? minimum, minimum);
6✔
62
    if (allowedValue !== debouncedValue) {
6!
63
      setValue(allowedValue);
6✔
64
      return;
6✔
65
    }
66
    onChange(allowedValue);
×
67
  }, [debouncedValue]);
68

69
  return (
12✔
70
    <TextField
71
      inputProps={{ step: 1, type: 'numeric', pattern: '[0-9]*', autoComplete: 'off' }}
72
      InputLabelProps={{ shrink: true }}
73
      error={min || max ? min > value || value > max : false}
41✔
74
      value={value}
75
      onChange={({ target: { value } }) => setValue(Number(value) || 0)}
×
76
      helperText={defaultValue !== undefined ? `Defaults to: ${defaultValue}` : null}
12✔
77
      {...remainder}
78
    />
79
  );
80
};
81

82
export const ArtifactGenerationSettings = () => {
6✔
83
  const { binaryDelta: deltaConfig = {}, binaryDeltaLimits: deltaLimits = {}, hasDelta: deltaEnabled } = useSelector(state => state.deployments.config) ?? {};
4!
84
  const isEnterprise = useSelector(getIsEnterprise);
3✔
85
  const dispatch = useDispatch();
3✔
86
  const [timeoutValue, setTimeoutValue] = useState(deltaConfig.timeout);
3✔
87
  const [disableChecksum, setDisableChecksum] = useState(deltaConfig.disableChecksum);
3✔
88
  const [disableDecompression, setDisableDecompression] = useState(deltaConfig.disableChecksum);
3✔
89
  const [compressionLevel, setCompressionLevel] = useState(deltaConfig.compressionLevel);
3✔
90
  const [sourceWindow, setSourceWindow] = useState(deltaConfig.sourceWindow);
3✔
91
  const [inputWindow, setInputWindow] = useState(deltaConfig.inputWindow);
3✔
92
  const [duplicatesWindow, setDuplicatesWindow] = useState(deltaConfig.duplicatesWindow);
3✔
93
  const [instructionBuffer, setInstructionBuffer] = useState(deltaConfig.instructionBuffer);
3✔
94
  const [isInitialized, setIsInitialized] = useState(false);
3✔
95
  const timer = useRef(null);
3✔
96

97
  const { classes } = useStyles();
3✔
98

99
  useEffect(() => {
3✔
100
    if (deltaConfig.timeout === -1) {
1!
101
      return;
×
102
    }
103
    const { timeout, duplicatesWindow, compressionLevel, disableChecksum, disableDecompression, inputWindow, instructionBuffer, sourceWindow } = deltaConfig;
1✔
104
    setDisableChecksum(disableChecksum);
1✔
105
    setDisableDecompression(disableDecompression);
1✔
106
    setCompressionLevel(compressionLevel);
1✔
107
    setTimeoutValue(timeout);
1✔
108
    setSourceWindow(sourceWindow);
1✔
109
    setInputWindow(inputWindow);
1✔
110
    setDuplicatesWindow(duplicatesWindow);
1✔
111
    setInstructionBuffer(instructionBuffer);
1✔
112
    setTimeout(() => setIsInitialized(true), 0);
1✔
113
  }, [JSON.stringify(deltaConfig), JSON.stringify(deltaLimits)]);
114

115
  useEffect(() => {
3✔
116
    dispatch(getDeploymentsConfig());
1✔
117
  }, []);
118

119
  useEffect(() => {
3✔
120
    if (!isInitialized) {
1!
121
      return;
1✔
122
    }
123
    clearTimeout(timer.current);
×
124
    timer.current = setTimeout(
×
125
      () =>
126
        dispatch(
×
127
          saveDeltaDeploymentsConfig({
128
            timeout: timeoutValue,
129
            duplicatesWindow,
130
            compressionLevel,
131
            disableChecksum,
132
            disableDecompression,
133
            inputWindow,
134
            instructionBuffer,
135
            sourceWindow
136
          })
137
        ),
138
      TIMEOUTS.twoSeconds
139
    );
140
    return () => {
×
141
      clearTimeout(timer.current);
×
142
    };
143
  }, [compressionLevel, disableChecksum, disableDecompression, duplicatesWindow, inputWindow, instructionBuffer, sourceWindow, timeoutValue]);
144

145
  const numberInputs = useMemo(() => {
3✔
146
    return [
1✔
147
      { ...numberFields.compressionLevel, setter: setCompressionLevel, value: compressionLevel, ...deltaLimits.compressionLevel },
148
      { ...numberFields.sourceWindow, setter: setSourceWindow, value: sourceWindow, ...deltaLimits.sourceWindow },
149
      { ...numberFields.inputWindow, setter: setInputWindow, value: inputWindow, ...deltaLimits.inputWindow },
150
      { ...numberFields.duplicatesWindow, setter: setDuplicatesWindow, value: duplicatesWindow, ...deltaLimits.duplicatesWindow },
151
      { ...numberFields.instructionBuffer, setter: setInstructionBuffer, value: instructionBuffer, ...deltaLimits.instructionBuffer }
152
    ];
153
  }, [
154
    compressionLevel,
155
    setCompressionLevel,
156
    setSourceWindow,
157
    sourceWindow,
158
    inputWindow,
159
    setInputWindow,
160
    setDuplicatesWindow,
161
    duplicatesWindow,
162
    setInstructionBuffer,
163
    instructionBuffer,
164
    JSON.stringify(deltaLimits)
165
  ]);
166

167
  return (
3✔
168
    <div className={`flexbox column ${classes.wrapper}`}>
169
      <div className="flexbox center-aligned">
170
        <DeltaIcon />
171
        <h5 className="margin-left-small">Delta artifacts generation configuration</h5>
172
      </div>
173
      {deltaEnabled && isInitialized ? (
9✔
174
        <div className="margin-small margin-top-none">
175
          <div className="flexbox">
176
            <NumberInputLimited
177
              limit={{ default: deltaLimits.timeout.default, min: deltaLimits.timeout.min, max: deltaLimits.timeout.max }}
178
              label="Timeout"
179
              onChange={setTimeoutValue}
180
              value={timeoutValue}
181
            />
182
            <span className="margin-left-small muted slightly-smaller">seconds</span>
183
          </div>
184
          <Typography className="margin-top-small" display="block" variant="caption">
185
            xDelta3 arguments
186
          </Typography>
187
          <div className="flexbox column margin-left">
188
            <FormControlLabel
189
              control={<Checkbox color="primary" checked={disableChecksum} onChange={({ target: { checked } }) => setDisableChecksum(checked)} size="small" />}
×
190
              label="Disable checksum"
191
            />
192
            <FormControlLabel
193
              control={
194
                <Checkbox
195
                  color="primary"
196
                  checked={disableDecompression}
197
                  onChange={({ target: { checked } }) => setDisableDecompression(checked)}
×
198
                  size="small"
199
                />
200
              }
201
              label="Disable external decompression"
202
            />
203
            {numberInputs.map(({ default: defaultValue, key, setter, title, value, min = 0, max }) => (
1✔
204
              <NumberInputLimited key={key} limit={{ default: defaultValue, max, min }} label={title} value={value} onChange={setter} />
5✔
205
            ))}
206
          </div>
207
        </div>
208
      ) : isEnterprise ? (
2!
209
        <InfoText>
210
          <InfoOutlinedIcon style={{ fontSize: '14px', margin: '0 4px 4px 0', verticalAlign: 'middle' }} />
211
          Automatic delta artifacts generation is not enabled in your account. If you want to start using this feature,{' '}
212
          <a href="mailto:contact@mender.io" target="_blank" rel="noopener noreferrer">
213
            contact our team
214
          </a>
215
          .
216
        </InfoText>
217
      ) : (
218
        <EnterpriseNotification
219
          isEnterprise={isEnterprise}
220
          benefit="automatic delta artifacts generation to minimize data transfer and improve the update delivery"
221
        />
222
      )}
223
    </div>
224
  );
225
};
226

227
export default ArtifactGenerationSettings;
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