• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.29
/src/js/components/auditlogs/eventdetails/portforward.js
1
// Copyright 2021 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 { connect } from 'react-redux';
16

17
import { useTheme } from '@mui/material/styles';
18

19
import moment from 'moment';
20
import momentDurationFormatSetup from 'moment-duration-format';
21

22
import { getDeviceById, getSessionDetails } from '../../../actions/deviceActions';
23
import { getIdAttribute, getUserCapabilities } from '../../../selectors';
24
import Loader from '../../common/loader';
25
import Time from '../../common/time';
26
import DeviceDetails, { DetailInformation } from './devicedetails';
27

28
momentDurationFormatSetup(moment);
7✔
29

30
export const PortForward = ({ canReadDevices, device, idAttribute, item, getDeviceById, getSessionDetails, onClose }) => {
7✔
31
  const theme = useTheme();
2✔
32
  const [sessionDetails, setSessionDetails] = useState();
2✔
33

34
  useEffect(() => {
2✔
35
    const { action, actor, meta, object, time } = item;
1✔
36
    if (canReadDevices && !device) {
1!
37
      getDeviceById(object.id);
×
38
    }
39
    getSessionDetails(
1✔
40
      meta.session_id[0],
41
      object.id,
42
      actor.id,
43
      action.startsWith('open') ? time : undefined,
1!
44
      action.startsWith('close') ? time : undefined
1!
45
    ).then(setSessionDetails);
46
  }, []);
47

48
  if (!sessionDetails || (canReadDevices && !device)) {
2✔
49
    return <Loader show={true} />;
1✔
50
  }
51

52
  const sessionMeta = {
1✔
53
    'Session ID': item.meta.session_id[0],
54
    'Start time': <Time value={sessionDetails.start} />,
55
    'End time': <Time value={sessionDetails.end} />,
56
    'Duration': moment.duration(moment(sessionDetails.end).diff(sessionDetails.start)).format('*hh:*mm:ss:SSS'),
57
    User: item.actor.email
58
  };
59

60
  return (
1✔
61
    <div className="flexbox column" style={{ margin: theme.spacing(3), minWidth: 'min-content' }}>
62
      {canReadDevices && <DeviceDetails device={device} idAttribute={idAttribute} onClose={onClose} />}
2✔
63
      <DetailInformation title="port forwarding" details={sessionMeta} />
64
    </div>
65
  );
66
};
67

68
const actionCreators = { getDeviceById, getSessionDetails };
7✔
69

70
const mapStateToProps = (state, ownProps) => {
7✔
71
  const { item = {} } = ownProps;
×
72
  const deviceId = item.object.id;
×
73
  const { canReadDevices } = getUserCapabilities(state);
×
74
  return {
×
75
    canReadDevices,
76
    device: state.devices.byId[deviceId],
77
    idAttribute: getIdAttribute(state).attribute
78
  };
79
};
80

81
export default connect(mapStateToProps, actionCreators)(PortForward);
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