From 66ad7b1a0fec8f5ac780f6921de9371b158b022b Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Wed, 6 May 2026 23:26:00 +0300 Subject: [PATCH] add cypress profile page spec --- .../cypress/e2e/profile_page.cy.ts | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 frontend/blog_portal/cypress/e2e/profile_page.cy.ts diff --git a/frontend/blog_portal/cypress/e2e/profile_page.cy.ts b/frontend/blog_portal/cypress/e2e/profile_page.cy.ts new file mode 100644 index 0000000..375e3c9 --- /dev/null +++ b/frontend/blog_portal/cypress/e2e/profile_page.cy.ts @@ -0,0 +1,86 @@ +describe("profile page", function () { + beforeEach(function () { + cy.resetDb(); + cy.clearMail(); + cy.seedConfirmedUser({ + email: "alice@example.com", + displayName: "alice", + password: "longenoughpassword", + }); + cy.seedConfirmedUser({ + email: "bob@example.com", + displayName: "bob", + password: "longenoughpassword", + }); + cy.seedPostAs({ + email: "alice@example.com", + password: "longenoughpassword", + title: "Alice's only post", + body: "Hello.", + }); + }); + + it("shows posts to anonymous visitors without owner controls", function () { + cy.visit("/users/alice"); + cy.contains("h1", "alice").should("be.visible"); + cy.contains(".post-card", "Alice's only post").should("be.visible"); + cy.contains("button", "New post").should("not.exist"); + cy.contains("button", "Promote to admin").should("not.exist"); + }); + + it("shows the New post button when viewing your own profile", function () { + cy.loginViaApi({ + email: "alice@example.com", + password: "longenoughpassword", + }); + + cy.visit("/users/alice"); + cy.contains("button", "New post").should("be.visible"); + cy.contains("button", "Promote to admin").should("not.exist"); + }); + + it("hides the Promote button from non-admin viewers", function () { + cy.loginViaApi({ + email: "bob@example.com", + password: "longenoughpassword", + }); + + cy.visit("/users/alice"); + cy.contains("button", "Promote to admin").should("not.exist"); + }); + + it("shows the Promote button to an admin viewing someone else", function () { + cy.seedAdmin({ + email: "admin@example.com", + displayName: "rootadmin", + password: "longenoughpassword", + }); + cy.loginViaApi({ + email: "admin@example.com", + password: "longenoughpassword", + }); + + cy.visit("/users/alice"); + cy.contains("button", "Promote to admin").should("be.visible"); + }); + + it("hides the Promote button when an admin views their own profile", function () { + cy.seedAdmin({ + email: "admin@example.com", + displayName: "rootadmin", + password: "longenoughpassword", + }); + cy.loginViaApi({ + email: "admin@example.com", + password: "longenoughpassword", + }); + + cy.visit("/users/rootadmin"); + cy.contains("button", "Promote to admin").should("not.exist"); + }); + + it("renders a not-found panel for unknown display names", function () { + cy.visit("/users/nobody"); + cy.contains("h1", "User not found").should("be.visible"); + }); +});