• 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

43.48
/src/js/components/devices/troubleshoot/terminal.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, { useCallback, useEffect, useState } from 'react';
15

16
import { FitAddon } from 'xterm-addon-fit';
17
import { WebLinksAddon } from 'xterm-addon-web-links';
18

19
import { TIMEOUTS } from '../../../constants/appConstants';
20
import { DEVICE_MESSAGE_TYPES as MessageTypes } from '../../../constants/deviceConstants';
21
import useWindowSize from '../../../utils/resizehook';
22
import XTerm from '../../common/xterm';
23

24
const fitAddon = new FitAddon();
13✔
25

26
export const options = {
13✔
27
  cursorBlink: 'block',
28
  macOptionIsMeta: true
29
};
30

31
// only matching absolute paths, so: /here/there - but not ../here or ./here or here/there
32
const unixPathRegex = new RegExp('(\\/([^\\0\\s!$`&*()\\[\\]+\'":;\\\\])+)');
13✔
33

34
export const Terminal = ({ onDownloadClick, sendMessage, sessionId, setSnackbar, socketInitialized, textInput, xtermRef, ...xtermProps }) => {
13✔
35
  const [dimensions, setDimensions] = useState({});
2✔
36
  const [isVisible, setIsVisible] = useState(false);
2✔
37
  const size = useWindowSize();
2✔
38

39
  const observer = new IntersectionObserver(([entry]) => setIsVisible(entry.isIntersecting));
2✔
40

41
  const tryFit = useCallback(() => {
2✔
42
    try {
×
43
      fitAddon.fit();
×
44
    } catch {
45
      setSnackbar('Fit not possible, terminal not yet visible', TIMEOUTS.fiveSeconds);
×
46
    }
47
  }, [fitAddon, setSnackbar]);
48

49
  useEffect(() => {
2✔
50
    if (!socketInitialized) {
2!
51
      return;
2✔
52
    }
53
    observer.observe(xtermRef.current.terminalRef.current);
×
54
    tryFit();
×
55
    // Remove the observer as soon as the component is unmounted
56
    return () => {
×
57
      observer.disconnect();
×
58
    };
59
  }, [socketInitialized, tryFit]);
60

61
  useEffect(() => {
2✔
62
    if (!socketInitialized || !xtermRef.current?.terminal || sessionId) {
2!
63
      return;
2✔
64
    }
65
    xtermRef.current.terminal.reset();
×
66
    const webLinksAddon = new WebLinksAddon((e, link) => onDownloadClick(link), { urlRegex: unixPathRegex }, true);
×
67
    xtermRef.current.terminal.loadAddon(webLinksAddon);
×
68
    tryFit();
×
69
    const { rows = 40, cols = 80 } = fitAddon.proposeDimensions() || {};
×
70
    sendMessage({ typ: MessageTypes.New, props: { terminal_height: rows, terminal_width: cols } });
×
71
    setDimensions({ rows, cols });
×
72
    xtermRef.current.terminal.focus();
×
73
  }, [sessionId, socketInitialized, tryFit, xtermRef.current]);
74

75
  useEffect(() => {
2✔
76
    if (!socketInitialized || !xtermRef.current.terminal || !isVisible) {
2!
77
      return;
2✔
78
    }
79
    fitAddon.fit();
×
80
    const newDimensions = fitAddon.proposeDimensions();
×
81
    if (newDimensions.rows != dimensions.rows || newDimensions.cols != dimensions.cols) {
×
82
      //
83
      sendMessage({
×
84
        typ: MessageTypes.Resize,
85
        props: { terminal_height: newDimensions.rows, terminal_width: newDimensions.cols }
86
      });
87
      setDimensions(newDimensions);
×
88
    }
89
  }, [size, isVisible]);
90

91
  useEffect(() => {
2✔
92
    if (!socketInitialized || !xtermRef.current.terminal || !textInput) {
2!
93
      return;
2✔
94
    }
95
    xtermRef.current.terminal.paste(textInput);
×
96
  }, [socketInitialized, xtermRef.current, textInput]);
97

98
  const onData = data => sendMessage({ typ: MessageTypes.Shell, body: data });
2✔
99

100
  return <XTerm xtermRef={xtermRef} addons={[fitAddon]} options={options} onData={onData} {...xtermProps} />;
2✔
101
};
102

103
export default Terminal;
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