console: purchase card review fixes
Co-Authored-By: Astra (gpt-6-astra) via Codex <noreply@openai.com>
7 files changed,
+226
−18
approved_domains_buy_copy_test.go+2 −1internal/console/apidomainbuy_test.go+2 −3internal/console/appdomainbuy.go+11 −1internal/console/domainbuy_card_test.go+64 −3internal/console/domainbuy_copy.go+2 −1internal/console/templates/domain_buy.html+20 −9internal/console/testdata/domainbuy_poll.cjs+125 −0
CI passed — run details
diff --git a/approved_domains_buy_copy_test.go b/approved_domains_buy_copy_test.go| index f1304caff..aa04e6571 100644 |
| --- a/approved_domains_buy_copy_test.go |
| +++ b/approved_domains_buy_copy_test.go |
| @@ -104,6 +104,7 @@ func TestApprovedDomainsBuyCopy(t *testing.T) { |
| {"operator.reason.registering", "internal/console/domainbuy.go", "registering"}, |
| {"operator.reason.unconfirmed", "internal/console/domainbuy.go", "unconfirmed"}, |
| {"operator.reason.unpaid", "internal/console/domainbuy.go", "unpaid"}, |
| + {"browser.ownership", "internal/console/domainbuy_copy.go", "The domain is registered in your name, so it is yours to keep or move."}, |
| {"browser.timing", "internal/console/domainbuy_copy.go", "Your domain usually works over HTTPS one to five minutes after payment."}, |
| {"cli.failedNoReason", "domains_buy_copy.go", "purchase failed. nothing was charged"}, |
| {"cli.expired", "domains_buy_copy.go", "checkout was not completed. nothing was charged"}, |
| @@ -115,7 +116,7 @@ func TestApprovedDomainsBuyCopy(t *testing.T) { |
| {"browser.stepRegister", "internal/console/domainbuy_copy.go", "Registering your domain"}, |
| {"browser.stepDNS", "internal/console/domainbuy_copy.go", "Pointing it at your app"}, |
| {"browser.stepHTTPS", "internal/console/domainbuy_copy.go", "Securing it with HTTPS"}, |
| - {"browser.ownership", "internal/console/domainbuy_copy.go", "It's registered in your name, so it's yours to keep or take elsewhere."}, |
| + {"browser.cardOwnership", "internal/console/domainbuy_copy.go", "It's registered in your name, so it's yours to keep or take elsewhere."}, |
| {"browser.liveTitle", "internal/console/domainbuy_copy.go", "{domain} is live"}, |
| {"browser.liveLede", "internal/console/domainbuy_copy.go", "Your new domain is up and running, pointed at {app} and secured with HTTPS. Go and take a look."}, |
| {"browser.visit", "internal/console/domainbuy_copy.go", "Visit {domain}"}, |
diff --git a/internal/console/apidomainbuy_test.go b/internal/console/apidomainbuy_test.go| index ec7381437..a7f000c6e 100644 |
| --- a/internal/console/apidomainbuy_test.go |
| +++ b/internal/console/apidomainbuy_test.go |
| @@ -3,7 +3,6 @@ package console |
| import ( |
| "context" |
| "encoding/json" |
| - "html" |
| "io" |
| "net/http" |
| "net/url" |
| @@ -182,10 +181,10 @@ func TestBrowserBuyRedirectsToCheckout(t *testing.T) { |
| t.Fatalf("quote status=%d, has price=%v, duplicate currency=%v, has phone=%v", status, strings.Contains(body, "$15"), strings.Contains(body, "$15 usd"), strings.Contains(body, "PhoneCountryCode")) |
| } |
| for _, want := range []string{ |
| - "It's registered in your name, so it's yours to keep or take elsewhere.", |
| + "The domain is registered in your name, so it is yours to keep or move.", |
| "Your domain usually works over HTTPS one to five minutes after payment.", |
| } { |
| - if !strings.Contains(body, "<p>"+html.EscapeString(want)+"</p>") { |
| + if !strings.Contains(body, "<p>"+want+"</p>") { |
| t.Errorf("missing visible copy %q", want) |
| } |
| } |
diff --git a/internal/console/appdomainbuy.go b/internal/console/appdomainbuy.go| index 48a42c409..0e4f9a593 100644 |
| --- a/internal/console/appdomainbuy.go |
| +++ b/internal/console/appdomainbuy.go |
| @@ -54,6 +54,7 @@ type domainPurchaseCard struct { |
| Stage domainPurchaseStage |
| Title, Lede string |
| Visit string |
| + Status string |
| StepLabels [4]string |
| } |
| @@ -64,11 +65,20 @@ func purchaseCard(p *DomainPurchase, domainState string) domainPurchaseCard { |
| } |
| stage := domainPurchaseStages[state] |
| fill := strings.NewReplacer("{domain}", p.Domain, "{app}", p.App) |
| - return domainPurchaseCard{ |
| + card := domainPurchaseCard{ |
| Stage: stage, Title: fill.Replace(domainBuyCopy[stage.Kind+"Title"]), |
| Lede: fill.Replace(domainBuyCopy[stage.Kind+"Lede"]), Visit: fill.Replace(domainBuyCopy["visit"]), |
| StepLabels: [4]string{domainBuyCopy["stepPaid"], domainBuyCopy["stepRegister"], domainBuyCopy["stepDNS"], domainBuyCopy["stepHTTPS"]}, |
| } |
| + card.Status = card.Title |
| + if stage.Kind == "progress" { |
| + for i, step := range stage.Steps { |
| + if step == "active" { |
| + card.Status = card.StepLabels[i] |
| + } |
| + } |
| + } |
| + return card |
| } |
| func domainPurchaseURL(account, app, id string) string { |
diff --git a/internal/console/domainbuy_card_test.go b/internal/console/domainbuy_card_test.go| index dcee3e815..5803efbb9 100644 |
| --- a/internal/console/domainbuy_card_test.go |
| +++ b/internal/console/domainbuy_card_test.go |
| @@ -1,9 +1,12 @@ |
| package console |
| import ( |
| + "bytes" |
| "context" |
| + "encoding/json" |
| "net/http" |
| "net/http/httptest" |
| + "os/exec" |
| "strings" |
| "testing" |
| "time" |
| @@ -164,14 +167,33 @@ func TestDomainPurchaseCardRender(t *testing.T) { |
| t.Error("incorrect visit action") |
| } |
| card := purchaseElement(t, body, "purchase-card") |
| - if strings.Count(purchaseText(card), domainBuyCopy["ownership"]) != 1 || strings.Count(purchaseText(card), domainBuyCopy["back"]) != 1 { |
| + if strings.Count(purchaseText(card), domainBuyCopy["cardOwnership"]) != 1 || strings.Count(purchaseText(card), domainBuyCopy["back"]) != 1 { |
| t.Error("card needs ownership and one back link") |
| } |
| if !strings.Contains(body, `<h1>Buy a domain</h1>`) { |
| t.Error("page heading changed") |
| } |
| - if purchaseAttr(purchaseElement(t, body, "purchase-progress"), "role") != "status" { |
| - t.Error("missing live region") |
| + progress := purchaseElement(t, body, "purchase-progress") |
| + if purchaseAttr(progress, "role") != "" || purchaseAttr(progress, "aria-atomic") != "" { |
| + t.Error("large container must not announce the whole card") |
| + } |
| + announcement := purchaseElement(t, body, "purchase-status") |
| + if purchaseAttr(announcement, "role") != "status" || purchaseAttr(announcement, "aria-live") != "polite" || purchaseAttr(announcement, "class") != "visually-hidden" || purchaseHidden(announcement) { |
| + t.Error("missing visually hidden polite status") |
| + } |
| + wantStatus := fill.Replace(domainBuyCopy[tc.kind+"Title"]) |
| + switch tc.state { |
| + case PurchaseAuthorised, PurchaseZoneReady, PurchaseRegistering: |
| + wantStatus = domainBuyCopy["stepRegister"] |
| + case PurchaseRegistered, PurchaseCaptured: |
| + wantStatus = domainBuyCopy["stepDNS"] |
| + case PurchaseDone: |
| + if tc.domainState != StateLive { |
| + wantStatus = domainBuyCopy["stepHTTPS"] |
| + } |
| + } |
| + if got := purchaseText(announcement); got != wantStatus { |
| + t.Errorf("status = %q, want %q", got, wantStatus) |
| } |
| if tc.kind == "progress" { |
| steps := purchaseElement(t, body, "purchase-steps") |
| @@ -248,3 +270,42 @@ func TestDomainPurchasePageRendersLiveBeforePolling(t *testing.T) { |
| t.Fatal("another account's claim supplied live status") |
| } |
| } |
| + |
| +func TestDomainPurchaseCardPolling(t *testing.T) { |
| + node, err := exec.LookPath("node") |
| + if err != nil { |
| + t.Skip("node is needed to execute the purchase polling script") |
| + } |
| + f := newPurchaseFixture(t) |
| + fixtures := map[string]any{"copy": domainBuyCopy} |
| + for _, state := range []PurchaseState{PurchaseRegistering, PurchaseAwaitingPayment, "live", PurchaseFailed, PurchaseExpired, PurchaseUnpaid} { |
| + p := &DomainPurchase{ID: "dp_card", Domain: "shop.com", App: "kass", State: state} |
| + domainState := "" |
| + if state == "live" { |
| + p.State, domainState = PurchaseDone, StateLive |
| + } |
| + body := purchaseCardHTML(t, f, p, domainState, "https://checkout.example.test/pay") |
| + start := strings.Index(body, "(function () {") |
| + end := strings.Index(body[start:], "</script>") |
| + elements := map[string]any{} |
| + for _, id := range []string{"purchase-card", "purchase-title", "purchase-lede", "purchase-steps", "purchase-mark", "purchase-error", "purchase-continue", "purchase-visit", "purchase-status"} { |
| + n := purchaseElement(t, body, id) |
| + elements[id] = map[string]any{"text": purchaseText(n), "hidden": purchaseHidden(n)} |
| + } |
| + fixtures[string(state)] = map[string]any{ |
| + "script": body[start : start+end], "elements": elements, |
| + "response": map[string]string{"state": string(p.State), "domain_state": domainState}, |
| + } |
| + } |
| + data, err := json.Marshal(fixtures) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) |
| + defer cancel() |
| + cmd := exec.CommandContext(ctx, node, "testdata/domainbuy_poll.cjs") |
| + cmd.Stdin = bytes.NewReader(data) |
| + if out, err := cmd.CombinedOutput(); err != nil { |
| + t.Fatalf("polling regression: %v\n%s", err, out) |
| + } |
| +} |
diff --git a/internal/console/domainbuy_copy.go b/internal/console/domainbuy_copy.go| index acbc018be..ea7dafbb0 100644 |
| --- a/internal/console/domainbuy_copy.go |
| +++ b/internal/console/domainbuy_copy.go |
| @@ -50,6 +50,7 @@ var domainBuyCopy = map[string]string{ |
| "State": "State or region (optional)", |
| "PostalCode": "Postal code", |
| "Country": "Country (two uppercase letters)", |
| + "ownership": "The domain is registered in your name, so it is yours to keep or move.", |
| "timing": "Your domain usually works over HTTPS one to five minutes after payment.", |
| // approved by Paul (copy review 2026-11-03) |
| "progressTitle": "Setting up {domain}", |
| @@ -58,7 +59,7 @@ var domainBuyCopy = map[string]string{ |
| "stepRegister": "Registering your domain", |
| "stepDNS": "Pointing it at your app", |
| "stepHTTPS": "Securing it with HTTPS", |
| - "ownership": "It's registered in your name, so it's yours to keep or take elsewhere.", |
| + "cardOwnership": "It's registered in your name, so it's yours to keep or take elsewhere.", |
| "liveTitle": "{domain} is live", |
| "liveLede": "Your new domain is up and running, pointed at {app} and secured with HTTPS. Go and take a look.", |
| "visit": "Visit {domain}", |
diff --git a/internal/console/templates/domain_buy.html b/internal/console/templates/domain_buy.html| index f89cefb93..f61b62098 100644 |
| --- a/internal/console/templates/domain_buy.html |
| +++ b/internal/console/templates/domain_buy.html |
| @@ -7,7 +7,7 @@ |
| .purchase-card [hidden] { display: none !important; } |
| .purchase-card h2 { margin: 0 0 0.5rem; font-size: 1.5rem; line-height: 1.2; } |
| .purchase-card .done-lede { margin: 0 0 1.2rem; font-size: 1.02rem; } |
| - .purchase-card .done-mark { width: 3rem; height: 3rem; margin-bottom: 0.8rem; } |
| + .purchase-card .done-mark { width: 3rem; height: 3rem; margin-bottom: 0.8rem; background: var(--rst-tone-positive-bg); color: var(--good); } |
| .purchase-card .done-actions { justify-content: flex-start; margin: 1.2rem 0 0; } |
| .purchase-card.done .done-actions { justify-content: center; } |
| .purchase-card .purchase-ownership, .purchase-card .purchase-error { margin: 0.9rem 0 0; color: var(--muted); font-size: 0.88rem; } |
| @@ -15,6 +15,7 @@ |
| .purchase-steps li { display: flex; align-items: center; gap: 0.6rem; } |
| .purchase-steps [data-state="pending"] { color: var(--muted); } |
| .purchase-step-mark { display: inline-grid; place-items: center; flex: none; width: 1.125rem; height: 1.125rem; color: var(--accent); } |
| + .purchase-steps [data-state="done"] .purchase-step-mark { color: var(--good); } |
| .purchase-step-mark .icon { width: 1.125rem; height: 1.125rem; stroke-width: 2.6; } |
| .purchase-steps li:not([data-state="done"]) .icon { display: none; } |
| .purchase-steps [data-state="active"] .purchase-step-mark::before { content: ""; width: 1rem; height: 1rem; border: 2px solid var(--rst-line); border-top-color: var(--accent); border-radius: 50%; } |
| @@ -25,7 +26,8 @@ |
| @keyframes purchase-spin { to { transform: rotate(360deg); } } |
| </style> |
| <section id="purchase-card" class="purchase-card{{if eq .Card.Stage.Kind "live"}} done{{end}}" aria-labelledby="purchase-title"> |
| - <div id="purchase-progress" role="status" aria-atomic="true"> |
| + <span id="purchase-status" class="visually-hidden" role="status" aria-live="polite">{{.Card.Status}}</span> |
| + <div id="purchase-progress"> |
| <span id="purchase-mark" class="done-mark" aria-hidden="true" {{if ne .Card.Stage.Kind "live"}}hidden{{end}}>{{icon "check"}}</span> |
| <h2 id="purchase-title">{{.Card.Title}}</h2> |
| <p id="purchase-lede" class="done-lede">{{.Card.Lede}}</p> |
| @@ -39,7 +41,7 @@ |
| <a id="purchase-visit" class="btn" href="https://{{.Purchase.Domain}}" target="_blank" rel="noopener" {{if ne .Card.Stage.Kind "live"}}hidden{{end}}>{{.Card.Visit}}</a> |
| <a class="btn btn-secondary" href="{{.Back}}">{{$.DomainBuyCopy.back}}</a> |
| </div> |
| - <p class="purchase-ownership">{{$.DomainBuyCopy.ownership}}</p> |
| + <p class="purchase-ownership">{{$.DomainBuyCopy.cardOwnership}}</p> |
| </section> |
| <script> |
| (function () { |
| @@ -50,8 +52,10 @@ |
| const steps = document.getElementById('purchase-steps'), rows = steps.querySelectorAll('li'); |
| const mark = document.getElementById('purchase-mark'), error = document.getElementById('purchase-error'); |
| const payment = document.getElementById('purchase-continue'), visit = document.getElementById('purchase-visit'); |
| + const status = document.getElementById('purchase-status'), labels = {{.Card.StepLabels}}; |
| const started = Date.now(); |
| - let state = {{.Purchase.State}}, domainState = {{.DomainState}}, rendered = ''; |
| + let state = {{.Purchase.State}}, domainState = {{.DomainState}}; |
| + let rendered = state + ':' + domainState + ':false'; |
| const fill = text => text.replace(/\{(domain|app)\}/g, (_, key) => key === 'domain' ? domain : app); |
| const terminal = () => ['failed', 'expired', 'unpaid'].includes(state) || (state === 'done' && domainState === 'live'); |
| function update() { |
| @@ -73,24 +77,31 @@ |
| if (payment) payment.hidden = stage.Kind !== 'awaiting'; |
| visit.hidden = stage.Kind !== 'live'; |
| visit.textContent = fill(copy.visit); |
| + const announcement = stage.Kind === 'progress' ? labels[stage.Steps.indexOf('active')] : title.textContent; |
| + if (status.textContent !== announcement) status.textContent = announcement; |
| } |
| async function poll() { |
| + if (Date.now() - started >= 3600000) { update(); return; } |
| try { |
| const response = await fetch(endpoint, {credentials: 'same-origin', cache: 'no-store'}); |
| if (!response.ok) throw new Error(); |
| const purchase = await response.json(); |
| if (!Object.prototype.hasOwnProperty.call(stages, purchase.state)) throw new Error(); |
| state = purchase.state; |
| - domainState = purchase.domain_state; |
| + domainState = purchase.domain_state || ''; |
| error.hidden = true; |
| update(); |
| if (terminal()) return; |
| } catch (_) { |
| - update(); |
| - if (error.hidden) error.textContent = copy.pollError; |
| - error.hidden = false; |
| + if (state !== 'awaiting_payment') { |
| + update(); |
| + if (error.hidden) error.textContent = copy.pollError; |
| + error.hidden = false; |
| + } |
| } |
| - setTimeout(poll, Date.now() - started < 600000 ? 3000 : 30000); |
| + const elapsed = Date.now() - started; |
| + if (elapsed >= 3600000) { update(); return; } |
| + setTimeout(poll, Math.min(elapsed < 600000 ? 3000 : 30000, 3600000 - elapsed)); |
| } |
| if (!terminal()) poll(); |
| })(); |
diff --git a/internal/console/testdata/domainbuy_poll.cjs b/internal/console/testdata/domainbuy_poll.cjs| new file mode 100644 |
| index 000000000..8f43e0c54 |
| --- /dev/null |
| +++ b/internal/console/testdata/domainbuy_poll.cjs |
| @@ -0,0 +1,125 @@ |
| +const assert = require('node:assert/strict'); |
| +const vm = require('node:vm'); |
| +const { test } = require('node:test'); |
| +const fixtures = JSON.parse(require('node:fs').readFileSync(0, 'utf8')); |
| + |
| +function harness(name) { |
| + const fixture = fixtures[name]; |
| + let now = 0, calls = 0, response = fixture.response; |
| + const timers = [], writes = []; |
| + const elements = Object.fromEntries(Object.entries(fixture.elements).map(([id, value]) => [id, { |
| + ...value, dataset: {}, classList: { toggle() {} }, |
| + setAttribute() {}, removeAttribute() {}, |
| + get textContent() { return this.text; }, |
| + set textContent(text) { writes.push([id, text]); this.text = text; } |
| + }])); |
| + elements['purchase-steps'].querySelectorAll = () => Array.from({ length: 4 }, () => ({ |
| + dataset: {}, setAttribute() {}, removeAttribute() {} |
| + })); |
| + vm.runInNewContext(fixture.script, { |
| + document: { getElementById: id => elements[id] || null }, |
| + Date: { now: () => now }, |
| + setTimeout: (fn, delay) => timers.push({ fn, delay }), |
| + fetch: async () => { |
| + calls++; |
| + if (response === 'error') throw new Error('offline'); |
| + return { ok: true, json: async () => response }; |
| + } |
| + }); |
| + return { |
| + elements, timers, writes, |
| + get calls() { return calls; }, |
| + async settle() { await new Promise(resolve => setImmediate(resolve)); }, |
| + async advance(time, next = response) { |
| + now = time; response = next; |
| + const timer = timers.shift(); |
| + assert.ok(timer, 'poll should be scheduled'); |
| + await timer.fn(); |
| + } |
| + }; |
| +} |
| + |
| +test('unchanged first poll does not rewrite server-rendered content', async () => { |
| + const h = harness('registering'); |
| + await h.settle(); |
| + assert.deepEqual(h.writes, []); |
| +}); |
| + |
| +test('omitted domain state and unchanged active step do not re-announce', async () => { |
| + const h = harness('registering'); |
| + await h.settle(); |
| + await h.advance(3000, { state: 'registering' }); |
| + assert.deepEqual(h.writes, []); |
| + await h.advance(6000, { state: 'zone_ready' }); |
| + await h.advance(600000, { state: 'registering' }); |
| + assert.deepEqual(h.writes.filter(([id]) => id === 'purchase-status'), []); |
| +}); |
| + |
| +test('announces the active step and then the terminal title', async () => { |
| + const h = harness('registering'); |
| + await h.settle(); |
| + for (const [state, domain_state, text] of [ |
| + ['registered', '', fixtures.copy.stepDNS], |
| + ['done', 'issuing-cert', fixtures.copy.stepHTTPS], |
| + ['done', 'live', 'shop.com is live'] |
| + ]) { |
| + await h.advance(3000, { state, domain_state }); |
| + assert.equal(h.elements['purchase-status'].textContent, text); |
| + } |
| + assert.equal(h.timers.length, 0); |
| +}); |
| + |
| +test('awaiting payment errors keep the last state silently', async () => { |
| + const h = harness('awaiting_payment'); |
| + await h.settle(); |
| + h.writes.length = 0; |
| + await h.advance(3000, 'error'); |
| + assert.equal(h.elements['purchase-error'].hidden, true); |
| + assert.deepEqual(h.writes, []); |
| + assert.equal(h.timers.length, 1); |
| +}); |
| + |
| +test('progress errors recover and continue polling', async () => { |
| + const h = harness('registering'); |
| + await h.settle(); |
| + await h.advance(3000, 'error'); |
| + assert.equal(h.elements['purchase-error'].hidden, false); |
| + assert.equal(h.elements['purchase-error'].textContent, fixtures.copy.pollError); |
| + await h.advance(6000, { state: 'registered', domain_state: '' }); |
| + assert.equal(h.elements['purchase-error'].hidden, true); |
| + assert.equal(h.elements['purchase-status'].textContent, fixtures.copy.stepDNS); |
| +}); |
| + |
| +for (const response of ['error', { state: 'registering', domain_state: '' }]) { |
| + test(`polling stops at one hour after ${JSON.stringify(response)}`, async () => { |
| + const h = harness('registering'); |
| + await h.settle(); |
| + await h.advance(600000, response); |
| + assert.equal(h.elements['purchase-lede'].textContent, fixtures.copy.slowLede); |
| + assert.equal(h.timers[0].delay, 30000); |
| + const calls = h.calls; |
| + await h.advance(3600000, response); |
| + assert.equal(h.calls, calls, 'no request at or after the deadline'); |
| + assert.equal(h.timers.length, 0); |
| + assert.equal(h.elements['purchase-lede'].textContent, fixtures.copy.slowLede); |
| + }); |
| +} |
| + |
| +for (const state of ['live', 'failed', 'expired', 'unpaid']) { |
| + test(`no polling when initially ${state}`, async () => { |
| + const h = harness(state); |
| + await h.settle(); |
| + assert.equal(h.calls, 0); |
| + assert.equal(h.timers.length, 0); |
| + }); |
| +} |
| + |
| +for (const state of ['failed', 'expired', 'unpaid']) { |
| + test(`announces ${state} and stops polling`, async () => { |
| + const h = harness('registering'); |
| + await h.settle(); |
| + await h.advance(3000, { state }); |
| + assert.equal(h.elements['purchase-status'].textContent, fixtures[state].elements['purchase-title'].text); |
| + assert.equal(h.timers.length, 0); |
| + }); |
| +} |