Skip to content

Commit

Permalink
Extended the list to test that favorites render correctly and can be …
Browse files Browse the repository at this point in the history
…removed from the list
  • Loading branch information
JacobArrow committed Nov 28, 2024
1 parent 92fec11 commit becb835
Showing 1 changed file with 57 additions and 7 deletions.
64 changes: 57 additions & 7 deletions src/apps/favorites-list/favorites-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe("Favorites list", () => {
win.sessionStorage.setItem(TOKEN_LIBRARY_KEY, "random-token");
});

// To get the list of favorites
cy.intercept("GET", "**list/default**", {
statusCode: 200,
body: {
Expand All @@ -16,12 +17,17 @@ describe("Favorites list", () => {
"870970-basis:29630364"
]
}
}).as("favorites");
}).as("Favorites");

// To fill the heart
cy.intercept("HEAD", "**list/default/work-of**", {
// To mark materials as favorites
cy.intercept("HEAD", "**list/default/**", {
statusCode: 200
});
}).as("Favorite list service");

// To delete a material from favorites
cy.intercept("DELETE", "**list/default/**", {
statusCode: 200
}).as("Favorite list service");

cy.interceptRest({
aliasName: "Availability",
Expand All @@ -45,31 +51,75 @@ describe("Favorites list", () => {
cy.visit("/iframe.html?id=apps-favorite-list--primary&viewMode=story");
});

// Test that the list of favorites is displayed with materials correctly
it("Favorites list basics", () => {
// Wait for element not in skeleton screen to prevent testing prematurely.
cy.get(".cover").should("be.visible");

// 2.a. Header "Favorites"
// Header has "Favorites"
cy.get(".content-list-page").find("h1").should("have.text", "Favorites");
// Number of materials on list

// Sub header shows correct number of materials
cy.get(".content-list-page")
.find("p")
.eq(0)
.should("have.text", "3 materials");

// 2.f. Link on material to work page
// Material links to correct material
cy.get(".content-list-page")
.find(".card-list-item")
.eq(0)
.find("a")
.should("have.attr", "href")
.should("include", "/work/work-of:870970-basis:20636866");

// Material has filled heart icon
cy.get(".content-list-page")
.find(".card-list-item")
.eq(0)
.find(".icon-favourite")
.should("have.class", "icon-favourite--filled");
});

it("Favorites list paginates", () => {
// 2.h it paginates
cy.visit(
"/iframe.html?id=apps-favorite-list--primary&args=pageSizeDesktop:2;pageSizeMobile:2"
);
// Content list should only contain 2 materials
cy.get(".content-list-page")
.find(".card-list-item")
.should("have.length", 2);
// Show more materials
cy.get(".result-pager").find(".btn-primary").click();
// Content list should now contain 3 materials
cy.get(".content-list-page")
.find(".card-list-item")
.should("have.length", 3);
});

// Test that we can remove a material from the list of favorites
it("Remove favourite", () => {
// To get the list of favorites after removing one
cy.intercept("GET", "**list/default**", {
statusCode: 200,
body: {
id: "default",
collections: ["870970-basis:51363035", "870970-basis:29630364"]
}
}).as("favorites");

// Wait for element not in skeleton screen to prevent testing prematurely.
cy.get(".cover").should("be.visible");

// Find the first material in the list and click the heart icon
cy.get(".content-list-page")
.find(".card-list-item")
.eq(0)
.find(".button-favourite")
.click();

// Material list should now contain 2 materials
cy.get(".content-list-page")
.find(".card-list-item")
.should("have.length", 2);
Expand Down

0 comments on commit becb835

Please sign in to comment.