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

mendersoftware / gui / 1350829378

27 Jun 2024 01:46PM UTC coverage: 83.494% (-16.5%) from 99.965%
1350829378

Pull #4465

gitlab-ci

mzedel
chore: test fixes

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4465: MEN-7169 - feat: added multi sorting capabilities to devices view

4506 of 6430 branches covered (70.08%)

81 of 100 new or added lines in 14 files covered. (81.0%)

1661 existing lines in 163 files now uncovered.

8574 of 10269 relevant lines covered (83.49%)

160.6 hits per line

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

33.33
/src/js/components/settings/cardsection.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, { useState } from 'react';
15

16
import { Button } from '@mui/material';
17

18
import { CardElement, useElements, useStripe } from '@stripe/react-stripe-js';
19

20
import stripeImage from '../../../assets/img/powered_by_stripe.png';
21
import InfoText from '../common/infotext';
22
import Loader from '../common/loader';
23

24
const CardSection = ({ isSignUp, onCancel, onComplete, onSubmit, setSnackbar }) => {
9✔
25
  const stripe = useStripe();
1✔
26
  const elements = useElements();
1✔
27
  const [errors, setErrors] = useState(false);
1✔
28
  const [loading, setLoading] = useState(false);
1✔
29
  const [empty, setEmpty] = useState(true);
1✔
30

31
  const handleSubmit = async event => {
1✔
UNCOV
32
    event.preventDefault();
×
UNCOV
33
    setLoading(true);
×
UNCOV
34
    return onSubmit()
×
35
      .then(confirmCard)
UNCOV
36
      .finally(() => setLoading(false));
×
37
  };
38

39
  const confirmCard = async secret => {
1✔
40
    // Use elements.getElement to get a reference to the mounted Element.
UNCOV
41
    const cardElement = elements.getElement(CardElement);
×
42

43
    // Use your card Element with other Stripe.js APIs
UNCOV
44
    try {
×
UNCOV
45
      const result = await stripe.confirmCardSetup(secret, {
×
46
        payment_method: {
47
          card: cardElement
48
        }
49
      });
50

UNCOV
51
      if (result.error) {
×
UNCOV
52
        setSnackbar(`Error while confirming card: ${result.error.message}`);
×
UNCOV
53
        onCancel();
×
54
      } else {
UNCOV
55
        setSnackbar(`Card confirmed. Updating your account...`);
×
UNCOV
56
        onComplete();
×
57
      }
58
    } catch (err) {
UNCOV
59
      setSnackbar(`Something went wrong while submitting the form. Please contact support.`);
×
UNCOV
60
      onCancel();
×
61
    }
62
  };
63

64
  const stripeElementChange = event => {
1✔
UNCOV
65
    setEmpty(false);
×
UNCOV
66
    if (event.complete) {
×
67
      // enable payment button
UNCOV
68
      setErrors(false);
×
UNCOV
69
    } else if (event.error) {
×
70
      // show validation to customer
UNCOV
71
      setErrors(true);
×
72
    }
73
  };
74

75
  return (
1✔
76
    <form className="margin-top-small" onSubmit={handleSubmit} onReset={onCancel}>
UNCOV
77
      <CardElement className="warning" onChange={event => stripeElementChange(event)} />
×
78
      {!!errors && <p className="warning">There is an error in the form. Please check that your details are correct</p>}
1!
79

80
      <div id="poweredByStripe">
81
        <div>All standard credit card fees apply (e.g. foreign transaction fee, if your card has one)</div>
82
        <img src={stripeImage} />
83
      </div>
84

85
      {isSignUp && <InfoText>Billing will be scheduled monthly, starting from today. You can cancel at any time.</InfoText>}
2✔
86

87
      <div className="flexbox center-aligned margin-top-small" style={{ justifyContent: 'flex-end' }}>
88
        {!isSignUp && (
1!
89
          <Button type="reset" disabled={loading} style={{ marginRight: 15 }}>
90
            Cancel
91
          </Button>
92
        )}
93
        <Button variant="contained" color="secondary" type="submit" disabled={errors || loading || empty}>
3✔
94
          {isSignUp ? 'Sign up' : 'Save'}
1!
95
        </Button>
96
      </div>
97
      <Loader show={loading} />
98
    </form>
99
  );
100
};
101

102
export default CardSection;
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