/** * @file ChangesPanelSettings.test.tsx * @description Settings → Git → Changes panel: the inner-repositories switch * starts off, turning it on stores `all` in the synced account preference, * and turning it off again removes the key (back to the default). * @author Nguyễn Ngọc Trí Vĩ */ import { describe, it, expect, beforeEach } from "vitest"; import { render, screen, fireEvent } from "@testing-library/react"; import { ChangesPanelSettings } from "../ChangesPanelSettings"; import { INNER_REPOS_KEY, readInnerReposMode } from "../../../lib/innerReposPref"; describe("ChangesPanelSettings", () => { beforeEach(() => localStorage.clear()); it("is off by default and toggles the account preference", () => { render(); const sw = screen.getByRole("switch", { name: /Show the repositories inside the workspace folder/, }); expect(sw).toHaveAttribute("aria-checked", "false"); expect(readInnerReposMode()).toBe("own"); fireEvent.click(sw); expect(localStorage.getItem(INNER_REPOS_KEY)).toBe("all"); expect(sw).toHaveAttribute("aria-checked", "true"); fireEvent.click(sw); expect(localStorage.getItem(INNER_REPOS_KEY)).toBeNull(); expect(readInnerReposMode()).toBe("own"); }); });