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