From 7a84bfaa2f2aa0418318cac8c06f38c4fa408bfc Mon Sep 17 00:00:00 2001 From: kasperbirch1 Date: Mon, 20 Jun 2022 10:08:53 +0200 Subject: [PATCH] Add test to button favorite $ yarn run start:storybook:test Test for the following - Material id is not on user's favorites list - Material id is on user's favorites list - User can add and remove material id from favorite list --- .../button-favourite/button-favourite.test.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/components/button-favourite/button-favourite.test.ts diff --git a/src/components/button-favourite/button-favourite.test.ts b/src/components/button-favourite/button-favourite.test.ts new file mode 100644 index 0000000000..c9e02848a0 --- /dev/null +++ b/src/components/button-favourite/button-favourite.test.ts @@ -0,0 +1,46 @@ +describe("Favorite button", () => { + it("Material id is not on user's favorites list", () => { + cy.intercept("HEAD", "**/list/default/**", { + statusCode: 404, + body: {} + }); + cy.visit( + "/iframe.html?args=&id=components-button-favourite--favourite&viewMode=story" + ); + cy.get('[aria-label="Tilføj til favoritter"]'); + }); + + it("Material id is on user's favorites list", () => { + cy.intercept("HEAD", "**/list/default/**", { + statusCode: 200, + body: {} + }); + cy.visit( + "/iframe.html?args=&id=components-button-favourite--favourite&viewMode=story" + ); + cy.get('[aria-label="Fjern fra favoritter"]'); + }); + + it("User can add and remove material id from favorite list", () => { + cy.intercept("HEAD", "**/list/default/**", { + statusCode: 404, + body: {} + }); + cy.intercept("PUT", "**/list/default/**", { + statusCode: 201, + body: {} + }); + cy.intercept("DELETE", "**/list/default/**", { + statusCode: 204, + body: {} + }); + cy.visit( + "/iframe.html?args=&id=components-button-favourite--favourite&viewMode=story" + ); + cy.get('[aria-label="Tilføj til favoritter"]').click(); + cy.get('[aria-label="Fjern fra favoritter"]').click(); + cy.get('[aria-label="Tilføj til favoritter"]').click(); + }); +}); + +export {};