add cypress admin actions spec
This commit is contained in:
parent
db910c9431
commit
d40efeec70
1 changed files with 99 additions and 0 deletions
99
frontend/blog_portal/cypress/e2e/admin_actions.cy.ts
Normal file
99
frontend/blog_portal/cypress/e2e/admin_actions.cy.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
describe("admin actions", function () {
|
||||
beforeEach(function () {
|
||||
cy.resetDb();
|
||||
cy.clearMail();
|
||||
cy.seedAdmin({
|
||||
email: "admin@example.com",
|
||||
displayName: "rootadmin",
|
||||
password: "longenoughpassword",
|
||||
});
|
||||
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 post",
|
||||
body: "Body.",
|
||||
}).as("alicePost");
|
||||
});
|
||||
|
||||
it("admin promotes another user via the profile page", function () {
|
||||
cy.loginViaApi({
|
||||
email: "admin@example.com",
|
||||
password: "longenoughpassword",
|
||||
});
|
||||
|
||||
cy.visit("/users/alice");
|
||||
cy.contains("button", "Promote to admin").click();
|
||||
|
||||
cy.logoutViaApi();
|
||||
cy.loginViaApi({
|
||||
email: "alice@example.com",
|
||||
password: "longenoughpassword",
|
||||
});
|
||||
cy.get<{ id: number }>("@alicePost").then(function (post) {
|
||||
cy.visit(`/posts/${post.id}`);
|
||||
cy.contains("button", "Feature in slot 1").should("be.visible");
|
||||
});
|
||||
});
|
||||
|
||||
it("admin features a post and it shows up on the home page", function () {
|
||||
cy.loginViaApi({
|
||||
email: "admin@example.com",
|
||||
password: "longenoughpassword",
|
||||
});
|
||||
|
||||
cy.get<{ id: number }>("@alicePost").then(function (post) {
|
||||
cy.visit(`/posts/${post.id}`);
|
||||
cy.contains("button", "Feature in slot 1").click();
|
||||
cy.contains(".badge", "Featured (slot 1)").should("be.visible");
|
||||
});
|
||||
|
||||
cy.logoutViaApi();
|
||||
cy.visit("/");
|
||||
cy.contains("h2", "Featured").should("be.visible");
|
||||
cy.get(".featured .post-card").should("have.length", 1);
|
||||
cy.contains(".featured .post-card", "Alice post").should("be.visible");
|
||||
});
|
||||
|
||||
it("admin unfeaturing a post removes it from the home page", function () {
|
||||
cy.loginViaApi({
|
||||
email: "admin@example.com",
|
||||
password: "longenoughpassword",
|
||||
});
|
||||
|
||||
cy.get<{ id: number }>("@alicePost").then(function (post) {
|
||||
cy.visit(`/posts/${post.id}`);
|
||||
cy.contains("button", "Feature in slot 1").click();
|
||||
cy.contains(".badge", "Featured (slot 1)").should("be.visible");
|
||||
cy.contains("button", "Unfeature").click();
|
||||
cy.contains(".badge", "Featured").should("not.exist");
|
||||
});
|
||||
|
||||
cy.logoutViaApi();
|
||||
cy.visit("/");
|
||||
cy.contains("h2", "Featured").should("not.exist");
|
||||
});
|
||||
|
||||
it("a newly promoted admin can also feature posts", function () {
|
||||
cy.promoteAdmin("bob@example.com");
|
||||
cy.loginViaApi({
|
||||
email: "bob@example.com",
|
||||
password: "longenoughpassword",
|
||||
});
|
||||
|
||||
cy.get<{ id: number }>("@alicePost").then(function (post) {
|
||||
cy.visit(`/posts/${post.id}`);
|
||||
cy.contains("button", "Feature in slot 2").click();
|
||||
cy.contains(".badge", "Featured (slot 2)").should("be.visible");
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue