Add QWord table insertion command

This commit is contained in:
Курнат Андрей
2026-06-02 08:32:09 +03:00
parent 06c6a99e6d
commit 26bf4b5873
3 changed files with 148 additions and 0 deletions
+39
View File
@@ -102,6 +102,45 @@ describe("QWord", () => {
}
});
it("вставляет таблицу выбранного размера через вкладку Вставка", () => {
const originalResizeObserver = globalThis.ResizeObserver;
const originalRequestAnimationFrame = window.requestAnimationFrame;
const onChange = vi.fn();
globalThis.ResizeObserver = class {
observe() {}
disconnect() {}
} as unknown as typeof ResizeObserver;
window.requestAnimationFrame = ((callback: FrameRequestCallback) => {
callback(0);
return 1;
}) as typeof window.requestAnimationFrame;
const document: WordDocument = {
id: "word-insert-table-test",
title: "Таблица.docx",
updatedAt: "2026-06-02T00:00:00.000Z",
html: "<p>Перед таблицей</p>"
};
try {
render(<QWord document={document} onChange={onChange} />);
fireEvent.click(screen.getByRole("tab", { name: "Вставка" }));
fireEvent.change(screen.getByLabelText("Строки таблицы"), { target: { value: "2" } });
fireEvent.change(screen.getByLabelText("Столбцы таблицы"), { target: { value: "3" } });
fireEvent.click(screen.getByRole("button", { name: "Таблица" }));
const updatedDocument = onChange.mock.calls[onChange.mock.calls.length - 1]?.[0] as WordDocument | undefined;
expect(updatedDocument?.html).toContain("<table>");
expect(updatedDocument?.html.match(/<tr/g)).toHaveLength(2);
expect(updatedDocument?.html.match(/<td/g)).toHaveLength(6);
} finally {
globalThis.ResizeObserver = originalResizeObserver;
window.requestAnimationFrame = originalRequestAnimationFrame;
}
});
it("обновляет текущую страницу в статусе при прокрутке документа", async () => {
const originalResizeObserver = globalThis.ResizeObserver;
const originalRequestAnimationFrame = window.requestAnimationFrame;