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