Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 10ddcc9

Browse files
committed
Played with karma config and client unit tests
1 parent c1b9788 commit 10ddcc9

File tree

8 files changed

+104
-81
lines changed

8 files changed

+104
-81
lines changed

client/app/main/main.component.spec.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { MaterialModule } from './../../components/material/material.module';
2+
/* tslint:disable no-unused-expression */
3+
14
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
25
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
36
import { expect } from 'chai';
@@ -7,37 +10,43 @@ import { SocketServiceStub } from 'components/socket/socket.mock';
710
import { PageTitleService } from 'components/page-title/page-title.service';
811
import { PageTitleServiceStub } from 'components/page-title/page-title.mock';
912
import { MainComponent } from './main.component';
13+
import { SocketServiceMock } from '../../components/socket/socket.service.mock';
14+
import { AuthServiceMock } from './../../components/auth/auth.service.mock';
15+
import { AuthService } from '../../components/auth/auth.service';
1016

1117
describe('Component: MainComponent', function () {
12-
let comp: MainComponent;
18+
let component: MainComponent;
1319
let fixture: ComponentFixture<MainComponent>;
14-
let httpTestingController: HttpTestingController;
20+
// let httpTestingController: HttpTestingController;
1521
// const mockThings = ['HTML5 Boilerplate', 'AngularJS', 'Karma', 'Express'];
1622

1723
beforeEach(async(() => {
1824
TestBed.configureTestingModule({
19-
imports: [FormsModule, HttpClientTestingModule],
20-
declarations: [MainComponent], // declare the test component
25+
imports: [MaterialModule], // FormsModule, HttpClientTestingModule
26+
declarations: [MainComponent],
2127
providers: [
22-
{ provide: SocketService, useClass: SocketServiceStub },
28+
{ provide: AuthService, useClass: AuthServiceMock },
2329
{ provide: PageTitleService, useClass: PageTitleServiceStub },
2430
],
2531
}).compileComponents();
2632

27-
httpTestingController = TestBed.get(HttpTestingController);
33+
// httpTestingController = TestBed.get(HttpTestingController);
2834
}));
2935

3036
beforeEach(async(() => {
3137
fixture = TestBed.createComponent(MainComponent);
32-
// MainComponent test instance
33-
comp = fixture.componentInstance;
34-
35-
/**
36-
* Trigger initial data binding and run lifecycle hooks
37-
*/
38+
component = fixture.componentInstance;
3839
fixture.detectChanges();
3940
}));
4041

42+
// it('should instantiate', () => {
43+
// expect(component).to.not.be.undefined;
44+
// });
45+
46+
// it('should set the page title to empty', () => {
47+
48+
// });
49+
4150
// it('should attach a list of things to the controller', () => {
4251
// // `GET /api/things` should be made once
4352
// const req = httpTestingController.expectOne('/api/things');

client/app/main/main.component.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { Subscription } from 'rxjs';
3-
import { PageTitleService } from 'components/page-title/page-title.service';
43
import { AuthService } from 'components/auth/auth.service';
4+
import { PageTitleService } from 'components/page-title/page-title.service';
55

66
@Component({
77
selector: 'app-main',
88
template: require('./main.html'),
9-
styles: [require('./main.scss')]
9+
styles: [require('./main.scss')],
1010
})
1111
export class MainComponent implements OnInit, OnDestroy {
12-
private isLoggedIn = false;
12+
private isLoggedIn = false; // used in html
1313
private authInfoSub: Subscription;
1414

15-
static parameters = [PageTitleService, AuthService];
16-
constructor(private pageTitleService: PageTitleService,
17-
private authService: AuthService) {
18-
this.authInfoSub = this.authService.authInfo()
19-
.subscribe(authInfo => {
20-
this.isLoggedIn = authInfo.isLoggedIn();
21-
});
22-
}
15+
static parameters = [AuthService, PageTitleService];
16+
constructor(private authService: AuthService, private pageTitleService: PageTitleService) {}
2317

2418
ngOnInit() {
19+
this.authInfoSub = this.authService.authInfo().subscribe(authInfo => {
20+
this.isLoggedIn = authInfo.isLoggedIn();
21+
});
2522
this.pageTitleService.title = '';
2623
}
2724

client/app/main/main.scss

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,22 @@ hr {
7777
}
7878

7979
.app-info-row {
80-
display: flex;
81-
flex-direction: row;
82-
justify-content: center;
83-
align-items: flex-start;
84-
padding: 15px 0;
80+
display: flex;
81+
flex-direction: row;
82+
justify-content: center;
83+
align-items: flex-start;
84+
padding: 15px 0;
8585
}
8686

8787
.app-info-box {
88-
display: flex;
89-
flex: 1;
90-
text-align: center;
91-
flex-direction: column;
92-
padding: 0 25px;
93-
88+
display: flex;
89+
flex: 1;
90+
text-align: center;
91+
flex-direction: column;
92+
padding: 0 25px;
9493

95-
h4 {
96-
margin: 5px auto;
94+
h4 {
95+
margin: 5px auto;
9796
}
9897
}
9998

@@ -103,64 +102,64 @@ hr {
103102
}
104103

105104
.material-icons {
106-
text-rendering: optimizeLegibility;
107-
-webkit-font-feature-settings: 'liga';
108-
-moz-font-feature-settings: 'liga';
109-
font-feature-settings: 'liga';
110-
font-size: 50px;
105+
text-rendering: optimizeLegibility;
106+
-webkit-font-feature-settings: 'liga';
107+
-moz-font-feature-settings: 'liga';
108+
font-feature-settings: 'liga';
109+
font-size: 50px;
111110
}
112111

113112
.light {
114-
font-weight: 300;
113+
font-weight: 300;
115114
}
116115

117116
.app-main-fair-container {
118-
display: flex;
119-
flex-flow: row wrap;
120-
justify-content: center;
121-
align-items: center;
122-
width: 90%;
123-
margin: 0 auto;
117+
display: flex;
118+
flex-flow: row wrap;
119+
justify-content: center;
120+
align-items: center;
121+
width: 90%;
122+
margin: 0 auto;
124123
}
125124

126125
.app-fair-box {
127-
width: 50%;
128-
margin: 30px auto;
129-
text-align: left;
126+
width: 50%;
127+
margin: 30px auto;
128+
text-align: left;
130129

131-
> img {
132-
width: 70%;
133-
height: 70%;
134-
margin-right: 50px;
135-
float: right;
136-
}
130+
> img {
131+
width: 70%;
132+
height: 70%;
133+
margin-right: 50px;
134+
float: right;
135+
}
137136
}
138137

139138
.app-main-fair-description {
140-
display: flex;
141-
flex-flow: column wrap;
142-
justify-content: flex-start;
143-
align-items: flex-start;
139+
display: flex;
140+
flex-flow: column wrap;
141+
justify-content: flex-start;
142+
align-items: flex-start;
144143

145-
> h2 {
146-
margin-bottom: 10px;
147-
}
144+
> h2 {
145+
margin-bottom: 10px;
146+
}
148147
}
149148

150149
/**
151150
* Rules for when the device is detected to be a small screen.
152151
*/
153152
@media (max-width: 720px) {
154-
.app-header-section {
155-
padding-top: $margin-promotion-sections-small;
156-
}
157-
158-
.app-header-start,
159-
.app-main-bottom-start {
160-
margin: $margin-promotion-sections-small 0;
161-
}
162-
163-
.app-main-row {
164-
margin: $margin-promotion-sections-small 0;
165-
}
153+
.app-header-section {
154+
padding-top: $margin-promotion-sections-small;
155+
}
156+
157+
.app-header-start,
158+
.app-main-bottom-start {
159+
margin: $margin-promotion-sections-small 0;
160+
}
161+
162+
.app-main-row {
163+
margin: $margin-promotion-sections-small 0;
164+
}
166165
}

client/components/activity/activity-sidenav/activity-sidenav.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ export class ActivitySidenavComponent implements OnDestroy, AfterViewInit {
3232

3333
private activityDirection: any;
3434

35-
static parameters = [SecondarySidenavService, ProvenanceService, SocketService, Router];
35+
static parameters = [Router, SecondarySidenavService, ProvenanceService, SocketService];
3636

37-
constructor(private sidenavService: SecondarySidenavService,
37+
constructor(
38+
private router: Router,
39+
private sidenavService: SecondarySidenavService,
3840
private provenanceService: ProvenanceService,
39-
private socketService: SocketService,
40-
private router: Router) {
41+
private socketService: SocketService
42+
) {
4143
this.activityDirectionFilters = values(config.activityDirectionFilters);
4244
this.router.events.pipe(
4345
filter(event => event instanceof NavigationStart)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sinon from 'sinon';
2+
import { of } from 'rxjs';
3+
import { AuthInfo } from './models/auth-info.model';
4+
5+
export class AuthServiceMock {
6+
// authInfo = sinon.fake.returns(of( new AuthInfo(undefined)));
7+
// numNotifications = sinon.spy();
8+
// renderTitle = sinon.spy();
9+
}

client/components/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { UserService } from './user.service';
66
import { TokenService } from './token.service';
77
import { User } from 'models/auth/user.model';
88
import { TokenResponse } from 'models/auth/token-response.model';
9-
import { AuthInfo } from './auth-info.model';
9+
import { AuthInfo } from './models/auth-info.model';
1010

1111
const _loginWithTokenResponse = (authService: AuthService) => pipe(
1212
mergeMap((res: TokenResponse) => {
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sinon from 'sinon';
2+
3+
export class PageTitleServiceMock {
4+
// title = sinon.spy();
5+
// numNotifications = sinon.spy();
6+
renderTitle = sinon.spy();
7+
}

0 commit comments

Comments
 (0)