Skip to content

Commit 985cc46

Browse files
authored
Merge pull request #13 from javierbrea/v1.1.1
V1.1.1
2 parents 65b7453 + 2cfd86a commit 985cc46

File tree

42 files changed

+5566
-3359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+5566
-3359
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
# tests
1010
/coverage
11-
/test-acceptance/app/build
12-
/test-acceptance/app/node_modules
13-
/test-acceptance/app/cypress/screenshots
14-
/test-acceptance/app/cypress/fixtures
1511

1612
# misc
1713
.DS_Store

.travis.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cache:
88
- ~/.npm
99
- ~/.cache
1010
- node_modules
11-
- test-acceptance/app/node_modules
11+
- test-e2e/react-app/node_modules
1212
- ~/.sonar/cache
1313

1414
addons:
@@ -25,12 +25,7 @@ addons:
2525
script:
2626
- npm run lint
2727
- npm run test
28-
- cd test-acceptance/app
29-
- npm ci
30-
- npm run cypress:install
31-
- npm run cypress:verify
32-
- npm run test:ci
33-
- cd ../..
28+
- npm run test-e2e:ci
3429
- npm run coveralls
3530
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sonar-scanner; fi'
3631

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Removed
1212
### BREAKING CHANGES
1313

14+
## [1.1.1] - 2019-12-28
15+
### Changed
16+
- Upgrade dependencies.
17+
- Rename acceptance tests into e2e tests.
18+
- Improve documentation examples.
19+
20+
### Added
21+
- Add npm command for running e2e tests.
22+
- Add e2e tests to check that examples works.
23+
1424
## [1.1.0] - 2019-10-27
1525
### Added
1626
- Add getLocalStorage command

README.md

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,77 @@ cy.removeLocalStorage("item");
7676

7777
### Preserving local storage between tests
7878

79-
Use `saveLocalStorage` to save a snapshot of current `localStorage` at the end of one test, and use the `restoreLocalStorage` command to restore it at the beginning of another one:
79+
Use `saveLocalStorage` to save a snapshot of current `localStorage` at the end of one test, and use the `restoreLocalStorage` command to restore it at the beginning of another one. _The usage of `beforeEach` and `afterEach` is recommended for this purpose._
80+
81+
### Examples
82+
83+
#### Cookies button example
84+
85+
Next example shows how this package can be used to test a "cookies button" _(which theoretically set a flag into `localStorage` and can be clicked only once)_
8086

8187
```js
82-
it("should hide privacy policy message on click accept cookies button", () => {
83-
cy.get("#accept-cookies").click();
84-
cy.get("#privacy-policy").should("not.be.visible");
85-
cy.saveLocalStorage();
88+
describe("Accept cookies button", () => {
89+
const COOKIES_BUTTON = "#accept-cookies";
90+
91+
before(() => {
92+
cy.clearLocalStorageSnapshot();
93+
});
94+
95+
beforeEach(() => {
96+
cy.restoreLocalStorage();
97+
cy.visit("/");
98+
});
99+
100+
afterEach(() => {
101+
cy.saveLocalStorage();
102+
});
103+
104+
it("should be visible", () => {
105+
cy.get(COOKIES_BUTTON).should("be.visible");
106+
});
107+
108+
it("should not be visible after clicked", () => {
109+
cy.get(COOKIES_BUTTON).click();
110+
cy.get(COOKIES_BUTTON).should("not.be.visible");
111+
});
112+
113+
it("should not be visible after reloading", () => {
114+
cy.get(COOKIES_BUTTON).should("not.be.visible");
115+
});
86116
});
117+
```
87118

88-
it("should not show privacy policy message after reloading page", () => {
89-
cy.restoreLocalStorage();
90-
cy.reload();
91-
cy.get("#privacy-policy").should("not.be.visible");
119+
> Note the usage of `beforeEach` and `afterEach` for preserving `localStorage` between all tests. Also `clearLocalStorageSnapshot` is used in the `before` statement to avoid possible conflicts with other test files preserving localStorage.
120+
121+
#### localStorage assertions
122+
123+
Based on the previous example, assertions could be added to check values of `localStorage`:
124+
125+
```js
126+
describe("localStorage cookies-accepted item", () => {
127+
beforeEach(() => {
128+
cy.restoreLocalStorage();
129+
cy.visit("/");
130+
});
131+
132+
afterEach(() => {
133+
cy.saveLocalStorage();
134+
});
135+
136+
it("should be null first time page is visited", () => {
137+
cy.getLocalStorage("cookies-accepted").should("equal", null);
138+
});
139+
140+
it("should be true after clicking cookies button", () => {
141+
cy.get("#accept-cookies").click();
142+
cy.getLocalStorage("cookies-accepted").should("equal", "true");
143+
});
144+
145+
it("should be true after reloading", () => {
146+
cy.getLocalStorage("cookies-accepted").then(cookiesAccepted => {
147+
expect(cookiesAccepted).to.equal("true");
148+
});
149+
});
92150
});
93151
```
94152

0 commit comments

Comments
 (0)