From 698e6fab607d74465a926f7d25f6defe0174f4e9 Mon Sep 17 00:00:00 2001 From: Maya Date: Sun, 8 Feb 2026 16:07:06 +0000 Subject: [PATCH] tests: cover PR #61 org invite flow --- frontend/cypress/e2e/organizations.cy.ts | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 frontend/cypress/e2e/organizations.cy.ts diff --git a/frontend/cypress/e2e/organizations.cy.ts b/frontend/cypress/e2e/organizations.cy.ts new file mode 100644 index 00000000..1d7f91a6 --- /dev/null +++ b/frontend/cypress/e2e/organizations.cy.ts @@ -0,0 +1,54 @@ +describe("Organizations (PR #61)", () => { + const email = Cypress.env("CLERK_TEST_EMAIL") || "jane+clerk_test@example.com"; + + beforeEach(() => { + // Story: user signs in via official Clerk Cypress commands. + cy.visit("/sign-in"); + cy.clerkLoaded(); + cy.clerkSignIn({ strategy: "email_code", identifier: email }); + }); + + it("signed-in user can open /organization and create an invite link", () => { + // Story (positive): org admin invites a teammate. + cy.visit("/organization"); + + cy.contains(/members\s*&\s*invites/i, { timeout: 30_000 }).should("be.visible"); + + // Open invite dialog. + cy.contains("button", /invite member/i).should("be.visible").click(); + + const invitedEmail = `cypress+invite-${Date.now()}@example.com`; + + // Fill invite form. + cy.get('input[type="email"]').should("be.visible").clear().type(invitedEmail); + + cy.contains("button", /send invite|invite|create/i).click(); + + // Confirm invite shows up in table. + cy.contains(invitedEmail, { timeout: 30_000 }).should("be.visible"); + + // Stub clipboard and verify "Copy link" emits /invite?token=... + cy.window().then((win) => { + // Some browsers/environments may not expose clipboard; guard accordingly. + if (!win.navigator.clipboard) { + // @ts-expect-error - allow defining clipboard in test runtime + win.navigator.clipboard = { writeText: () => Promise.resolve() }; + } + cy.stub(win.navigator.clipboard, "writeText").as("writeText"); + }); + + // Click copy link for this invite row. + cy.contains("tr", invitedEmail) + .should("be.visible") + .within(() => { + cy.contains("button", /copy link/i).click(); + }); + + cy.get("@writeText").should("have.been.calledOnce"); + cy.get("@writeText").should((writeText) => { + const stub = writeText as unknown as sinon.SinonStub; + const text = stub.getCall(0).args[0] as string; + expect(text).to.match(/\/invite\?token=/); + }); + }); +});