-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve documentation examples and add e2e tests to check that exampl…
…es works
- Loading branch information
1 parent
e78a91a
commit 7299012
Showing
4 changed files
with
131 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
test-e2e/react-app/cypress/integration/assertions-example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
describe("localStorage cookies-accepted item", () => { | ||
beforeEach(() => { | ||
cy.restoreLocalStorage(); | ||
cy.visit("/"); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.saveLocalStorage(); | ||
}); | ||
|
||
it("should be null first time page is visited", () => { | ||
cy.getLocalStorage("cookies-accepted").should("equal", null); | ||
}); | ||
|
||
it("should be true after clicking cookies button", () => { | ||
cy.get("#accept-cookies").click(); | ||
cy.getLocalStorage("cookies-accepted").should("equal", "true"); | ||
}); | ||
|
||
it("should be true after reloading", () => { | ||
cy.getLocalStorage("cookies-accepted").then(cookiesAccepted => { | ||
expect(cookiesAccepted).to.equal("true"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
describe("Accept cookies button", () => { | ||
const COOKIES_BUTTON = "#accept-cookies"; | ||
|
||
before(() => { | ||
cy.clearLocalStorageSnapshot(); | ||
}); | ||
|
||
beforeEach(() => { | ||
cy.restoreLocalStorage(); | ||
cy.visit("/"); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.saveLocalStorage(); | ||
}); | ||
|
||
it("should be visible", () => { | ||
cy.get(COOKIES_BUTTON).should("be.visible"); | ||
}); | ||
|
||
it("should not be visible after clicked", () => { | ||
cy.get(COOKIES_BUTTON).click(); | ||
cy.get(COOKIES_BUTTON).should("not.be.visible"); | ||
}); | ||
|
||
it("should not be visible after reloading", () => { | ||
cy.get(COOKIES_BUTTON).should("not.be.visible"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import { userPreferences } from "./origins"; | ||
|
||
export const acceptCookies = () => userPreferences.cookiesAccepted().update(true); | ||
export const acceptCookies = () => { | ||
// save value directly in another localStorage key for an easier assertions example | ||
localStorage.setItem("cookies-accepted", true); | ||
return userPreferences.cookiesAccepted().update(true); | ||
}; | ||
|
||
export const rejectCookies = () => userPreferences.cookiesAccepted().update(false); | ||
export const rejectCookies = () => { | ||
// save value directly in another localStorage key for an easier assertions example | ||
localStorage.setItem("cookies-accepted", false); | ||
return userPreferences.cookiesAccepted().update(false); | ||
}; |