From d40efeec706a3a7a97d47d9dc07678659f768268 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Wed, 6 May 2026 23:26:55 +0300 Subject: [PATCH] add cypress admin actions spec --- .../cypress/e2e/admin_actions.cy.ts | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 frontend/blog_portal/cypress/e2e/admin_actions.cy.ts diff --git a/frontend/blog_portal/cypress/e2e/admin_actions.cy.ts b/frontend/blog_portal/cypress/e2e/admin_actions.cy.ts new file mode 100644 index 0000000..7412b2e --- /dev/null +++ b/frontend/blog_portal/cypress/e2e/admin_actions.cy.ts @@ -0,0 +1,99 @@ +describe("admin actions", function () { + beforeEach(function () { + cy.resetDb(); + cy.clearMail(); + cy.seedAdmin({ + email: "admin@example.com", + displayName: "rootadmin", + password: "longenoughpassword", + }); + 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 post", + body: "Body.", + }).as("alicePost"); + }); + + it("admin promotes another user via the profile page", function () { + cy.loginViaApi({ + email: "admin@example.com", + password: "longenoughpassword", + }); + + cy.visit("/users/alice"); + cy.contains("button", "Promote to admin").click(); + + cy.logoutViaApi(); + cy.loginViaApi({ + email: "alice@example.com", + password: "longenoughpassword", + }); + cy.get<{ id: number }>("@alicePost").then(function (post) { + cy.visit(`/posts/${post.id}`); + cy.contains("button", "Feature in slot 1").should("be.visible"); + }); + }); + + it("admin features a post and it shows up on the home page", function () { + cy.loginViaApi({ + email: "admin@example.com", + password: "longenoughpassword", + }); + + cy.get<{ id: number }>("@alicePost").then(function (post) { + cy.visit(`/posts/${post.id}`); + cy.contains("button", "Feature in slot 1").click(); + cy.contains(".badge", "Featured (slot 1)").should("be.visible"); + }); + + cy.logoutViaApi(); + cy.visit("/"); + cy.contains("h2", "Featured").should("be.visible"); + cy.get(".featured .post-card").should("have.length", 1); + cy.contains(".featured .post-card", "Alice post").should("be.visible"); + }); + + it("admin unfeaturing a post removes it from the home page", function () { + cy.loginViaApi({ + email: "admin@example.com", + password: "longenoughpassword", + }); + + cy.get<{ id: number }>("@alicePost").then(function (post) { + cy.visit(`/posts/${post.id}`); + cy.contains("button", "Feature in slot 1").click(); + cy.contains(".badge", "Featured (slot 1)").should("be.visible"); + cy.contains("button", "Unfeature").click(); + cy.contains(".badge", "Featured").should("not.exist"); + }); + + cy.logoutViaApi(); + cy.visit("/"); + cy.contains("h2", "Featured").should("not.exist"); + }); + + it("a newly promoted admin can also feature posts", function () { + cy.promoteAdmin("bob@example.com"); + cy.loginViaApi({ + email: "bob@example.com", + password: "longenoughpassword", + }); + + cy.get<{ id: number }>("@alicePost").then(function (post) { + cy.visit(`/posts/${post.id}`); + cy.contains("button", "Feature in slot 2").click(); + cy.contains(".badge", "Featured (slot 2)").should("be.visible"); + }); + }); +});