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"); }); });