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

mendersoftware / mender-server / 1568834739

02 Dec 2024 10:01AM UTC coverage: 73.562% (+0.8%) from 72.786%
1568834739

Pull #211

gitlab-ci

mineralsfree
test: added upgrade unit tests

Ticket: MEN-7469
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #211: MEN-7469-feat: updated upgrades and add-on page

4251 of 6156 branches covered (69.05%)

Branch coverage included in aggregate %.

166 of 200 new or added lines in 18 files covered. (83.0%)

47 existing lines in 4 files now uncovered.

40029 of 54038 relevant lines covered (74.08%)

17.83 hits per line

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

52.17
/frontend/src/js/components/settings/PlanExpanded.tsx
1
// Copyright 2024 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 { useRef, useState } from 'react';
15
import { useSelector } from 'react-redux';
16

17
import { Divider, Drawer } from '@mui/material';
18

19
import { DrawerTitle } from '@northern.tech/common-ui/DrawerTitle';
20
import Form from '@northern.tech/common-ui/forms/form';
21
import storeActions from '@northern.tech/store/actions';
22
import { Plan } from '@northern.tech/store/constants';
23
import { Organization } from '@northern.tech/store/organizationSlice/types';
24
import { getCurrentUser } from '@northern.tech/store/selectors';
25
import { useAppDispatch } from '@northern.tech/store/store';
26
import { completeUpgrade } from '@northern.tech/store/thunks';
27

28
import { PlanExpandedForm } from './PlanExpandedForm';
29
import CardSection from './cardsection';
30

31
const { setSnackbar } = storeActions;
6✔
32

33
interface PlanExpandedProps {
34
  plan: Plan;
35
  organization: Organization;
36
  onCloseClick: () => void;
37
}
38

39
export const PlanExpanded = (props: PlanExpandedProps) => {
6✔
40
  const { plan: selectedPlan, onCloseClick, organization } = props;
2✔
41
  const [isValid, setIsValid] = useState(false);
1✔
42
  const dispatch = useAppDispatch();
1✔
43
  const formSubmitRef = useRef<() => void | null>(null);
1✔
44
  const { email } = useSelector(getCurrentUser);
1✔
45
  const handleUpgrade = () => {
1✔
NEW
46
    if (formSubmitRef.current) {
×
NEW
47
      formSubmitRef.current();
×
48
    }
49
  };
50

51
  const handleSubmit = async values => {
1✔
52
    const {
53
      email,
54
      name,
55
      country: { code },
56
      state,
57
      city,
58
      line1,
59
      postal_code
NEW
60
    } = values;
×
NEW
61
    const billing_profile = { email, name, address: { country: code, state, city, line1, postal_code } };
×
NEW
62
    await dispatch(completeUpgrade({ tenantId: organization.id, plan: selectedPlan.id, billing_profile }));
×
NEW
63
    onCloseClick();
×
64
  };
65
  return (
1✔
66
    <Drawer anchor="right" open={true} PaperProps={{ style: { minWidth: '75vw' } }}>
67
      <DrawerTitle title={<>Subscribe to {selectedPlan.name}</>} onClose={onCloseClick} />
68
      <Divider className="margin-bottom" />
69
      <div>
70
        Complete checkout to subscribe to <b>{selectedPlan.name}</b> at <b>{selectedPlan.price}</b>
71
      </div>
72
      <Form
73
        submitRef={formSubmitRef}
74
        onSubmit={handleSubmit}
75
        initialValues={{ email, name: organization.name || '', line1: '', state: '', city: '', postal_code: '', country: '' }}
1!
76
        showButtons={false}
77
        autocomplete="off"
78
      >
79
        <PlanExpandedForm setIsValid={setIsValid} />
80
      </Form>
81
      {isValid && (
1!
82
        <>
83
          <h4>Card Details</h4>
84
          <CardSection
85
            organization={organization}
86
            onComplete={handleUpgrade}
NEW
87
            setSnackbar={(message: string) => dispatch(setSnackbar(message))}
×
88
            isSignUp={true}
89
          />
90
        </>
91
      )}
92
    </Drawer>
93
  );
94
};
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