test: add component tests

This commit is contained in:
2026-02-08 13:01:59 +05:00
parent 1a0d99828e
commit 1b0675e4b2
16 changed files with 479 additions and 4 deletions
@@ -0,0 +1,31 @@
import TextConfig from "$components/text/TextConfig.svelte";
import { render, screen, cleanup } from "@testing-library/svelte";
import { describe, expect, it, afterEach } from "vitest";
afterEach(() => {
cleanup();
});
describe("TextConfig.svelte", () => {
it("should render with card title", () => {
render(TextConfig);
expect(screen.getByText("Настройки текста")).toBeInTheDocument();
});
it("should render all settings controls", () => {
render(TextConfig);
expect(screen.getByText("Размер")).toBeInTheDocument();
expect(screen.getByText("Шрифт")).toBeInTheDocument();
expect(screen.getByText("Цвет")).toBeInTheDocument();
expect(screen.getByText("Выравнивание")).toBeInTheDocument();
expect(screen.getByText("Отступы")).toBeInTheDocument();
expect(screen.getByText("Смещение")).toBeInTheDocument();
});
it("should have correct structure with SettingsGrid", () => {
render(TextConfig);
const settingsGrid = document.querySelector(".settings-grid");
expect(settingsGrid).toBeInTheDocument();
});
});
@@ -0,0 +1,62 @@
import TextInlineEdit from "$components/text/TextInlineEdit.svelte";
import { render, cleanup } from "@testing-library/svelte";
import { describe, expect, it, afterEach } from "vitest";
afterEach(() => {
cleanup();
});
describe("TextInlineEdit.svelte", () => {
it("should render with initial text", () => {
render(TextInlineEdit, {
props: {
id: 1,
text: "Test text",
ondelete: () => {},
},
});
const input = document.querySelector("input[type='text']");
expect(input).toBeInTheDocument();
expect(input).toHaveValue("Test text");
});
it("should render delete button", () => {
render(TextInlineEdit, {
props: {
id: 1,
text: "Test",
ondelete: () => {},
},
});
const deleteBtn = document.querySelector("button");
expect(deleteBtn).toBeInTheDocument();
});
it("should have text-item class", () => {
render(TextInlineEdit, {
props: {
id: 1,
text: "Test",
ondelete: () => {},
},
});
const textItem = document.querySelector(".text-item");
expect(textItem).toBeInTheDocument();
});
it("should render with empty text", () => {
render(TextInlineEdit, {
props: {
id: 1,
text: "",
ondelete: () => {},
},
});
const input = document.querySelector("input[type='text']");
expect(input).toHaveValue("");
});
});
@@ -0,0 +1,40 @@
import TextManager from "$components/text/TextManager.svelte";
import { textsState } from "$states/texts.svelte";
import { render, screen } from "@testing-library/svelte";
import { beforeEach, describe, expect, it } from "vitest";
describe("TextManager.svelte", () => {
beforeEach(() => {
textsState.texts.length = 0;
});
it("should render with card title", () => {
render(TextManager);
expect(screen.getByText("Тексты панелей")).toBeInTheDocument();
});
it("should render input group", () => {
render(TextManager);
const inputGroup = document.querySelector(".input-group");
expect(inputGroup).toBeInTheDocument();
});
it("should show empty state when no texts", () => {
render(TextManager);
const textsList = document.querySelector(".texts-list");
expect(textsList).toBeInTheDocument();
expect(textsList?.children.length).toBe(0);
});
it("should render texts-list container", () => {
render(TextManager);
const textsList = document.querySelector(".texts-list");
expect(textsList).toBeInTheDocument();
});
it("should have correct structure with Card", () => {
render(TextManager);
const card = document.querySelector("section.card, div[class*='card']");
expect(card).toBeInTheDocument();
});
});