Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Keep the sender in the same draft when going Back from Add signers

Claude5b0dd99160b7
diff --git a/e2e/support/admin-session.ts b/e2e/support/admin-session.ts
new file mode 100644
index 0000000..91d743d
--- /dev/null
+++ b/e2e/support/admin-session.ts
@@ -0,0 +1,51 @@
+import { expect, type Page } from "@playwright/test";
+import pg from "pg";
+
+import { e2eDatabaseUrl } from "../../playwright.config";
+
+// The password every account in signing-flow.spec.ts is made with.
+export const E2E_PASSWORD = "correct horse battery staple 42";
+
+/**
+ * Signs in as the administrator that the first test in signing-flow.spec.ts
+ * sets up. The last test there turns on two-step sign-in for them, so it is
+ * turned off again first: these tests are about other things, and a
+ * password is enough for them.
+ */
+export async function signInAsAdministrator(page: Page): Promise<string> {
+ const database = new pg.Client({ connectionString: e2eDatabaseUrl });
+ let adminEmail = "";
+
+ await database.connect();
+
+ try {
+ const admin = await database.query<{ email: string; id: string }>(
+ `select id, email from public."user" where role = 'admin' order by "createdAt" limit 1`,
+ );
+
+ adminEmail = admin.rows[0]?.email ?? "";
+
+ await database.query(
+ `update public."user" set "twoFactorEnabled" = false where id = $1`,
+ [admin.rows[0]?.id],
+ );
+ await database.query(`delete from public."twoFactor" where "userId" = $1`, [
+ admin.rows[0]?.id,
+ ]);
+ await database.query(
+ `update public.app_settings set require_two_factor = false`,
+ );
+ } finally {
+ await database.end();
+ }
+
+ expect(adminEmail).not.toBe("");
+
+ await page.goto("/login");
+ await page.getByLabel("Email").fill(adminEmail);
+ await page.getByLabel("Password").fill(E2E_PASSWORD);
+ await page.getByRole("button", { name: "Log in" }).click();
+ await expect(page).toHaveURL(/\/dashboard$/);
+
+ return adminEmail;
+}
diff --git a/e2e/wizard-signers-back.spec.ts b/e2e/wizard-signers-back.spec.ts
new file mode 100644
index 0000000..f0dff6c
--- /dev/null
+++ b/e2e/wizard-signers-back.spec.ts
@@ -0,0 +1,55 @@
+import { expect, test } from "@playwright/test";
+import pg from "pg";
+
+import { e2eDatabaseUrl } from "../playwright.config";
+import { signInAsAdministrator } from "./support/admin-session";
+import { writeSamplePdf } from "./support/sample-pdf";
+
+// Runs after signing-flow.spec.ts, which sets up the install and its
+// administrator.
+
+const TITLE = "Back from signers";
+
+async function countDrafts(): Promise<number> {
+ const database = new pg.Client({ connectionString: e2eDatabaseUrl });
+
+ await database.connect();
+
+ try {
+ const result = await database.query<{ total: number }>(
+ `select count(*)::int as total from envelopes where title = $1`,
+ [TITLE],
+ );
+
+ return result.rows[0]?.total ?? 0;
+ } finally {
+ await database.end();
+ }
+}
+
+test("Back from Add signers stays in the same draft", async ({
+ page,
+}, testInfo) => {
+ await signInAsAdministrator(page);
+
+ const pdfPath = await writeSamplePdf(testInfo.outputPath("back.pdf"));
+
+ await page.goto("/envelopes/new");
+ await page.getByLabel("Envelope title").fill(TITLE);
+ await page.getByLabel("Upload PDF").setInputFiles(pdfPath);
+ await page.getByRole("button", { name: "Next ->" }).click();
+ await expect(page).toHaveURL(/\/envelopes\/[^/]+\/signers$/);
+
+ const envelopeId =
+ /\/envelopes\/([^/]+)\/signers$/.exec(page.url())?.[1] ?? "";
+
+ await page.getByRole("link", { name: "← Back" }).click();
+
+ // The draft's own page, not a blank upload form that would make another.
+ await expect(page).toHaveURL(new RegExp(`/envelopes/${envelopeId}$`));
+ await expect(page.getByRole("heading", { name: TITLE })).toBeVisible();
+ await expect(
+ page.getByRole("link", { name: "Continue editing" }),
+ ).toBeVisible();
+ expect(await countDrafts()).toBe(1);
+});
diff --git a/src/components/envelopes/signers-shell.tsx b/src/components/envelopes/signers-shell.tsx
index 7ae4789..1f9cffa 100644
--- a/src/components/envelopes/signers-shell.tsx
+++ b/src/components/envelopes/signers-shell.tsx
@@ -1116,7 +1116,10 @@ export function SignersShell({
</div>
<div className="flex flex-col-reverse gap-3 pt-2 sm:flex-row sm:justify-end">
- <ShellButton href="/envelopes/new" variant="secondary">
+ {/* The document is part of the draft and is not uploaded again,
+ so Back goes to this draft's own page, where it can be
+ continued or deleted, not to a blank upload form. */}
+ <ShellButton href={`/envelopes/${envelopeId}`} variant="secondary">
← Back
</ShellButton>
<ShellButton