• 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

96.88
/src/js/components/releases/dialogs/artifactinformationform.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, { useEffect, useState } from 'react';
15
import { FormProvider, useForm } from 'react-hook-form';
16

17
import { FormControl, Input, InputLabel, TextField } from '@mui/material';
18

19
import ChipSelect from '../../common/chipselect';
20
import { DOCSTIPS, DocsTooltip } from '../../common/docslink';
21
import { InfoHintContainer } from '../../common/info-hint';
22
import { HELPTOOLTIPS, MenderHelpTooltip } from '../../helptips/helptooltips';
23
import { FileInformation } from './addartifact';
24

25
const defaultVersion = '1.0.0';
6✔
26

27
export const VersionInformation = ({ creation = {}, onRemove, updateCreation }) => {
6!
28
  const { file, fileSystem: propFs, name, softwareName: propName, softwareVersion: version = '', type } = creation;
2!
29
  const [fileSystem, setFileSystem] = useState(propFs);
2✔
30
  const [softwareName, setSoftwareName] = useState(propName || name.replace('.', '-'));
2✔
31
  const [softwareVersion, setSoftwareVersion] = useState(version || defaultVersion);
2✔
32

33
  useEffect(() => {
2✔
34
    updateCreation({ finalStep: true });
1✔
35
  }, [updateCreation]);
36

37
  useEffect(() => {
2✔
38
    updateCreation({ fileSystem, softwareName, softwareVersion, isValid: fileSystem && softwareName && softwareVersion });
1✔
39
  }, [fileSystem, softwareName, softwareVersion, updateCreation]);
40

41
  return (
2✔
42
    <>
43
      <FileInformation file={file} type={type} onRemove={onRemove} />
44
      <h4>Version information</h4>
45
      <div className="flexbox column">
46
        {[
47
          { key: 'fileSystem', title: 'Software filesystem', setter: setFileSystem, value: fileSystem },
48
          { key: 'softwareName', title: 'Software name', setter: setSoftwareName, value: softwareName },
49
          { key: 'softwareVersion', title: 'Software version', setter: setSoftwareVersion, value: softwareVersion }
50
        ].map(({ key, title, setter, value: currentValue }, index) => (
51
          <TextField autoFocus={!index} fullWidth key={key} label={title} onChange={({ target: { value } }) => setter(value)} value={currentValue} />
6✔
52
        ))}
53
      </div>
54
    </>
55
  );
56
};
57

58
const checkDestinationValidity = destination => (destination.length ? /^(?:\/|[a-z]+:\/\/)/.test(destination) : true);
144✔
59

60
export const ArtifactInformation = ({ creation = {}, deviceTypes = [], onRemove, updateCreation }) => {
6!
61
  const { destination = '', file, name = '', selectedDeviceTypes = [], type } = creation;
89✔
62

63
  const methods = useForm({ mode: 'onChange', defaultValues: { deviceTypes: selectedDeviceTypes } });
89✔
64
  const { watch } = methods;
89✔
65
  const formDeviceTypes = watch('deviceTypes');
89✔
66

67
  useEffect(() => {
89✔
68
    updateCreation({ selectedDeviceTypes: formDeviceTypes });
13✔
69
  }, [formDeviceTypes, updateCreation]);
70

71
  useEffect(() => {
89✔
72
    updateCreation({
35✔
73
      destination,
74
      isValid: checkDestinationValidity(destination) && selectedDeviceTypes.length && name,
74✔
75
      finalStep: false
76
    });
77
  }, [destination, name, selectedDeviceTypes.length, updateCreation]);
78

79
  const onDestinationChange = ({ target: { value } }) =>
89✔
80
    updateCreation({ destination: value, isValid: checkDestinationValidity(value) && selectedDeviceTypes.length && name });
20!
81

82
  const isValidDestination = checkDestinationValidity(destination);
89✔
83
  return (
89✔
84
    <div className="flexbox column">
85
      <FileInformation file={file} type={type} onRemove={onRemove} />
86
      <TextField
87
        autoFocus={true}
88
        error={!isValidDestination}
89
        fullWidth
90
        helperText={!isValidDestination && <div className="warning">Destination has to be an absolute path</div>}
107✔
91
        inputProps={{ style: { marginTop: 16 } }}
92
        InputLabelProps={{ shrink: true }}
93
        label="Destination directory where the file will be installed on your devices"
94
        onChange={onDestinationChange}
95
        placeholder="Example: /opt/installed-by-single-file"
96
        value={destination}
97
      />
98
      <h4>Artifact information</h4>
99
      <FormControl>
UNCOV
100
        <InputLabel htmlFor="release-name" className="flexbox center-aligned" onClick={e => e.preventDefault()}>
×
101
          Release name
102
          <InfoHintContainer>
103
            <MenderHelpTooltip id={HELPTOOLTIPS.releaseName.id} />
104
            <DocsTooltip id={DOCSTIPS.releases.id} />
105
          </InfoHintContainer>
106
        </InputLabel>
107
        <Input
108
          defaultValue={name}
109
          className="release-name-input"
110
          id="release-name"
111
          placeholder="A descriptive name for the software"
112
          onChange={e => updateCreation({ name: e.target.value })}
12✔
113
        />
114
      </FormControl>
115
      <FormProvider {...methods}>
116
        <form noValidate>
117
          <ChipSelect
118
            name="deviceTypes"
119
            label="Device types compatible"
120
            placeholder="Enter all device types this software is compatible with"
121
            options={deviceTypes}
122
          />
123
        </form>
124
      </FormProvider>
125
    </div>
126
  );
127
};
128

129
const steps = [ArtifactInformation, VersionInformation];
6✔
130

131
export const ArtifactInformationForm = ({ activeStep, ...remainder }) => {
6✔
132
  const Component = steps[activeStep];
81✔
133
  return <Component {...remainder} />;
81✔
134
};
135

136
export default ArtifactInformationForm;
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