add cypress home page spec

This commit is contained in:
Yisroel Baum 2026-05-06 23:25:44 +03:00
parent 07f9746316
commit 84ee24c2ee
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -0,0 +1,101 @@
describe("home 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 first",
body: "Alice's first post.",
});
cy.seedPostAs({
email: "bob@example.com",
password: "longenoughpassword",
title: "Bob says hi",
body: "Bob's only post.",
});
cy.seedPostAs({
email: "alice@example.com",
password: "longenoughpassword",
title: "Alice second",
body: "Alice's second post.",
});
});
it("renders recent posts in newest-first order with author links", function () {
cy.visit("/");
cy.contains("h2", "Recent posts").should("be.visible");
cy.get(".recent .post-card").should("have.length", 3);
cy.get(".recent .post-card").first().within(function () {
cy.contains("Alice second");
cy.contains("a", "alice");
});
});
it("hides the featured section when no posts are featured", function () {
cy.visit("/");
cy.contains("h2", "Featured").should("not.exist");
});
it("shows featured posts in slot order once an admin features them", function () {
cy.seedAdmin({
email: "admin@example.com",
displayName: "rootadmin",
password: "longenoughpassword",
});
cy.request("/api/posts").then(function (response) {
const posts = response.body.posts as Array<{
id: number;
title: string;
}>;
const aliceSecond = posts.find(function (entry) {
return entry.title === "Alice second";
})!;
const bobPost = posts.find(function (entry) {
return entry.title === "Bob says hi";
})!;
cy.seedFeaturedPost({
adminEmail: "admin@example.com",
adminPassword: "longenoughpassword",
postId: bobPost.id,
slot: 2,
});
cy.seedFeaturedPost({
adminEmail: "admin@example.com",
adminPassword: "longenoughpassword",
postId: aliceSecond.id,
slot: 1,
});
});
cy.visit("/");
cy.contains("h2", "Featured").should("be.visible");
cy.get(".featured .post-card").should("have.length", 2);
cy.get(".featured .post-card").eq(0).contains("Alice second");
cy.get(".featured .post-card").eq(1).contains("Bob says hi");
});
it("searches users by display name and email prefix", function () {
cy.visit("/");
cy.get('input[type="search"]').type("al");
cy.get(".results li").should("have.length", 1);
cy.get(".results li").contains("alice");
cy.get('input[type="search"]').clear().type("b");
cy.get(".results li").should("have.length", 1);
cy.get(".results li").contains("bob");
cy.get('input[type="search"]').clear().type("zzz");
cy.get(".results li").should("have.length", 0);
});
});