Skip to content

Commit 1c97090

Browse files
committed
Updated frontend with E2E test
1 parent 8774dde commit 1c97090

23 files changed

+366
-117
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ script:
4545
- cd frontend
4646
- npm run lint
4747
- npm run test
48+
- npm run e2e
4849
- cd ..
4950
- cd backend
5051
- npm run lint

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ The project involves:
88
* API
99
- Yii2 REST API, Yii2 RBAC, JWT (JSON Web Token), Memcached
1010
* Backend: Staff/Administrator dashboard to manage staffs, users and settings
11-
- Angular 6, Bootstrap 4, JWT (JSON Web Token), Moment.js, Sweet Alert, Underscore.js
11+
- Angular 6, Bootstrap 4, JWT (JSON Web Token), Moment.js, Sweet Alert, Underscore.js, Basic Unit test
1212
* Frontend: User website to support user registration, login and account management
13-
- Angular 6, [@ng-toolkit/universal](https://github.com/maciejtreder/ng-toolkit), Bootstrap 4, JWT (JSON Web Token), Moment.js, Sweet Alert
13+
- Angular 6, [@ng-toolkit/universal](https://github.com/maciejtreder/ng-toolkit), Bootstrap 4, JWT (JSON Web Token), Moment.js, Sweet Alert, Basic Unit & E2E test
1414

1515
**Demo**
1616

@@ -114,6 +114,14 @@ Once all containers are finished compiling, then open the browser.
114114
```
115115
$ docker exec -it api /bin/sh
116116
```
117+
- To run code sniffer, use following command:
118+
```
119+
$ docker exec api composer run sniff
120+
```
121+
- To run unit test, use following command:
122+
```
123+
$ docker exec api composer run test:unit
124+
```
117125
118126
* **Backend - Angular**: [http://localhost/backend](http://localhost/backend)
119127
- Administrator username: `admin`, password: `123456`
@@ -127,7 +135,12 @@ Once all containers are finished compiling, then open the browser.
127135
$ docker exec -it backend /bin/sh
128136
```
129137
- Note that the **live reloading feature has been disabled** due to restriction.
130-
- Please open **Developer Tool** to prevent caching. The changes will be checked every 1s. Please refer `/backend/image-files/usr/local/bin/docker-entrypoint-dev.sh`.
138+
- Please open **Developer Tool** to prevent caching. The changes will be checked every 1s. Please refer `/backend/image-files/usr/local/bin/docker-entrypoint-dev.sh`.
139+
- To run unit test, use following command:
140+
```
141+
$ cd frontend
142+
$ npm run test
143+
```
131144
132145
* **Frontend - Angular**: [http://localhost/frontend](http://localhost/frontend)
133146
- Username: `user`, password `123456`
@@ -141,6 +154,16 @@ Once all containers are finished compiling, then open the browser.
141154
```
142155
- Note that the **live reloading feature has been disabled** due to restriction.
143156
- Please open **Developer Tool** to prevent caching. The changes will be checked every 1s. Please refer `/frontend/image-files/usr/local/bin/docker-entrypoint-dev.sh`.
157+
- To run unit test, use following command:
158+
```
159+
$ cd frontend
160+
$ npm run test
161+
```
162+
- To run E2E test, use following command:
163+
```
164+
$ cd frontend
165+
$ npm run e2e
166+
```
144167
145168
## Files & Folders structures
146169

api/web/index-test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
if (!stristr($remote_address, '127.0.0.1')
2020
&& !stristr($remote_address, '::1')
21-
&& !stristr($remote_address, '172.19')) {
21+
&& !stristr($remote_address, '172.')) {
2222
die('You are not allowed to access this file.');
2323
}
2424

docker-compose.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ services:
5757
- api
5858
networks:
5959
- internal
60-
# volumes:
60+
volumes:
6161
# - ./frontend/image-files/etc/nginx/nginx.conf:/etc/nginx/nginx.conf
6262
# - ./frontend/src:/app/src
6363

@@ -83,9 +83,6 @@ services:
8383
networks:
8484
internal:
8585
driver: bridge
86-
ipam:
87-
config:
88-
- subnet: 172.19.0.0/24
8986

9087
volumes:
9188
mysql_data:

frontend/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ dist
4646
.webpack.json
4747
compiled
4848
dll
49+
50+
output

frontend/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ testem.log
4242
# System Files
4343
.DS_Store
4444
Thumbs.db
45+
46+
output

frontend/e2e/app.e2e-spec.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

frontend/e2e/app.po.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {_} from "underscore";
2+
import {browser} from "protractor";
3+
import {Header} from "../page-object/header.po";
4+
import {IndexPage} from "../page-object/index.po";
5+
import {GlobalPage} from "../page-object/global.po";
6+
7+
describe('Index page', () => {
8+
9+
beforeAll(() => {
10+
IndexPage.navigateTo();
11+
12+
GlobalPage.takeScreenshot('index-page');
13+
});
14+
15+
describe('Header', () => {
16+
it('should display logo', () => {
17+
expect(Header.getLogo().isPresent()).toBe(true)
18+
});
19+
20+
describe('Menu', () => {
21+
_.each(['Home', 'Another Page', 'Sample Page'], menuText => {
22+
it('should display menu `' + menuText + '`', () => {
23+
expect(Header.getMenuByText(menuText).isPresent()).toBe(true);
24+
});
25+
});
26+
27+
it('should set active class for menu `Home`', () => {
28+
expect(Header.getActiveMenu().getText()).toBe('Home');
29+
});
30+
});
31+
32+
describe('Buttons - Before Login', () => {
33+
_.each(['Login', 'Sign up'], menuText => {
34+
it('should display button `' + menuText + '`', () => {
35+
expect(Header.getButtonForBeforeLogin(menuText).isPresent()).toBe(true);
36+
});
37+
});
38+
39+
describe('Click `Login` button', () => {
40+
beforeAll(() => {
41+
IndexPage.navigateTo();
42+
Header.clickLoginButton();
43+
GlobalPage.takeScreenshot('after-click-login-button');
44+
});
45+
46+
it('should go to login page', () => {
47+
expect(browser.getCurrentUrl()).toContain('/login');
48+
});
49+
});
50+
describe('Click `Sign up` button', () => {
51+
beforeAll(() => {
52+
IndexPage.navigateTo();
53+
Header.clickSignUpButton();
54+
GlobalPage.takeScreenshot('after-click-signup');
55+
});
56+
57+
it('should go to login page', () => {
58+
expect(browser.getCurrentUrl()).toContain('/signup');
59+
});
60+
});
61+
});
62+
});
63+
64+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {_} from "underscore";
2+
import {Header} from "../page-object/header.po";
3+
import {LoginPage} from "../page-object/login.po";
4+
import {IndexPage} from "../page-object/index.po";
5+
import {GlobalPage} from "../page-object/global.po";
6+
7+
describe('Login page', () => {
8+
9+
beforeAll(() => {
10+
LoginPage.navigateTo();
11+
12+
GlobalPage.takeScreenshot('login-page');
13+
});
14+
15+
describe('Header', () => {
16+
17+
it('should active button `Login`', () => {
18+
expect(Header.getActiveButtonForBeforeLogin().getText()).toBe('Login');
19+
});
20+
});
21+
22+
describe('Login form', () => {
23+
describe('With non-existing account', () => {
24+
beforeAll(() => {
25+
LoginPage.navigateTo();
26+
LoginPage.fillLoginForm('non-exist-username', 'fake-password');
27+
LoginPage.clickLoginButton();
28+
});
29+
30+
it('should show error message', () => {
31+
expect(LoginPage.getPasswordHelpBlock().getText()).toBe('Incorrect username or password.');
32+
});
33+
});
34+
35+
describe('With existing account', () => {
36+
beforeAll(() => {
37+
LoginPage.navigateTo();
38+
LoginPage.fillLoginForm('user', '123456');
39+
LoginPage.clickLoginButton();
40+
});
41+
42+
it('should redirect to index page', () => {
43+
GlobalPage.takeScreenshot('index-page-after-login');
44+
expect(IndexPage.getPageWrapper().isPresent()).toBe(true);
45+
});
46+
47+
it('should see username', () => {
48+
expect(Header.getTextUsername().getText()).toBe('user (User)');
49+
});
50+
51+
});
52+
});
53+
});

0 commit comments

Comments
 (0)