افزودن نشان نسخه به پایین بخش کناری

یک حباب کوچک و شیشه‌ای با فونت تک‌عرض در فوتر ستون کناری، کنار دکمهٔ خروج:

- `font-mono` — پشتهٔ فونت‌های سیستمی (ui-monospace، SFMono، Menlo،
  Consolas) که همیشه نصب‌اند؛ پس نسخه روی هر دستگاه یکسان رندر می‌شود،
  بدون انتظار برای وب‌فونت، و رقم‌ها جابه‌جا نمی‌شوند.
- شیشه‌ای با translucent و blur: `bg-white/5` + `border-white/10` +
  `backdrop-blur-sm`. بدون gradient و بدون shadow، مطابق §12 پلن.
- `ltr-inline` تا الگوریتم bidi در پوستهٔ RTL رشتهٔ لاتین را جابه‌جا نکند،
  و `tabular-nums` تا عرض numeralها ثابت بماند.

نسخه از `src/lib/version.ts` می‌آید — به‌جای import کردن کل
`package.json` که کل manifest را برای یک رشته به باندل کلاینت می‌کشید.
هزینهٔ این انتخاب drift است، پس `version.test.tsx` می‌سنجد که با
`apps/web/package.json` یکی باشد.

تست‌های جدید: ۵ (نسخه و نشان نسخه در پوسته).
This commit is contained in:
mjalmoudy94
2026-10-13 08:35:29 +03:30
parent 3d1e98f4fb
commit 0fd50d94fc
3 changed files with 117 additions and 3 deletions
+64
View File
@@ -0,0 +1,64 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { AppShell } from "@/components/AppShell";
import { APP_VERSION, APP_VERSION_LABEL } from "@/lib/version";
/**
* `APP_VERSION` is a literal rather than a `package.json` import, because a
* whole-JSON import drags the manifest into the client bundle for one string.
* The cost of that choice is drift, so these tests pay it off: if someone
* bumps the manifest and forgets the literal, the UI would quietly claim the
* wrong build — which is exactly the bug a version badge exists to prevent.
*/
vi.mock("next/navigation", () => ({
useRouter: () => ({ push: vi.fn(), replace: vi.fn() }),
usePathname: () => "/dashboard",
}));
vi.mock("@/lib/session", () => ({
useSession: () => ({
ready: true,
token: "token",
user: { email: "owner@example.com", name: "مالک", is_platform_owner: false },
organizations: [],
activeOrganization: null,
setActiveOrganization: vi.fn(),
logout: vi.fn(),
}),
}));
const manifest = JSON.parse(
readFileSync(join(process.cwd(), "package.json"), "utf-8"),
) as { version: string };
describe("app version", () => {
it("matches the version in apps/web/package.json", () => {
expect(APP_VERSION).toBe(manifest.version);
});
it("renders with a v prefix so it reads as a version in the UI", () => {
expect(APP_VERSION_LABEL).toBe(`v${APP_VERSION}`);
});
it("is a plain semver triple with no pre-release or build metadata", () => {
// The pill is ~40px wide and offers no truncation affordance; anything
// longer than x.y.z would overflow the footer next to the logout button.
expect(APP_VERSION).toMatch(/^\d+\.\d+\.\d+$/);
});
});
describe("sidebar version badge", () => {
it("shows the version in the shell footer", () => {
render(<AppShell><p>بدنه</p></AppShell>);
expect(screen.getByText(APP_VERSION_LABEL)).toBeInTheDocument();
});
it("sets the direction explicitly so the RTL shell cannot reorder it", () => {
render(<AppShell><p>بدنه</p></AppShell>);
const badge = screen.getByText(APP_VERSION_LABEL);
expect(badge.className).toContain("ltr-inline");
});
});