Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit e06a09c

Browse files
authored
Update client dependencies (#52)
* Update angular version * Fix lint errors * Test users component * Test user effects
1 parent 9a7a1a7 commit e06a09c

23 files changed

+182
-104
lines changed

client/.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# compiled output
44
/dist
55
/tmp
6+
/out-tsc
67

78
# dependencies
89
/node_modules
@@ -26,7 +27,7 @@
2627
# misc
2728
/.sass-cache
2829
/connect.lock
29-
/coverage/*
30+
/coverage
3031
/libpeerconnection.log
3132
npm-debug.log
3233
testem.log
@@ -36,6 +37,6 @@ testem.log
3637
/e2e/*.js
3738
/e2e/*.map
3839

39-
#System Files
40+
# System Files
4041
.DS_Store
4142
Thumbs.db

client/e2e/tsconfig.e2e.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
{
2+
"extends": "../tsconfig.json",
23
"compilerOptions": {
3-
"sourceMap": true,
4-
"declaration": false,
5-
"moduleResolution": "node",
6-
"emitDecoratorMetadata": true,
7-
"experimentalDecorators": true,
8-
"lib": [
9-
"es2016"
10-
],
11-
"outDir": "../dist/out-tsc-e2e",
4+
"outDir": "../out-tsc/e2e",
125
"module": "commonjs",
13-
"target": "es6",
6+
"target": "es5",
147
"types":[
158
"jasmine",
169
"node"

client/package.json

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,29 @@
1313
},
1414
"private": false,
1515
"dependencies": {
16-
"@angular/common": "^2.4.0",
17-
"@angular/compiler": "^2.4.0",
18-
"@angular/core": "^2.4.0",
19-
"@angular/forms": "^2.4.0",
20-
"@angular/http": "^2.4.0",
21-
"@angular/material": "^2.0.0-beta.2",
22-
"@angular/platform-browser": "^2.4.0",
23-
"@angular/platform-browser-dynamic": "^2.4.0",
24-
"@angular/router": "^3.4.0",
16+
"@angular/animations": "^4.1.1",
17+
"@angular/common": "^4.0.0",
18+
"@angular/compiler": "^4.0.0",
19+
"@angular/core": "^4.0.0",
20+
"@angular/forms": "^4.0.0",
21+
"@angular/http": "^4.0.0",
22+
"@angular/material": "^2.0.0-beta.3",
23+
"@angular/platform-browser": "^4.0.0",
24+
"@angular/platform-browser-dynamic": "^4.0.0",
25+
"@angular/router": "^4.0.0",
2526
"@ngrx/core": "^1.2.0",
26-
"@ngrx/effects": "^2.0.0",
27-
"@ngrx/store": "^2.2.1",
27+
"@ngrx/effects": "^2.0.3",
28+
"@ngrx/store": "^2.2.2",
2829
"core-js": "^2.4.1",
2930
"hammerjs": "^2.0.8",
30-
"reselect": "^2.5.4",
31+
"reselect": "^3.0.0",
3132
"rxjs": "^5.1.0",
32-
"zone.js": "^0.7.6"
33+
"zone.js": "^0.8.4"
3334
},
3435
"devDependencies": {
35-
"@angular/cli": "1.0.0-rc.0",
36-
"@angular/compiler-cli": "^2.4.0",
37-
"@ngrx/store-devtools": "^3.2.3",
36+
"@angular/cli": "1.0.2",
37+
"@angular/compiler-cli": "^4.0.0",
38+
"@ngrx/store-devtools": "^3.2.4",
3839
"@types/hammerjs": "^2.0.34",
3940
"@types/jasmine": "2.5.38",
4041
"@types/node": "~6.0.60",
@@ -49,9 +50,9 @@
4950
"karma-jasmine-html-reporter": "^0.2.2",
5051
"ngrx-store-freeze": "^0.1.9",
5152
"protractor": "~5.1.0",
52-
"sw-precache": "^5.0.0",
53+
"sw-precache": "^5.1.1",
5354
"ts-node": "~2.0.0",
54-
"tslint": "~4.4.2",
55-
"typescript": "~2.0.0"
55+
"tslint": "~4.5.0",
56+
"typescript": "~2.2.0"
5657
}
5758
}

client/src/app/actions/user.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { Action } from '@ngrx/store';
22
import { User } from '../models/user';
3-
import { type } from '../util';
43

5-
export const ActionTypes = {
6-
LOAD_USER: type('[User] Load User'),
7-
LOAD_USER_SUCCESS: type('[User] Load User Success'),
8-
};
4+
export const LOAD_USER = '[User] Load User';
5+
export const LOAD_USER_SUCCESS = '[User] Load User Success';
96

107
export class LoadUserAction implements Action {
11-
type = ActionTypes.LOAD_USER;
8+
readonly type = LOAD_USER;
129

1310
constructor() { }
1411
}
1512

1613
export class LoadUserSuccessAction implements Action {
17-
type = ActionTypes.LOAD_USER_SUCCESS;
14+
readonly type = LOAD_USER_SUCCESS;
1815

1916
constructor(public payload: User[]) { }
2017
}

client/src/app/app.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ import { Component } from '@angular/core';
88
styles: [``]
99
})
1010
export class AppComponent {
11-
title = 'app works!';
1211
}

client/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { StoreModule } from '@ngrx/store';
88
import { EffectsModule } from '@ngrx/effects';
99
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
1010
import { MaterialModule } from '@angular/material';
11+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
1112

1213
import { reducer } from './reducers';
1314
import { AppRoutingModule } from './app-routing.module';
@@ -30,6 +31,7 @@ import { UserService } from './services/user.service';
3031
HttpModule,
3132
AppRoutingModule,
3233
MaterialModule,
34+
BrowserAnimationsModule,
3335
StoreModule.provideStore(reducer),
3436
StoreDevtoolsModule.instrumentOnlyWithExtension(),
3537
EffectsModule.run(UserEffects),

client/src/app/components/users/users.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<md-card class="example-card" *ngFor="let user of user$ | async">
22
<md-card-header>
33
<div md-card-avatar class="example-header-image"></div>
4-
<md-card-title>{{user.username}}</md-card-title>
5-
<md-card-subtitle>{{user.email}}</md-card-subtitle>
4+
<md-card-title>{{ user.username }}</md-card-title>
5+
<md-card-subtitle>{{ user.email }}</md-card-subtitle>
66
</md-card-header>
77
<img md-card-image src="assets/person-icon.png">
88
<md-card-content>
9-
<p>{{user.url}}</p>
9+
<p>{{ user.url }}</p>
1010
</md-card-content>
1111
<md-card-actions>
1212
<button md-button>SHARE</button>
Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/* tslint:disable:no-unused-variable */
1+
import 'hammerjs';
2+
import { NO_ERRORS_SCHEMA } from '@angular/core';
23
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
34
import { By } from '@angular/platform-browser';
45
import { DebugElement } from '@angular/core';
6+
import { Observable } from 'rxjs/Observable';
57
import { MaterialModule } from '@angular/material';
68
import { reducer } from '../../reducers';
79
import { StoreModule } from '@ngrx/store';
@@ -11,25 +13,63 @@ import { UsersComponent } from './users.component';
1113
describe('UsersComponent', () => {
1214
let component: UsersComponent;
1315
let fixture: ComponentFixture<UsersComponent>;
16+
let debugs: DebugElement[];
17+
let element: HTMLElement;
18+
const users: any = Observable.of([{
19+
url: 'http://localhost/nirgalon',
20+
username: 'Nir Galon',
21+
22+
groups: ['admin']
23+
}, {
24+
url: 'http://localhost/adisaar',
25+
username: 'Adi Saar',
26+
email: '',
27+
groups: ['users']
28+
}]);
1429

1530
beforeEach(async(() => {
1631
TestBed.configureTestingModule({
1732
imports: [
18-
MaterialModule.forRoot(),
33+
MaterialModule,
1934
StoreModule.provideStore(reducer)
2035
],
21-
declarations: [ UsersComponent ]
36+
declarations: [ UsersComponent ],
37+
schemas: [ NO_ERRORS_SCHEMA ]
2238
})
2339
.compileComponents();
2440
}));
2541

2642
beforeEach(() => {
2743
fixture = TestBed.createComponent(UsersComponent);
2844
component = fixture.componentInstance;
45+
46+
// Create a dummy transaction.
47+
component.user$ = users;
2948
fixture.detectChanges();
3049
});
3150

3251
it('should create', () => {
3352
expect(component).toBeTruthy();
3453
});
54+
55+
it('should display first user email', () => {
56+
element = fixture.debugElement.query(By.css('md-card-subtitle')).nativeElement;
57+
expect(element.textContent).toContain('[email protected]');
58+
});
59+
60+
it('should display users name', () => {
61+
debugs = fixture.debugElement.queryAll(By.css('md-card-title'));
62+
debugs.forEach((elem, index) => {
63+
element = elem.nativeElement;
64+
expect(element.textContent).toContain(users.value[index].username);
65+
});
66+
});
67+
68+
it('should display the users url links', () => {
69+
debugs = fixture.debugElement.queryAll(By.css('md-card-content > p'));
70+
debugs.forEach((elem, index) => {
71+
element = elem.nativeElement;
72+
expect(element.textContent).toContain(users.value[index].url);
73+
});
74+
});
3575
});

client/src/app/components/users/users.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { User } from '../../models/user';
1212
styleUrls: ['./users.component.scss']
1313
})
1414
export class UsersComponent implements OnInit {
15-
private user$: Observable<User[]>;
15+
public user$: Observable<User[]>;
1616

1717
constructor(
1818
private store: Store<fromRoot.State>,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { TestBed, async, inject } from '@angular/core/testing';
2+
import { EffectsTestingModule, EffectsRunner } from '@ngrx/effects/testing';
3+
4+
import { UserEffects } from './user';
5+
import { UserService } from '../services/user.service';
6+
import * as userAction from '../actions/user';
7+
8+
describe('UsersEffects', () => {
9+
const userServiceStub = {};
10+
let runner: EffectsRunner;
11+
let userEffects: UserEffects;
12+
13+
beforeEach(() => {
14+
TestBed.configureTestingModule({
15+
imports: [
16+
EffectsTestingModule,
17+
],
18+
providers: [
19+
{ provide: UserService, useValue: userServiceStub },
20+
UserEffects,
21+
]
22+
});
23+
});
24+
25+
beforeEach(inject([
26+
EffectsRunner, UserEffects
27+
],
28+
(_runner, _userEffects) => {
29+
runner = _runner;
30+
userEffects = _userEffects;
31+
}
32+
));
33+
34+
it('should create the service', inject([UserEffects], (service: UserEffects) => {
35+
expect(service).toBeTruthy();
36+
}));
37+
38+
it('should return a LOAD_USER_SUCCESS action after LOAD_USER', () => {
39+
runner.queue({ type: 'LOAD_USER' });
40+
41+
userEffects.loadUser$.subscribe(result => {
42+
expect(result).toEqual({ type: 'LOAD_USER_SUCCESS' });
43+
});
44+
});
45+
});

0 commit comments

Comments
 (0)