style: fix formatting via prettier

This commit is contained in:
2026-08-28 14:29:54 +05:00
parent 10278981ba
commit ada96b3534
124 changed files with 8211 additions and 5662 deletions
+29 -27
View File
@@ -1,23 +1,25 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { getTheme, initTheme, setTheme } from './theme.svelte';
import { beforeEach, describe, expect, it, vi } from "vitest";
import { getTheme, initTheme, setTheme } from "./theme.svelte";
type Store = Record<string, string>;
function stubEnv(opts: { attr?: string; system?: boolean } = {}) {
const store: Store = {};
vi.stubGlobal('localStorage', {
vi.stubGlobal("localStorage", {
getItem: (k: string) => (k in store ? store[k] : null),
setItem: (k: string, v: string) => {
store[k] = v;
}
},
});
const doc: { documentElement: { dataset: Record<string, string | undefined> } } = {
documentElement: { dataset: {} }
const doc: {
documentElement: { dataset: Record<string, string | undefined> };
} = {
documentElement: { dataset: {} },
};
if (opts.attr !== undefined) doc.documentElement.dataset.theme = opts.attr;
vi.stubGlobal('document', doc);
vi.stubGlobal('window', {
matchMedia: (_q: string) => ({ matches: opts.system ?? false })
vi.stubGlobal("document", doc);
vi.stubGlobal("window", {
matchMedia: (_q: string) => ({ matches: opts.system ?? false }),
});
return { store, doc };
}
@@ -26,38 +28,38 @@ beforeEach(() => {
vi.unstubAllGlobals();
});
describe('initTheme', () => {
it('доверяет атрибуту от анти-вспышки скрипта', () => {
stubEnv({ attr: 'dark' });
describe("initTheme", () => {
it("доверяет атрибуту от анти-вспышки скрипта", () => {
stubEnv({ attr: "dark" });
initTheme();
expect(getTheme()).toBe('dark');
expect(getTheme()).toBe("dark");
});
it('без атрибута берёт системную тему', () => {
it("без атрибута берёт системную тему", () => {
stubEnv({ system: true });
initTheme();
expect(getTheme()).toBe('dark');
expect(getTheme()).toBe("dark");
stubEnv({ system: false });
initTheme();
expect(getTheme()).toBe('light');
expect(getTheme()).toBe("light");
});
it('мусорный атрибут игнорируется в пользу системной', () => {
stubEnv({ attr: 'sepia', system: false });
it("мусорный атрибут игнорируется в пользу системной", () => {
stubEnv({ attr: "sepia", system: false });
initTheme();
expect(getTheme()).toBe('light');
expect(getTheme()).toBe("light");
});
});
describe('setTheme', () => {
it('сохраняет выбор и применяет атрибут на html', () => {
describe("setTheme", () => {
it("сохраняет выбор и применяет атрибут на html", () => {
const { store, doc } = stubEnv({});
initTheme();
setTheme('dark');
expect(store['theme']).toBe('dark');
expect(doc.documentElement.dataset.theme).toBe('dark');
setTheme('light');
expect(store['theme']).toBe('light');
expect(doc.documentElement.dataset.theme).toBe('light');
setTheme("dark");
expect(store["theme"]).toBe("dark");
expect(doc.documentElement.dataset.theme).toBe("dark");
setTheme("light");
expect(store["theme"]).toBe("light");
expect(doc.documentElement.dataset.theme).toBe("light");
});
});