• 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

83.56
/src/js/components/settings/settings.js
1
// Copyright 2017 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 { useSelector } from 'react-redux';
16
import { Navigate, useParams } from 'react-router-dom';
17

18
// material ui
19
import { Payment as PaymentIcon } from '@mui/icons-material';
20

21
import { Elements } from '@stripe/react-stripe-js';
22

23
import { TIMEOUTS, canAccess } from '../../constants/appConstants';
24
import { versionCompare } from '../../helpers';
25
import {
26
  getCurrentUser,
27
  getFeatures,
28
  getIsEnterprise,
29
  getOrganization,
30
  getTenantCapabilities,
31
  getUserCapabilities,
32
  getUserRoles,
33
  getVersionInformation
34
} from '../../selectors';
35
import LeftNav from '../common/left-nav';
36
import SelfUserManagement from '../settings/user-management/selfusermanagement';
37
import UserManagement from '../settings/user-management/usermanagement';
38
import Global from './global';
39
import Integrations from './integrations';
40
import Organization from './organization/organization';
41
import Roles from './roles';
42
import Upgrade from './upgrade';
43

44
let stripePromise = null;
4✔
45

46
const sectionMap = {
4✔
47
  'global-settings': { component: Global, text: () => 'Global settings', canAccess },
1✔
48
  'my-profile': { component: SelfUserManagement, text: () => 'My profile', canAccess },
1✔
49
  'organization-and-billing': {
50
    component: Organization,
51
    text: () => 'Organization and billing',
1✔
52
    canAccess: ({ hasMultitenancy }) => hasMultitenancy
1✔
53
  },
54
  'user-management': {
55
    component: UserManagement,
56
    text: () => 'User management',
1✔
57
    canAccess: ({ userCapabilities: { canManageUsers } }) => canManageUsers
1✔
58
  },
59
  'role-management': {
60
    component: Roles,
61
    text: () => 'Roles',
×
62
    canAccess: ({ currentUser, isEnterprise, userRoles: { isAdmin } }) => currentUser && isAdmin && isEnterprise
1✔
63
  },
64
  integrations: {
65
    component: Integrations,
66
    text: () => 'Integrations',
1✔
67
    canAccess: ({ userRoles: { isAdmin }, version }) => isAdmin && versionCompare(version, '3.2') > -1
1✔
68
  },
69
  upgrade: {
70
    component: Upgrade,
71
    icon: <PaymentIcon />,
72
    text: ({ isTrial }) => (isTrial ? 'Upgrade to a plan' : 'Upgrades and add-ons'),
1!
73
    canAccess: ({ hasMultitenancy }) => hasMultitenancy
1✔
74
  }
75
};
76

77
export const Settings = () => {
4✔
78
  const currentUser = useSelector(getCurrentUser);
1✔
79
  const isEnterprise = useSelector(getIsEnterprise);
1✔
80
  const { hasMultitenancy } = useSelector(getFeatures);
1✔
81
  const { trial: isTrial = false } = useSelector(getOrganization);
1✔
82
  const stripeAPIKey = useSelector(state => state.app.stripeAPIKey);
2✔
83
  const tenantCapabilities = useSelector(getTenantCapabilities);
1✔
84
  const userCapabilities = useSelector(getUserCapabilities);
1✔
85
  const userRoles = useSelector(getUserRoles);
1✔
86
  const { Integration: version } = useSelector(getVersionInformation);
1✔
87

88
  const [loadingFinished, setLoadingFinished] = useState(!stripeAPIKey);
1✔
89
  const { section: sectionParam } = useParams();
1✔
90

91
  useEffect(() => {
1✔
92
    // Make sure to call `loadStripe` outside of a component’s render to avoid recreating
93
    // the `Stripe` object on every render - but don't initialize twice.
94
    if (!stripePromise) {
1!
95
      import(/* webpackChunkName: "stripe" */ '@stripe/stripe-js').then(({ loadStripe }) => {
1✔
96
        if (stripeAPIKey) {
1!
97
          stripePromise = loadStripe(stripeAPIKey).finally(() => setLoadingFinished(true));
×
98
        }
99
      });
100
    } else {
101
      const notStripePromise = new Promise(resolve => setTimeout(resolve, TIMEOUTS.debounceDefault));
×
102
      Promise.race([stripePromise, notStripePromise]).then(result => setLoadingFinished(result !== notStripePromise));
×
103
    }
104
  }, [stripeAPIKey]);
105

106
  const checkDenyAccess = item =>
1✔
107
    currentUser.id && !item.canAccess({ currentUser, hasMultitenancy, isEnterprise, isTrial, tenantCapabilities, userCapabilities, userRoles, version });
8✔
108

109
  const getCurrentSection = (sections, section = sectionParam) => {
1!
110
    if (!sections.hasOwnProperty(section) || checkDenyAccess(sections[section])) {
1!
111
      return;
×
112
    }
113
    return sections[section];
1✔
114
  };
115

116
  const links = Object.entries(sectionMap).reduce((accu, [key, item]) => {
1✔
117
    if (!checkDenyAccess(item)) {
7✔
118
      accu.push({
6✔
119
        path: `/settings/${key}`,
120
        icon: item.icon,
121
        title: item.text({ isTrial })
122
      });
123
    }
124
    return accu;
7✔
125
  }, []);
126

127
  const section = getCurrentSection(sectionMap, sectionParam);
1✔
128
  if (!section) {
1!
129
    return <Navigate to="/settings/my-profile" replace />;
×
130
  }
131
  const Component = section.component;
1✔
132
  return (
1✔
133
    <div className="tab-container with-sub-panels" style={{ minHeight: '95%' }}>
134
      <LeftNav sections={[{ itemClass: 'settingsNav', items: links, title: 'Settings' }]} />
135
      <div className="rightFluid padding-right">
136
        {loadingFinished && (
2✔
137
          <Elements stripe={stripePromise}>
138
            <Component />
139
          </Elements>
140
        )}
141
      </div>
142
    </div>
143
  );
144
};
145

146
export default Settings;
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