From 6f160ddd4e778dbabf1c87b7a89c4ddbb14eee83 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Wed, 6 May 2026 23:26:14 +0300 Subject: [PATCH] add cypress new-post spec --- .../cypress/e2e/new_post_page.cy.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 frontend/blog_portal/cypress/e2e/new_post_page.cy.ts diff --git a/frontend/blog_portal/cypress/e2e/new_post_page.cy.ts b/frontend/blog_portal/cypress/e2e/new_post_page.cy.ts new file mode 100644 index 0000000..db9673b --- /dev/null +++ b/frontend/blog_portal/cypress/e2e/new_post_page.cy.ts @@ -0,0 +1,63 @@ +describe("new post 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", + }); + }); + + it("redirects anonymous visitors to /login", function () { + cy.visit("/users/alice/posts/new"); + cy.location("pathname").should("eq", "/login"); + }); + + it("redirects users away from another user's new-post page", function () { + cy.loginViaApi({ + email: "alice@example.com", + password: "longenoughpassword", + }); + + cy.visit("/users/bob/posts/new"); + cy.location("pathname").should("eq", "/"); + }); + + it("publishes a post and redirects to the new post page", function () { + cy.loginViaApi({ + email: "alice@example.com", + password: "longenoughpassword", + }); + + cy.visit("/users/alice/posts/new"); + cy.get('input[type="text"]').type("Hello world"); + cy.get("textarea").type("This is the body of my first post."); + cy.contains("button", "Publish").click(); + + cy.location("pathname").should("match", /^\/posts\/\d+$/); + cy.contains("h1", "Hello world").should("be.visible"); + cy.contains(".body", "This is the body of my first post.").should( + "be.visible", + ); + }); + + it("blocks submission when the title is empty (HTML5 validation)", function () { + cy.loginViaApi({ + email: "alice@example.com", + password: "longenoughpassword", + }); + + cy.visit("/users/alice/posts/new"); + cy.get("textarea").type("body only"); + cy.contains("button", "Publish").click(); + + cy.location("pathname").should("eq", "/users/alice/posts/new"); + cy.get('input[type="text"]:invalid').should("exist"); + }); +});