feat(me): organize personal dashboard and localize user actions
This commit is contained in:
1 parent
2840ef5d9d
commit
85a6df162b
9 files changed
+768
-576
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createTranslator } from "next-intl";
|
||||
import { expect, it } from "vitest";
|
||||
import en from "@/messages/en.json";
|
||||
import italian from "@/messages/it.json";
|
||||
|
||||
it.each([
|
||||
["en", en],
|
||||
["it", italian],
|
||||
] as const)("renders all dashboard messages in %s", (locale, messages) => {
|
||||
const errors: unknown[] = [];
|
||||
const t = createTranslator({
|
||||
locale,
|
||||
messages: messages as typeof en,
|
||||
namespace: "pages.myDashboard",
|
||||
onError: (error) => errors.push(error),
|
||||
});
|
||||
const keys = new Set(
|
||||
["credits", "duckets", "diamonds", "points"].map(
|
||||
(key) => `currencies.${key}`,
|
||||
),
|
||||
);
|
||||
for (const error of [
|
||||
"not_enough",
|
||||
"no_referrals",
|
||||
"bad_config",
|
||||
"ratelimit",
|
||||
"error",
|
||||
])
|
||||
keys.add(`errors.${error}`);
|
||||
for (const file of ["page.tsx", "CopyReferralButton.tsx"]) {
|
||||
for (const match of readFileSync(
|
||||
`src/app/(site)/me/${file}`,
|
||||
"utf8",
|
||||
).matchAll(/\bt\("([^"]+)"/g))
|
||||
keys.add(match[1]);
|
||||
}
|
||||
for (const key of keys) {
|
||||
const message = key as Parameters<typeof t>[0];
|
||||
expect(t.has(message), key).toBe(true);
|
||||
expect(
|
||||
t(message, {
|
||||
count: 3,
|
||||
amount: "30",
|
||||
currency: "Diamanti",
|
||||
hotel: "Epicnabbo",
|
||||
date: "06/09/2026",
|
||||
}),
|
||||
key,
|
||||
).not.toBe("");
|
||||
}
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
Reference in new issue
Block a user