Fix splice(-1,1) removing last user when logged-in user not found

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 13:52:08 +08:00
parent 3db725e52c
commit 9acd722929
2 changed files with 35 additions and 3 deletions

View File

@@ -21,8 +21,8 @@ vi.mock("@/api/client.js", () => ({
}));
// Mock login store to avoid its side effects
vi.mock("@/stores/login", () => {
const { defineStore } = require("pinia");
vi.mock("@/stores/login", async () => {
const { defineStore } = await import("pinia");
return {
useLoginStore: defineStore("loginStore", {
state: () => ({
@@ -243,6 +243,36 @@ describe("acctMgmtStore", () => {
});
});
describe("moveCurrentLoginUserToFirstRow", () => {
it("moves logged-in user to first position", async () => {
const list = [
{ username: "alice", name: "Alice" },
{ username: "currentUser", name: "Current" },
{ username: "bob", name: "Bob" },
];
const result = await store.moveCurrentLoginUserToFirstRow(list);
expect(result.map((u) => u.username)).toEqual([
"currentUser",
"alice",
"bob",
]);
});
it("preserves list when logged-in user is not found", async () => {
const list = [
{ username: "alice", name: "Alice" },
{ username: "bob", name: "Bob" },
{ username: "charlie", name: "Charlie" },
];
const result = await store.moveCurrentLoginUserToFirstRow(list);
expect(result.map((u) => u.username)).toEqual([
"alice",
"bob",
"charlie",
]);
});
});
it("resetJustCreateFlag resets flag", () => {
store.isOneAccountJustCreate = true;
store.resetJustCreateFlag();