From a76fc22e00979f50a6e5600022caa596c735a0c2 Mon Sep 17 00:00:00 2001 From: Morozov Artem <126605382+Temmmmmo@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:02:59 +0300 Subject: [PATCH] fix(print): restore two-sided printing Restore the print setting disabled in 1b2dd86 (#45) in the current TypeScript UI. Send options.two_sided explicitly and cover default, enabled, and disabled modes in browser tests. --- src/api/printer.ts | 7 ++++- src/assets/main.css | 8 ++++++ src/components/SendTaskDialog.vue | 10 ++++++- tests/api.test.ts | 15 +++++++++- tests/browser/printing.spec.ts | 46 +++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/api/printer.ts b/src/api/printer.ts index ca96418..fba34aa 100644 --- a/src/api/printer.ts +++ b/src/api/printer.ts @@ -6,6 +6,7 @@ export interface PrintRequest { file: File; copies: number; pages: string; + twoSided: boolean; } const base = () => process.env.VUE_APP_API_PRINTER; @@ -20,7 +21,11 @@ export async function uploadFile( number: input.number.trim(), filename: input.file.name, source: "webapp", - options: { copies: input.copies, pages: input.pages.replace(/\s/g, "") }, + options: { + copies: input.copies, + pages: input.pages.replace(/\s/g, ""), + two_sided: input.twoSided, + }, }, { timeout: 30_000 }, ); diff --git a/src/assets/main.css b/src/assets/main.css index 67a81b4..1da2e1a 100644 --- a/src/assets/main.css +++ b/src/assets/main.css @@ -283,6 +283,14 @@ summary span { .settings-fields { padding-bottom: 20px; } +.print-option { + grid-column: 1 / -1; + display: flex; + align-items: center; + gap: 10px; + font-size: 13px; + cursor: pointer; +} .button { min-height: 46px; padding: 12px 18px; diff --git a/src/components/SendTaskDialog.vue b/src/components/SendTaskDialog.vue index a9acc1c..8afdae8 100644 --- a/src/components/SendTaskDialog.vue +++ b/src/components/SendTaskDialog.vue @@ -14,6 +14,7 @@ const number = ref(session ? "" : readStorage("number")); const file = ref(); const copies = ref(1); const pages = ref(""); +const twoSided = ref(false); const busy = ref(false); const progress = ref(0); const error = ref(""); @@ -94,6 +95,7 @@ async function send() { file: file.value, copies: copies.value, pages: pages.value, + twoSided: twoSided.value, }, (percent) => { progress.value = percent; @@ -171,7 +173,9 @@ async function send() { diff --git a/tests/api.test.ts b/tests/api.test.ts index 682be63..dc328e9 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -18,7 +18,14 @@ test("upload reserves PIN then sends multipart PDF with progress; QR sends uniqu const file = new File(["%PDF-1.7"], "notes.pdf"); assert.equal( await uploadFile( - { surname: " Иванов ", number: " 123 ", file, copies: 1, pages: "" }, + { + surname: " Иванов ", + number: " 123 ", + file, + copies: 1, + pages: "", + twoSided: false, + }, () => {}, ), "AB12", @@ -26,6 +33,11 @@ test("upload reserves PIN then sends multipart PDF with progress; QR sends uniqu assert.equal(calls.length, 2); assert.match(calls[0].url, /\/file$/); assert.equal(JSON.parse(calls[0].data as string).surname, "Иванов"); + assert.deepEqual(JSON.parse(calls[0].data as string).options, { + copies: 1, + pages: "", + two_sided: false, + }); assert.match(calls[1].url, /\/file\/AB12$/); assert.equal((calls[1].data as FormData).get("file"), file); await printQr("token", ["AB12", "AB12"]); @@ -60,6 +72,7 @@ test("failed reservation does not upload and failed QR is not treated as success file: new File(["%PDF-"], "n.pdf"), copies: 1, pages: "", + twoSided: false, }, () => {}, ), diff --git a/tests/browser/printing.spec.ts b/tests/browser/printing.spec.ts index 1720e4a..1ff7bbf 100644 --- a/tests/browser/printing.spec.ts +++ b/tests/browser/printing.spec.ts @@ -8,6 +8,7 @@ test("upload, PIN, old history and embedded context survive navigation", async ( uploads = 0; await page.route("**/print/file", async (route) => { reserves++; + expect(route.request().postDataJSON().options.two_sided).toBe(false); await new Promise((resolve) => setTimeout(resolve, 200)); await route.fulfill({ json: { pin: "AB12CD" } }); }); @@ -45,6 +46,51 @@ test("upload, PIN, old history and embedded context survive navigation", async ( ), ).toBe(true); }); +for (const twoSided of [true, false]) { + test(`print settings send two_sided=${twoSided} after toggling the checkbox`, async ({ + page, + }) => { + await page.route("**/print/file", (route) => + route.fulfill({ json: { pin: "AB12CD" } }), + ); + await page.route("**/print/file/AB12CD", (route) => + route.fulfill({ json: { pin: "AB12CD" } }), + ); + await page.goto("/"); + await page.getByLabel("Фамилия", { exact: true }).fill("Иванов"); + await page + .getByLabel("Номер профсоюзного билета", { exact: true }) + .fill("123456"); + await page.locator("#file").setInputFiles({ + name: "Лекция.pdf", + mimeType: "application/pdf", + buffer: Buffer.from("%PDF-1.7\nexample"), + }); + await page.getByText("Настройки печати", { exact: false }).click(); + const checkbox = page.getByRole("checkbox", { + name: "Двусторонняя печать", + }); + await expect(checkbox).not.toBeChecked(); + await checkbox.check(); + await checkbox.setChecked(twoSided); + await page.getByLabel("Количество копий").fill("2"); + await page.getByLabel("Страницы", { exact: true }).fill("1-3, 5"); + + const reservation = page.waitForRequest( + (request) => + request.url().endsWith("/print/file") && request.method() === "POST", + ); + await page.getByRole("button", { name: "Загрузить для печати" }).click(); + expect((await reservation).postDataJSON().options).toEqual({ + copies: 2, + pages: "1-3,5", + two_sided: twoSided, + }); + await expect( + page.getByRole("heading", { name: "Можно идти к принтеру" }), + ).toBeVisible(); + }); +} test("upload failure preserves input and corrupt history remains usable", async ({ page, }) => {