From 7aaf25bfe0bb94e3f33ec651a1b3b8abe8e8cd6a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:53:44 +0000 Subject: [PATCH 1/4] test(i18n): add comprehensive tests for translation function and locale management Co-authored-by: chuanman2707 <29907469+chuanman2707@users.noreply.github.com> --- mhm/src/lib/i18n.test.ts | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 mhm/src/lib/i18n.test.ts diff --git a/mhm/src/lib/i18n.test.ts b/mhm/src/lib/i18n.test.ts new file mode 100644 index 0000000..aaa6764 --- /dev/null +++ b/mhm/src/lib/i18n.test.ts @@ -0,0 +1,51 @@ +import { describe, expect, it, beforeEach } from "vitest"; +import { setLocale, getLocale, t, type Locale } from "./i18n"; + +describe("i18n", () => { + beforeEach(() => { + // Reset localStorage and locale before each test + localStorage.clear(); + setLocale("vi"); + }); + + describe("locale management", () => { + it("should return the default locale (vi)", () => { + expect(getLocale()).toBe("vi"); + }); + + it("should update the locale and store it in localStorage", () => { + setLocale("en"); + expect(getLocale()).toBe("en"); + expect(localStorage.getItem("locale")).toBe("en"); + + setLocale("vi"); + expect(getLocale()).toBe("vi"); + expect(localStorage.getItem("locale")).toBe("vi"); + }); + }); + + describe("translation function (t)", () => { + it("should return the translated string for a valid key in the default locale", () => { + setLocale("vi"); + expect(t("nav.dashboard")).toBe("Dashboard"); + expect(t("nav.reservations")).toBe("Đặt phòng"); + }); + + it("should return the translated string for a valid key when the locale is changed", () => { + setLocale("en"); + expect(t("nav.reservations")).toBe("Reservations"); + expect(t("guests.total")).toBe("Total Guests"); + }); + + it("should fall back to returning the key if it is not found", () => { + expect(t("unknown.key")).toBe("unknown.key"); + expect(t("another.missing.key")).toBe("another.missing.key"); + }); + + it("should fallback to 'vi' if current locale translation is somehow missing", () => { + // Force a non-existent locale to test the fallback behavior + setLocale("fr" as Locale); + expect(t("nav.reservations")).toBe("Đặt phòng"); // Should fallback to "vi" + }); + }); +}); From 0bac9a1a46edc75a935430c400c3e95a025349d5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 16:03:35 +0000 Subject: [PATCH 2/4] test(i18n): add comprehensive tests for translation function and locale management Also fixes a Clippy warning (`clippy::unnecessary_sort_by`) in `groups.rs` by changing `.sort_by(|a, b| b.1.len().cmp(&a.1.len()))` to `.sort_by_key(|b| std::cmp::Reverse(b.1.len()))`. Co-authored-by: chuanman2707 <29907469+chuanman2707@users.noreply.github.com> From 517df516705e4928e0ecdd93152a4c867eee66ca Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 16:17:15 +0000 Subject: [PATCH 3/4] test(i18n): add comprehensive tests for translation function and locale management Also fixes a Clippy warning (`clippy::unnecessary_sort_by`) in `groups.rs` by changing `.sort_by(|a, b| b.1.len().cmp(&a.1.len()))` to `.sort_by_key(|b| std::cmp::Reverse(b.1.len()))`. Co-authored-by: chuanman2707 <29907469+chuanman2707@users.noreply.github.com> --- mhm/src-tauri/src/commands/groups.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mhm/src-tauri/src/commands/groups.rs b/mhm/src-tauri/src/commands/groups.rs index 8efa2f1..93bd111 100644 --- a/mhm/src-tauri/src/commands/groups.rs +++ b/mhm/src-tauri/src/commands/groups.rs @@ -297,7 +297,7 @@ pub async fn auto_assign_rooms( } let mut floors_sorted: Vec<(i32, Vec<&Room>)> = floor_groups.into_iter().collect(); - floors_sorted.sort_by(|a, b| b.1.len().cmp(&a.1.len())); + floors_sorted.sort_by_key(|b| std::cmp::Reverse(b.1.len())); let mut assignments = Vec::new(); let needed = req.room_count as usize; From e6a41aed8ad897a9ee178dd4ebc677b22a26dd46 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 17 Apr 2026 01:41:27 +0000 Subject: [PATCH 4/4] test(i18n): add comprehensive tests for translation function and locale management Co-authored-by: chuanman2707 <29907469+chuanman2707@users.noreply.github.com>