Simpl-Resultat/src/shared/upsellCta.test.ts
le king fu 57a0fbc2f7
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 1m42s
feat(upsell): activate "Get Base", honest Premium note, purchase path in Free, Account card text
- upsellCtaFor(tier) decides what a locked screen offers: Base is
  purchasable, Premium stays disabled with "Premium isn't sold online
  yet". Pure and tested on the whole entitlements matrix.
- Shared CTAs, one component per file: PurchaseButton ("Get Base") and
  DownloadLatestButton open the localized product page (purchaseUrl) and
  need no router; HaveKeyButton renders only inside BrowserRouter.
- UpsellGate uses them; the purchase link never calls onNavigate, so
  modal hosts stay open. ProfileFormModal reuses UpsellGate instead of
  its compact panel, keeps its Cancel button, and closes after "I
  already have a key" (onNavigate={onClose}).
- In Free, the Updates card offers Get Base, I already have a key and
  Download the latest version; the error page (outside the router)
  offers Get Base and the download link. No update check, no network
  call.
- i18n FR/EN: Account card text, Premium note, Updates notEntitled text,
  download label, editions guide step and tip; the "coming soon" note
  key is gone. Tests pin the upsell key set and the decided texts.
- Docs: ADR 0017 amendment, architecture (UpsellGate row, shared CTAs,
  upsellCtaFor, multi-profile row, counts), user guide section 12;
  CHANGELOG FR/EN.

Proven red: Premium made purchasable 2, balance sold as Base in the
matrix 4, the old note key back in a locale 1, Account text altered 1,
download label altered 1.

Fixes #346

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 15:50:45 -04:00

66 lines
2.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { upsellCtaFor } from "./upsellCta";
import { ENTITLEMENTS, requiredTierFor, type FeatureKey } from "./entitlements";
import fr from "../i18n/locales/fr.json";
import en from "../i18n/locales/en.json";
// No jsdom here: this pure rule is the only automated proof of what a locked
// screen offers (issue #346, decision A1).
describe("upsellCtaFor", () => {
it("makes Base purchasable, with no note", () => {
expect(upsellCtaFor("base")).toEqual({ purchasable: true, noteKey: null });
});
it("keeps Premium disabled, with the not-for-sale note", () => {
expect(upsellCtaFor("premium")).toEqual({
purchasable: false,
noteKey: "upsell.premiumNotForSale",
});
});
it("offers nothing for free, which no feature requires", () => {
expect(upsellCtaFor("free")).toEqual({ purchasable: false, noteKey: null });
});
});
// The same rule, walked through the real matrix: what each locked screen shows.
describe("upsellCtaFor on every gated feature", () => {
const features = Object.keys(ENTITLEMENTS) as FeatureKey[];
const resolve = (messages: unknown, key: string): unknown =>
key
.split(".")
.reduce<unknown>(
(node, part) =>
node && typeof node === "object" ? (node as Record<string, unknown>)[part] : undefined,
messages,
);
it("sells Base on the Budget, Adjustments, advanced reports and extra profile screens", () => {
for (const f of ["budget", "adjustments", "reports-advanced", "multi-profile"] as FeatureKey[]) {
expect(upsellCtaFor(requiredTierFor(f)), f).toEqual({ purchasable: true, noteKey: null });
}
});
it("keeps the Balance screen (Premium) disabled with its note", () => {
expect(upsellCtaFor(requiredTierFor("balance"))).toEqual({
purchasable: false,
noteKey: "upsell.premiumNotForSale",
});
});
it("covers every feature of the matrix, with notes that exist in both locales", () => {
expect(features.sort()).toEqual(
["adjustments", "balance", "budget", "multi-profile", "reports-advanced"].sort(),
);
for (const f of features) {
const { noteKey } = upsellCtaFor(requiredTierFor(f));
if (noteKey === null) continue;
for (const [lng, messages] of Object.entries({ fr, en })) {
const value = resolve(messages, noteKey);
expect(typeof value, `${noteKey} in ${lng}`).toBe("string");
expect((value as string).trim(), `${noteKey} in ${lng}`).not.toBe("");
}
}
});
});