Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/api/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface PrintRequest {
file: File;
copies: number;
pages: string;
twoSided: boolean;
}
const base = () => process.env.VUE_APP_API_PRINTER;

Expand All @@ -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 },
);
Expand Down
8 changes: 8 additions & 0 deletions src/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion src/components/SendTaskDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const number = ref(session ? "" : readStorage("number"));
const file = ref<File>();
const copies = ref(1);
const pages = ref("");
const twoSided = ref(false);
const busy = ref(false);
const progress = ref(0);
const error = ref("");
Expand Down Expand Up @@ -94,6 +95,7 @@ async function send() {
file: file.value,
copies: copies.value,
pages: pages.value,
twoSided: twoSided.value,
},
(percent) => {
progress.value = percent;
Expand Down Expand Up @@ -171,7 +173,9 @@ async function send() {
<details class="print-settings">
<summary>
Настройки печати
<span>{{ copies }} коп. · {{ pages || "Все страницы" }}</span>
<span>{{ copies }} коп. · {{ pages || "Все страницы" }}{{
twoSided ? " · Двусторонняя" : ""
}}</span>
</summary>
<div class="fields-grid settings-fields">
<div class="field">
Expand All @@ -194,6 +198,10 @@ async function send() {
aria-describedby="pages-help"
/><small id="pages-help">Например: 1-3, 5</small>
</div>
<label class="print-option" for="two-sided">
<input id="two-sided" v-model="twoSided" type="checkbox" />
Двусторонняя печать
</label>
</div>
</details>
</fieldset>
Expand Down
15 changes: 14 additions & 1 deletion tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ 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",
);
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"]);
Expand Down Expand Up @@ -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,
},
() => {},
),
Expand Down
46 changes: 46 additions & 0 deletions tests/browser/printing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" } });
});
Expand Down Expand Up @@ -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,
}) => {
Expand Down
Loading