mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-09-15 05:56:36 +00:00
style: fix formatting via prettier
This commit is contained in:
+29
-27
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user