~cytrogen/gstack

ref: cd66fc2f890982351e3178925be563681d0ab2c5 gstack/browse/test/fixtures/qa-eval-checkout.html -rw-r--r-- 4.2 KiB
cd66fc2f — Garry Tan fix: 6 critical fixes + community PR guardrails (v0.13.2.0) (#602) 12 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>QA Eval — Checkout</title>
  <style>
    body { font-family: sans-serif; padding: 20px; }
    .checkout-form { max-width: 500px; }
    .form-group { margin-bottom: 15px; }
    .form-group label { display: block; margin-bottom: 4px; font-weight: bold; }
    .form-group input { width: 100%; padding: 8px; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; }
    .form-group input.invalid { border-color: red; }
    .form-group .error-msg { color: red; font-size: 12px; display: none; }
    .total { font-size: 24px; font-weight: bold; margin: 20px 0; }
    button[type="submit"] { padding: 12px 24px; background: #0066cc; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; }
    .order-summary { background: #f5f5f5; padding: 15px; border-radius: 4px; margin-bottom: 20px; }
  </style>
</head>
<body>
  <h1>Checkout</h1>

  <div class="order-summary">
    <h2>Order Summary</h2>
    <p>Widget Pro — $99.99 x <input type="number" id="quantity" value="1" min="1" style="width: 50px;"></p>
    <p class="total" id="total">Total: $99.99</p>  <!-- BUG 2: shows $NaN when quantity is cleared -->
  </div>

  <form class="checkout-form" id="checkout-form">
    <h2>Shipping Information</h2>

    <div class="form-group">
      <label for="email">Email</label>
      <input type="text" id="email" name="email" placeholder="you@example.com" required
             pattern="[^@]+@[^@]">  <!-- BUG 1: broken regex — accepts "user@" as valid -->
      <span class="error-msg" id="email-error">Please enter a valid email</span>
    </div>

    <div class="form-group">
      <label for="address">Address</label>
      <input type="text" id="address" name="address" placeholder="123 Main St" required>
    </div>

    <div class="form-group">
      <label for="city">City</label>
      <input type="text" id="city" name="city" placeholder="San Francisco" required>
    </div>

    <div class="form-group">
      <label for="zip">Zip Code</label>
      <input type="text" id="zip" name="zip" placeholder="94105">  <!-- BUG 4: missing required attribute -->
    </div>

    <h2>Payment</h2>

    <div class="form-group">
      <label for="cc">Credit Card Number</label>
      <input type="text" id="cc" name="cc" placeholder="4111 1111 1111 1111" required>
      <!-- BUG 3: no maxlength — overflows container at >20 chars -->
    </div>

    <div class="form-group">
      <label for="exp">Expiration</label>
      <input type="text" id="exp" name="exp" placeholder="MM/YY" required maxlength="5">
    </div>

    <div class="form-group">
      <label for="cvv">CVV</label>
      <input type="text" id="cvv" name="cvv" placeholder="123" required maxlength="4">
    </div>

    <button type="submit">Place Order — $<span id="submit-total">99.99</span></button>
  </form>

  <script>
    // Update total when quantity changes
    const quantityInput = document.getElementById('quantity');
    const totalEl = document.getElementById('total');
    const submitTotalEl = document.getElementById('submit-total');

    quantityInput.addEventListener('input', () => {
      // BUG 2: parseInt on empty string returns NaN, no fallback
      const qty = parseInt(quantityInput.value);
      const total = (qty * 99.99).toFixed(2);
      totalEl.textContent = 'Total: $' + total;
      submitTotalEl.textContent = total;
    });

    // Email validation (broken)
    const emailInput = document.getElementById('email');
    emailInput.addEventListener('blur', () => {
      // BUG 1: this regex accepts "user@" — missing domain part check
      const valid = /[^@]+@/.test(emailInput.value);
      emailInput.classList.toggle('invalid', !valid && emailInput.value.length > 0);
      document.getElementById('email-error').style.display = (!valid && emailInput.value.length > 0) ? 'block' : 'none';
    });

    // Form submit
    document.getElementById('checkout-form').addEventListener('submit', (e) => {
      e.preventDefault();
      // BUG 5: stripe is not defined — console error on submit
      stripe.createPaymentMethod({
        type: 'card',
        card: { number: document.getElementById('cc').value }
      });
    });
  </script>
</body>
</html>