• 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

64.79
/src/js/components/search-result.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, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16
import { useNavigate } from 'react-router-dom';
17

18
import { Close as CloseIcon } from '@mui/icons-material';
19
// material ui
20
import { ClickAwayListener, Drawer, IconButton, Typography } from '@mui/material';
21
import { makeStyles } from 'tss-react/mui';
22

23
import pluralize from 'pluralize';
24

25
import { setSearchState } from '../actions/appActions';
26
import { setDeviceListState } from '../actions/deviceActions';
27
import { SORTING_OPTIONS, TIMEOUTS } from '../constants/appConstants';
28
import { getIdAttribute, getMappedDevicesList, getOnboardingState, getUserSettings } from '../selectors';
29
import { getHeaders } from './devices/authorized-devices';
30
import { routes } from './devices/base-devices';
31
import Devicelist from './devices/devicelist';
32

33
const useStyles = makeStyles()(theme => ({
53✔
34
  drawerOffset: {
35
    top: theme.mixins.toolbar.minHeight + 1,
36
    left: 200
37
  },
38
  paper: {
39
    maxWidth: '100vw',
40
    minHeight: '20vh',
41
    boxShadow: 'none'
42
  }
43
}));
44

45
const leftNavOffset = 500;
3✔
46
const ResultTitle = ({ onClick, term, total }) => {
3✔
47
  const content = `${total ? total : 'No'} ${pluralize('device', total)} found for "${term}"`;
1!
48
  let props = { className: 'bold' };
1✔
49
  let style = {};
1✔
50
  if (!total) {
1!
51
    props = { className: 'info' };
1✔
52
    style = { width: `calc(100% - ${leftNavOffset}px)` };
1✔
53
  }
54
  return (
1✔
55
    <div className={`flexbox ${total ? 'center-aligned' : 'centered'}`} style={style}>
1!
56
      <Typography variant="body2" {...props}>
57
        {content}
58
      </Typography>
59
      <a className="margin-left-large" onClick={onClick}>
60
        clear search
61
      </a>
62
    </div>
63
  );
64
};
65

66
export const SearchResult = ({ onToggleSearchResult, open = true }) => {
3!
67
  const navigate = useNavigate();
1,169✔
68
  const dispatch = useDispatch();
1,169✔
69

70
  const { columnSelection } = useSelector(getUserSettings);
1,169✔
71
  const customColumnSizes = useSelector(state => state.users.customColumns);
2,244✔
72
  const devices = useSelector(state => getMappedDevicesList(state, 'search'));
2,244✔
73
  const idAttribute = useSelector(getIdAttribute);
1,169✔
74
  const onboardingState = useSelector(getOnboardingState);
1,169✔
75
  const searchState = useSelector(state => state.app.searchState);
2,244✔
76

77
  const { classes } = useStyles();
1,169✔
78

79
  const [columnHeaders, setColumnHeaders] = useState(getHeaders(columnSelection, routes.devices.defaultHeaders, idAttribute));
1,169✔
80

81
  const { isSearching, searchTerm, searchTotal, sort = {} } = searchState;
1,169!
82
  const { direction: sortDown = SORTING_OPTIONS.desc, key: sortCol } = sort;
1,169✔
83

84
  useEffect(() => {
1,169✔
85
    const columnHeaders = getHeaders(columnSelection, routes.devices.defaultHeaders, idAttribute);
11✔
86
    setColumnHeaders(columnHeaders);
11✔
87
  }, [columnSelection, idAttribute.attribute]);
88

89
  useEffect(() => {
1,169✔
90
    if (!open && isSearching) {
5!
91
      onToggleSearchResult();
×
92
    }
93
  }, [open, isSearching]);
94

95
  useEffect(() => {
1,169✔
96
    if (open && !searchTerm) {
5!
97
      onToggleSearchResult();
×
98
    }
99
  }, [open, searchTerm]);
100

101
  const onDeviceSelect = device => {
1,169✔
102
    dispatch(setDeviceListState({ selectedId: device.id }));
×
103
    onToggleSearchResult();
×
104
    setTimeout(() => navigate(`/devices/${device.status}?id=${device.id}`), TIMEOUTS.debounceShort);
×
105
  };
106

107
  const handlePageChange = page => {
1,169✔
108
    dispatch(setSearchState({ page }));
×
109
  };
110

111
  const onSortChange = attribute => {
1,169✔
112
    let changedSortCol = attribute.name;
×
113
    let changedSortDown = sortDown === SORTING_OPTIONS.desc ? SORTING_OPTIONS.asc : SORTING_OPTIONS.desc;
×
114
    if (changedSortCol !== sortCol) {
×
115
      changedSortDown = SORTING_OPTIONS.desc;
×
116
    }
117
    dispatch(setSearchState({ page: 1, sort: { direction: changedSortDown, key: changedSortCol, scope: attribute.scope } }));
×
118
  };
119

120
  const onClearClick = () => {
1,169✔
121
    dispatch(setSearchState({ searchTerm: '' }));
×
122
    onToggleSearchResult();
×
123
  };
124

125
  return (
1,169✔
126
    <ClickAwayListener onClickAway={onToggleSearchResult}>
127
      <Drawer
128
        anchor="top"
129
        classes={classes}
130
        disableEnforceFocus
131
        open={open}
132
        ModalProps={{ className: classes.drawerOffset, BackdropProps: { className: classes.drawerOffset } }}
133
        PaperProps={{ className: `${classes.drawerOffset} ${classes.paper}` }}
134
        SlideProps={{ direction: 'left' }}
135
      >
136
        <div className="flexbox center-aligned margin-bottom-small space-between">
137
          <ResultTitle onClick={onClearClick} term={searchTerm} total={searchTotal} />
138
          <IconButton onClick={onToggleSearchResult} aria-label="close" size="large">
139
            <CloseIcon />
140
          </IconButton>
141
        </div>
142
        {!!searchTotal && (
1,169!
143
          <Devicelist
144
            className=""
145
            columnHeaders={columnHeaders}
146
            customColumnSizes={customColumnSizes}
147
            deviceListState={{ perPage: 10, sort: {} }}
148
            devices={devices}
149
            idAttribute={idAttribute}
150
            onboardingState={onboardingState}
151
            onSort={onSortChange}
152
            PaginationProps={{ rowsPerPageOptions: [10] }}
153
            pageTotal={searchTotal}
154
            onPageChange={handlePageChange}
155
            pageLoading={isSearching}
156
            onExpandClick={onDeviceSelect}
157
          />
158
        )}
159
      </Drawer>
160
    </ClickAwayListener>
161
  );
162
};
163

164
export default SearchResult;
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