package action import ( "context" "testing" ) // TestRuleNotifyContext 验证规则级通知标记可传递且缺省为允许。 func TestRuleNotifyContext(t *testing.T) { if got := RuleNotify(nil); !got { t.Fatal("nil ctx should allow notify") } if got := RuleNotify(context.Background()); !got { t.Fatal("ctx without rule notify should allow notify") } ctx := WithRuleNotify(context.Background(), false) if got := RuleNotify(ctx); got { t.Fatal("rule notify=false should be propagated") } if got := RuleNotify(WithRuleNotify(ctx, true)); !got { t.Fatal("inner rule notify=true should override") } } // TestNotificationsAllowed 验证全局开关与规则级开关是"与"关系。 func TestNotificationsAllowed(t *testing.T) { defer SetToastEnabled(true) SetToastEnabled(true) if !NotificationsAllowed(WithRuleNotify(context.Background(), true)) { t.Fatal("global on + rule on should allow") } if NotificationsAllowed(WithRuleNotify(context.Background(), false)) { t.Fatal("rule off should suppress toast") } SetToastEnabled(false) if NotificationsAllowed(context.Background()) { t.Fatal("global off should suppress toast") } }