add cypress new-post spec

This commit is contained in:
Yisroel Baum 2026-05-06 23:26:14 +03:00
parent 66ad7b1a0f
commit 6f160ddd4e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

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