Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit 97cbeff

Browse files
committed
Add react-app e2e tests
1 parent f50efd2 commit 97cbeff

25 files changed

+549
-271
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ addons:
1717

1818
script:
1919
- npm run lint
20-
- npm run test
21-
- npm run coveralls
20+
#- npm run test
2221
- npm run build
22+
- cd test-e2e/react-app
23+
- npm ci
24+
- npm run cypress:install
25+
- npm run cypress:verify
26+
- npm run test:ci
27+
- cd ../..
28+
- npm run coveralls
2329
- 'if [ -n "$SONAR_TOKEN" ]; then sonar-scanner -Dsonar.login=${SONAR_TOKEN}; fi'
2430

2531
deploy:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe("About section", () => {
2+
const SELECTORS = {
3+
VERSION: "about-version"
4+
};
5+
6+
before(() => {
7+
cy.visit("/");
8+
});
9+
10+
it("should display current version", () => {
11+
cy.findByTestId(SELECTORS.VERSION).should("have.text", "1.2.0");
12+
});
13+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
describe("behaviors and fixtures", () => {
2+
const SELECTORS = {
3+
BEHAVIORS_COLLECTION_ITEM: ".behaviors-collection-item",
4+
FIXTURES_COLLECTION_ITEM: ".fixtures-collection-item",
5+
CURRENT_BEHAVIOR: "current-behavior-name",
6+
CURRENT_FIXTURE: "current-fixture-id",
7+
SET_BEHAVIOR_BASE: "set-behavior-base",
8+
SET_BEHAVIOR_USER2: "set-behavior-user2"
9+
};
10+
11+
before(() => {
12+
cy.visit("/");
13+
});
14+
15+
it("should display behaviors collection", () => {
16+
cy.get(SELECTORS.BEHAVIORS_COLLECTION_ITEM).should("have.length", 2);
17+
});
18+
19+
it("should display fixtures collection", () => {
20+
cy.get(SELECTORS.FIXTURES_COLLECTION_ITEM).should("have.length", 2);
21+
});
22+
23+
describe("when behavior is base", () => {
24+
before(() => {
25+
cy.findByTestId(SELECTORS.SET_BEHAVIOR_BASE).click();
26+
});
27+
28+
it("should display current behavior", () => {
29+
cy.findByTestId(SELECTORS.CURRENT_BEHAVIOR).should("have.text", "base");
30+
});
31+
32+
it("should display current fixture", () => {
33+
cy.findByTestId(SELECTORS.CURRENT_FIXTURE).should(
34+
"have.text",
35+
"0afdbb7f0ac441e56eae9401501e4a4b"
36+
);
37+
});
38+
});
39+
40+
describe("when behavior is user2", () => {
41+
before(() => {
42+
cy.findByTestId(SELECTORS.SET_BEHAVIOR_USER2).click();
43+
});
44+
45+
it("should display current behavior", () => {
46+
cy.findByTestId(SELECTORS.CURRENT_BEHAVIOR).should("have.text", "user2");
47+
});
48+
49+
it("should display current fixture", () => {
50+
cy.findByTestId(SELECTORS.CURRENT_FIXTURE).should(
51+
"have.text",
52+
"d765f4ee07c59692b6a517143f756ecd"
53+
);
54+
});
55+
});
56+
});

test-e2e/react-app/cypress/integration/cookies.js

Lines changed: 0 additions & 130 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
describe("Settings section", () => {
2+
const SELECTORS = {
3+
PATH: "settings-path",
4+
DELAY: "settings-delay"
5+
};
6+
7+
before(() => {
8+
cy.visit("/");
9+
});
10+
11+
it("should display current path", () => {
12+
cy.findByTestId(SELECTORS.PATH).should("have.text", "mocks");
13+
});
14+
15+
it("should display current delay", () => {
16+
cy.findByTestId(SELECTORS.DELAY).should("have.text", "0");
17+
});
18+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "@testing-library/cypress/add-commands";

test-e2e/react-app/mocks/behaviors.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const { Behavior } = require("@mocks-server/main");
22

3-
const { getUser } = require("./fixtures");
3+
const { getUser, getUser2 } = require("./fixtures");
44

55
const base = new Behavior([getUser]);
6+
const user2 = new Behavior([getUser2]);
67

78
module.exports = {
8-
base
9+
base,
10+
user2
911
};

test-e2e/react-app/mocks/fixtures.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ const getUser = {
77
}
88
};
99

10+
const getUser2 = {
11+
url: "/api/user",
12+
method: "GET",
13+
response: {
14+
status: 200,
15+
body: [{ email: "foo2@foo2.com" }]
16+
}
17+
};
18+
1019
module.exports = {
11-
getUser
20+
getUser,
21+
getUser2
1222
};

0 commit comments

Comments
 (0)