carlos / platform Public

console: an open purchase card switching to no app drops app-only steps

The poll reply's pointed=false (Unpointing) now moves the card to no app
as app '' does, and steps the stage has no state for (DNS, HTTPS) are
hidden, matching a freshly drawn no-app card. Polling harness covers it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f3f38925e1cd1a5ec074955bd91b01d21d5608b1 parent f94842b
3 files changed, +39 −5
  • internal/console/domainbuy_card_test.go +14 −1
  • internal/console/templates/domain_buy.html +4 −1
  • internal/console/testdata/domainbuy_poll.cjs +21 −3
diff --git a/internal/console/domainbuy_card_test.go b/internal/console/domainbuy_card_test.go
index de6bdae4a..a39bf74ff 100644
--- a/internal/console/domainbuy_card_test.go
+++ b/internal/console/domainbuy_card_test.go
@@ -278,12 +278,17 @@ func TestDomainPurchaseCardPolling(t *testing.T) {
}
f := newPurchaseFixture(t)
fixtures := map[string]any{"copy": domainBuyCopy}
- for _, state := range []PurchaseState{PurchaseRegistering, PurchaseAwaitingPayment, "live", PurchaseFailed, PurchaseExpired, PurchaseUnpaid} {
+ // The last fixture is a freshly rendered no-app card, for the open
+ // card that switches to no app to match.
+ for _, state := range []PurchaseState{PurchaseRegistering, PurchaseAwaitingPayment, "live", PurchaseFailed, PurchaseExpired, PurchaseUnpaid, "noapp_captured"} {
p := &DomainPurchase{ID: "dp_card", Domain: "shop.com", App: "kass", State: state}
domainState := ""
if state == "live" {
p.State, domainState = PurchaseDone, StateLive
}
+ if state == "noapp_captured" {
+ p.State, p.App = PurchaseCaptured, ""
+ }
body := purchaseCardHTML(t, f, p, domainState, "https://checkout.example.test/pay")
start := strings.Index(body, "(function () {")
end := strings.Index(body[start:], "</script>")
@@ -294,6 +299,7 @@ func TestDomainPurchaseCardPolling(t *testing.T) {
}
fixtures[string(state)] = map[string]any{
"script": body[start : start+end], "elements": elements,
+ "rows": purchaseStepRows(body),
"response": map[string]string{"state": string(p.State), "domain_state": domainState},
}
}
@@ -309,3 +315,10 @@ func TestDomainPurchaseCardPolling(t *testing.T) {
t.Fatalf("polling regression: %v\n%s", err, out)
}
}
+
+// purchaseStepRows is how many steps the card's list renders.
+func purchaseStepRows(body string) int {
+ _, list, _ := strings.Cut(body, `id="purchase-steps"`)
+ list, _, _ = strings.Cut(list, "</ol>")
+ return strings.Count(list, "<li ")
+}
diff --git a/internal/console/templates/domain_buy.html b/internal/console/templates/domain_buy.html
index 18eb250ec..1b8becda6 100644
--- a/internal/console/templates/domain_buy.html
+++ b/internal/console/templates/domain_buy.html
@@ -76,6 +76,9 @@
lede.textContent = fill(copy[slow ? 'slowLede' : stage.Kind + 'Lede']);
steps.hidden = !stepped;
rows.forEach((row, i) => {
+ // A step the stage has no state for is the app's (DNS, HTTPS): hidden
+ // once the card has no app, as a freshly drawn no-app card lacks it.
+ row.hidden = !stage.Steps[i];
row.dataset.state = stage.Steps[i];
if (stage.Steps[i] === 'active') row.setAttribute('aria-current', 'step');
else row.removeAttribute('aria-current');
@@ -97,7 +100,7 @@
if (!Object.prototype.hasOwnProperty.call(stagesApp, purchase.state)) throw new Error();
state = purchase.state;
domainState = purchase.domain_state || '';
- if (purchase.app === '') noApp = true;
+ if (purchase.app === '' || purchase.pointed === false) noApp = true;
error.hidden = true;
update();
if (terminal()) return;
diff --git a/internal/console/testdata/domainbuy_poll.cjs b/internal/console/testdata/domainbuy_poll.cjs
index 8f43e0c54..7b14ac7b6 100644
--- a/internal/console/testdata/domainbuy_poll.cjs
+++ b/internal/console/testdata/domainbuy_poll.cjs
@@ -13,9 +13,10 @@ function harness(name) {
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() {}
+ const rows = Array.from({ length: fixture.rows }, () => ({
+ dataset: {}, hidden: false, setAttribute() {}, removeAttribute() {}
}));
+ elements['purchase-steps'].querySelectorAll = () => rows;
vm.runInNewContext(fixture.script, {
document: { getElementById: id => elements[id] || null },
Date: { now: () => now },
@@ -27,7 +28,7 @@ function harness(name) {
}
});
return {
- elements, timers, writes,
+ elements, timers, writes, rows,
get calls() { return calls; },
async settle() { await new Promise(resolve => setImmediate(resolve)); },
async advance(time, next = response) {
@@ -123,3 +124,20 @@ for (const state of ['failed', 'expired', 'unpaid']) {
assert.equal(h.timers.length, 0);
});
}
+
+for (const response of [
+ { state: 'captured', app: '', pointed: false, domain_state: '' },
+ { state: 'captured', app: 'kass', pointed: false, domain_state: '' }
+]) {
+ test(`an open card switching to no app (${JSON.stringify(response)}) drops the app-only steps`, async () => {
+ const h = harness('registering');
+ await h.settle();
+ assert.equal(h.rows.length, 4);
+ await h.advance(3000, response);
+ const fresh = fixtures.noapp_captured;
+ assert.equal(h.rows.filter(row => !row.hidden).length, fresh.rows, 'visible steps match a fresh no-app card');
+ assert.deepEqual(h.rows.map(row => row.hidden), [false, false, true, true]);
+ assert.equal(h.elements['purchase-title'].textContent, fresh.elements['purchase-title'].text);
+ assert.equal(h.elements['purchase-lede'].textContent, fresh.elements['purchase-lede'].text);
+ });
+}