Name the org type by its display name in the default change's toast
The default change's success toast named the type by its key, as in "Default change committed for personal: 4 migrated.", while the org types page heads the same card "Personal" and the reorder's toast names the types it reaches by their display names (#187). CommitOrgTypeDefaultChange passes the display name from the type it already reads to render the card, and falls back to the key only if the name is empty. A handler test asserts the display name and the absence of the key. The 18 plan-act goldens that carry the toast change only in that line. The full suite passes.
This commit is contained in:
@@ -166,6 +166,7 @@ func otcScalar(t *testing.T, database *sql.DB, query string, args ...any) int {
|
||||
// operator person, and two single-tier ladders A and B.
|
||||
type otcFixture struct {
|
||||
orgType string
|
||||
displayName string
|
||||
operatorID string
|
||||
ladderA, prodA string
|
||||
ladderB, prodB string
|
||||
@@ -182,10 +183,10 @@ func newOtcFixture(t *testing.T, database *sql.DB) otcFixture {
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
f := otcFixture{orgType: "otc-" + sfx}
|
||||
f := otcFixture{orgType: "otc-" + sfx, displayName: "OTC " + sfx}
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`INSERT INTO core.org_types (org_type, display_name, is_active) VALUES ($1, $2, true)`,
|
||||
f.orgType, "OTC "+sfx,
|
||||
f.orgType, f.displayName,
|
||||
); err != nil {
|
||||
t.Fatalf("org type: %v", err)
|
||||
}
|
||||
|
||||
@@ -209,6 +209,23 @@ func TestOrgTypeDefaultChange_NoDrainForAnActTheRequestFinished(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The success toast names the organization type by its display name, as the
|
||||
// card's heading does, not by its key.
|
||||
func TestOrgTypeDefaultChange_ToastNamesTheDisplayName(t *testing.T) {
|
||||
database := dbtest.Open(t)
|
||||
f := newOtcFixture(t, database)
|
||||
h := newOtcHarnessWith(t, database, f.operatorID, otcOptions{})
|
||||
otcHolders(t, database, f, 2, false)
|
||||
|
||||
toast := commitB(h, f, "migrate").Header().Get("HX-Trigger")
|
||||
if want := "Default change committed for " + f.displayName + ": 2 migrated."; !strings.Contains(toast, want) {
|
||||
t.Errorf("the toast %q, want %q", toast, want)
|
||||
}
|
||||
if strings.Contains(toast, f.orgType) {
|
||||
t.Errorf("the toast %q names the key %q", toast, f.orgType)
|
||||
}
|
||||
}
|
||||
|
||||
// A read of the toast's counts that fails leaves the parts it could not read out
|
||||
// of the success toast, logs the failure with the act id, and starts the drain
|
||||
// only if work is left.
|
||||
@@ -248,7 +265,7 @@ func TestOrgTypeDefaultChange_UnreadPendingObligationsStopTheRequestAndStartTheD
|
||||
|
||||
rec := commitB(h, f, "migrate")
|
||||
toast := rec.Header().Get("HX-Trigger")
|
||||
if !strings.Contains(toast, "showSuccessToast") || !strings.Contains(toast, "Default change committed for "+f.orgType+".") {
|
||||
if !strings.Contains(toast, "showSuccessToast") || !strings.Contains(toast, "Default change committed for "+f.displayName+".") {
|
||||
t.Errorf("the toast %q, want the success toast without counts", toast)
|
||||
}
|
||||
if n := otcScalar(t, database, `SELECT count(*) FROM core.plan_act_obligations WHERE org_type = $1 AND status = 'settled'`, f.orgType); n != 0 {
|
||||
|
||||
@@ -271,9 +271,10 @@ func (r *OrgTypeChangeResult) summaryParts() []string {
|
||||
return parts
|
||||
}
|
||||
|
||||
// DefaultChangeToast is the success toast of a default change that committed.
|
||||
func (r *OrgTypeChangeResult) DefaultChangeToast(orgType string) string {
|
||||
return r.toast(fmt.Sprintf("Default change committed for %s", orgType))
|
||||
// DefaultChangeToast is the success toast of a default change that committed,
|
||||
// naming the organization type by its display name.
|
||||
func (r *OrgTypeChangeResult) DefaultChangeToast(displayName string) string {
|
||||
return r.toast(fmt.Sprintf("Default change committed for %s", displayName))
|
||||
}
|
||||
|
||||
// toast is head followed by the result's summary. A result whose counts could
|
||||
@@ -613,7 +614,11 @@ func (h *OperatorPartialsHandler) CommitOrgTypeDefaultChange(w http.ResponseWrit
|
||||
ot = fresh
|
||||
}
|
||||
result := planActToastResult(changed.PlanActShare)
|
||||
fireSuccessToast(w, result.DefaultChangeToast(orgType))
|
||||
name := ot.DisplayName
|
||||
if name == "" {
|
||||
name = ot.OrgType
|
||||
}
|
||||
fireSuccessToast(w, result.DefaultChangeToast(name))
|
||||
h.renderOrgTypeCard(w, r, ot, "", nil, "")
|
||||
if !changed.Pass.Done {
|
||||
h.startPlanActDrain(r.Context(), changed.ActID)
|
||||
|
||||
@@ -312,7 +312,7 @@ func TestDefaultChangeTwiceRefusesTheSecond(t *testing.T) {
|
||||
refused++
|
||||
}
|
||||
}
|
||||
if want := []string{"Default change committed for <orgtype:T>: 1 grandfathered."}; !slices.Equal(toasts, want) {
|
||||
if want := []string{"Default change committed for T: 1 grandfathered."}; !slices.Equal(toasts, want) {
|
||||
t.Errorf("toasts = %q, want %q", toasts, want)
|
||||
}
|
||||
if refused != 1 {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 already at the default."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 already at the default."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": [],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 initiated, 1 grandfathered, 1 untouched, 1 without a default pool."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 initiated, 1 grandfathered, 1 untouched, 1 without a default pool."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 not yet reached.",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 not yet reached.",
|
||||
"[id^=\"plan-act-\"]: 1 organization not yet reached."
|
||||
],
|
||||
"checked": [],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 not yet reached.",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 not yet reached.",
|
||||
"[id^=\"plan-act-\"]: 1 organization not yet reached."
|
||||
],
|
||||
"checked": [],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 not yet reached.",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 not yet reached.",
|
||||
"[id^=\"plan-act-\"]: 1 organization not yet reached."
|
||||
],
|
||||
"checked": [],
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 migrated."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 migrated."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": [],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 migrated, 1 left plan-less."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 migrated, 1 left plan-less."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": [],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 migrated, 2 not yet reached.",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 migrated, 2 not yet reached.",
|
||||
"[id^=\"plan-act-\"]: 2 organizations not yet reached."
|
||||
],
|
||||
"checked": [],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 2 migrated."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 2 migrated."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 untouched."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 untouched."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": [
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
"first": {
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 already at the default."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 already at the default."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": []
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
"first": {
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 grandfathered."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 grandfathered."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": []
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
"second": {
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 grandfathered."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 grandfathered."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": []
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
"second": {
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 grandfathered."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 grandfathered."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": []
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"first": {
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 grandfathered."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 grandfathered."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": []
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"first": {
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 grandfathered."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 grandfathered."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": []
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"first": {
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 grandfathered."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 grandfathered."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": []
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"first": {
|
||||
"answer": [
|
||||
"status 200",
|
||||
"Hx-Trigger showSuccessToast: Default change committed for <orgtype:T>: 1 grandfathered."
|
||||
"Hx-Trigger showSuccessToast: Default change committed for T: 1 grandfathered."
|
||||
],
|
||||
"checked": [],
|
||||
"logs": []
|
||||
|
||||
Reference in New Issue
Block a user