Skip to content

Commit a808226

Browse files
committed
#18 fix unit-tests and typos
1 parent 05897da commit a808226

16 files changed

+117
-86
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The app will automatically reload if you change anything in the source files.
2626
## Prepare your environment
2727

2828
### Set environment variables
29-
Create file .keys.json from keys.example.ts into environments folder
29+
Create file .keys.json from keys.example.ts into environments folder with the content pinned in our slack channel
3030

3131
### Prepare your environment for vscode
3232
Install the following extensions:

src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
33

4-
import { AzureGuardService } from './guards/azure-guard.service'
4+
import { AzureGuardService } from './guards/azure-guard.service';
55
import { ReportsComponent } from './modules/reports/pages/reports.component';
66
import { TimeClockComponent } from './modules/time-clock/pages/time-clock.component';
77
import { TimeEntriesComponent } from './modules/time-entries/pages/time-entries.component';
@@ -12,7 +12,7 @@ import { LoginComponent } from './modules/login/login.component';
1212

1313
const routes: Routes = [
1414

15-
{ path: '', component: HomeComponent, canActivate:[AzureGuardService],
15+
{ path: '', component: HomeComponent, canActivate: [AzureGuardService],
1616
children: [
1717
{ path: 'reports', component: ReportsComponent },
1818
{ path: 'time-clock', component: TimeClockComponent },

src/app/guards/azure-guard.service.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TestBed, inject } from '@angular/core/testing';
22
import { RouterTestingModule } from '@angular/router/testing';
3-
import { Router } from '@angular/router'
3+
import { Router } from '@angular/router';
44

55
import { AzureAdB2CService } from '../modules/login/services/azure.ad.b2c.service';
66
import { AzureGuardService } from './azure-guard.service';
@@ -29,19 +29,19 @@ describe('AzureGuardService', () => {
2929
expect(service).toBeTruthy();
3030
});
3131

32-
it('should check if is login', () => {
33-
spyOn(azureAdB2CService, 'isLogin').and.returnValue(true)
34-
const isAcitve = service.canActivate();
35-
expect(azureAdB2CService.isLogin).toHaveBeenCalled;
36-
expect(isAcitve).toEqual(true);
32+
it('can activate the route when user is logged-in', () => {
33+
spyOn(azureAdB2CService, 'isLogin').and.returnValue(true);
34+
const canActivate = service.canActivate();
35+
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
36+
expect(canActivate).toEqual(true);
3737
});
3838

39-
it('should check if not is login', inject([Router], (router: Router) => {
40-
spyOn(azureAdB2CService, 'isLogin').and.returnValue(false)
39+
it('can not active the route and is redirected to login if user is not logged-in', inject([Router], (router: Router) => {
40+
spyOn(azureAdB2CService, 'isLogin').and.returnValue(false);
4141
spyOn(router, 'navigate').and.stub();
42-
const isAcitve = service.canActivate();
43-
expect(azureAdB2CService.isLogin).toHaveBeenCalled;
44-
expect(isAcitve).toEqual(false);
42+
const canActivate = service.canActivate();
43+
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
44+
expect(canActivate).toEqual(false);
4545
expect(router.navigate).toHaveBeenCalledWith(['login']);
4646
}));
4747

src/app/guards/azure-guard.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { AzureAdB2CService } from '../modules/login/services/azure.ad.b2c.servic
88
export class AzureGuardService implements CanActivate {
99

1010
constructor(private azureAdB2CService: AzureAdB2CService, private router: Router) { }
11+
1112
canActivate() {
12-
if(this.azureAdB2CService.isLogin()) {
13+
if (this.azureAdB2CService.isLogin()) {
1314
return true;
1415
} else {
1516
this.router.navigate(['login']);
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FormBuilder } from '@angular/forms';
1+
import { FormBuilder, AbstractControl } from '@angular/forms';
22
import { async, TestBed } from '@angular/core/testing';
33

44
import { CreateActivityComponent } from './create-activity.component';
@@ -10,7 +10,7 @@ describe('CreateActivityComponent', () => {
1010
const data = {
1111
name: '',
1212
description: ''
13-
}
13+
};
1414

1515
beforeEach(async(() => {
1616
TestBed.configureTestingModule({
@@ -24,19 +24,28 @@ describe('CreateActivityComponent', () => {
2424
expect(component).toBeTruthy();
2525
});
2626

27-
it('should reset form', () => {
28-
component.onSubmit(data)
29-
expect(component.activityForm.reset()).toHaveBeenCalled
27+
it('should reset form onSubmit', () => {
28+
spyOn(component.activityForm, 'reset');
29+
30+
component.onSubmit(data);
31+
32+
expect(component.activityForm.reset).toHaveBeenCalled();
3033
});
3134

32-
it('should get name', () => {
33-
component.name
34-
expect(component.activityForm.get('name')).toHaveBeenCalled
35+
it('should get name using activityForm', () => {
36+
spyOn(component.activityForm, 'get');
37+
// tslint:disable-next-line:no-unused-expression
38+
component.name;
39+
expect(component.activityForm.get).toHaveBeenCalledWith('name');
3540
});
3641

37-
it('should get description', () => {
38-
component.description
39-
expect(component.activityForm.get('description')).toHaveBeenCalled
42+
it('should get description using activityForm', () => {
43+
spyOn(component.activityForm, 'get');
44+
45+
// tslint:disable-next-line:no-unused-expression
46+
component.description;
47+
48+
expect(component.activityForm.get).toHaveBeenCalledWith('description');
4049
});
4150

4251
});

src/app/modules/activities-management/pages/activities-management.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('ActivitiesManagementComponent', () => {
1616
providers: [ ActivityService, HttpClient, HttpHandler ]
1717
});
1818
component = TestBed.createComponent(ActivitiesManagementComponent).componentInstance;
19-
activityService = TestBed.get(ActivityService);
19+
activityService = TestBed.inject(ActivityService);
2020
spyOn(activityService, 'getActivities').and.returnValue(of(activitiesFromApi));
2121
}));
2222

src/app/modules/home/home.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('HomeComponent', () => {
1919
fixture.detectChanges();
2020
});
2121

22-
it('should create', () => {
22+
it('should be created', () => {
2323
expect(component).toBeTruthy();
2424
});
2525
});

src/app/modules/login/login.component.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
22
import { RouterTestingModule } from '@angular/router/testing';
33
import { AzureAdB2CService } from '../../modules/login/services/azure.ad.b2c.service';
4-
import { of } from 'rxjs'
4+
import { of } from 'rxjs';
55

66
import { LoginComponent } from './login.component';
77
import { Router } from '@angular/router';
@@ -49,18 +49,18 @@ describe('LoginComponent', () => {
4949
expect(component).toBeTruthy();
5050
});
5151

52-
it('should sign up or login with google', inject([Router], (router: Router) => {
52+
it('should sign up or login with google if is not logged-in into the app', inject([Router], (router: Router) => {
5353
spyOn(azureAdB2CService, 'isLogin').and.returnValue(false);
54-
spyOn(azureAdB2CService, 'signIn').and.returnValue(of())
54+
spyOn(azureAdB2CService, 'signIn').and.returnValue(of());
5555
component.login();
56-
expect(azureAdB2CService.signIn).toHaveBeenCalled;
56+
expect(azureAdB2CService.signIn).toHaveBeenCalled();
5757
}));
5858

59-
it('should not sign up or login with google', inject([Router], (router: Router) => {
60-
spyOn(azureAdB2CService, 'isLogin').and.returnValue(true)
59+
it('should not sign-up or login with google if is already logged-in into the app', inject([Router], (router: Router) => {
60+
spyOn(azureAdB2CService, 'isLogin').and.returnValue(true);
6161
spyOn(router, 'navigate').and.stub();
6262
component.login();
63-
expect(azureAdB2CService.isLogin).toHaveBeenCalled;
63+
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
6464
expect(router.navigate).toHaveBeenCalledWith(['']);
6565
}));
6666
});

src/app/modules/login/login.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { AzureAdB2CService } from './services/azure.ad.b2c.service'
2+
import { AzureAdB2CService } from './services/azure.ad.b2c.service';
33
import { Router } from '@angular/router';
44

55
@Component({
@@ -10,10 +10,10 @@ import { Router } from '@angular/router';
1010

1111
export class LoginComponent {
1212

13-
constructor(private azureAdB2CService: AzureAdB2CService, private router:Router) {}
13+
constructor(private azureAdB2CService: AzureAdB2CService, private router: Router) {}
1414

1515
login(): void {
16-
if(this.azureAdB2CService.isLogin()) {
16+
if (this.azureAdB2CService.isLogin()) {
1717
this.router.navigate(['']);
1818
} else {
1919
this.azureAdB2CService.signIn().subscribe(() => {

src/app/modules/login/services/azure.ad.b2c.service.spec.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ describe('AzureAdB2CService', () => {
66
let service: AzureAdB2CService;
77
const msalStub = {
88
loginPopup() {
9-
return {}
9+
return {};
1010
}
11-
}
11+
};
1212

1313
beforeEach(() => {
1414
TestBed.configureTestingModule({
@@ -17,28 +17,28 @@ describe('AzureAdB2CService', () => {
1717
service = TestBed.inject(AzureAdB2CService);
1818
});
1919

20-
it('should create', inject([AzureAdB2CService],
20+
it('should be created', inject([AzureAdB2CService],
2121
( apiService: AzureAdB2CService) => {
2222
expect(apiService).toBeTruthy();
2323
}));
2424

25-
it('should call msal loginPopup', () => {
25+
it('on signIn should call msal loginPopup', () => {
2626
spyOn(UserAgentApplication.prototype, 'loginPopup').and.returnValue((
2727
new Promise((resolve) => {
2828
resolve();
2929
})
30-
))
31-
service.signIn()
32-
expect(UserAgentApplication.prototype.loginPopup).toHaveBeenCalled;
30+
));
31+
service.signIn();
32+
expect(UserAgentApplication.prototype.loginPopup).toHaveBeenCalled();
3333
});
3434

35-
it('should call msal logout', () => {
36-
spyOn(UserAgentApplication.prototype, 'logout').and.returnValue()
37-
service.logout()
38-
expect(UserAgentApplication.prototype.logout).toHaveBeenCalled;
35+
it('on logout should call msal logout', () => {
36+
spyOn(UserAgentApplication.prototype, 'logout').and.returnValue();
37+
service.logout();
38+
expect(UserAgentApplication.prototype.logout).toHaveBeenCalled();
3939
});
4040

41-
it('should get name Account', () => {
41+
it('should get Account name from UserAgentApplication', () => {
4242
const account: Account = {
4343
accountIdentifier: 'abc',
4444
homeAccountIdentifier: 'abc',
@@ -47,15 +47,17 @@ describe('AzureAdB2CService', () => {
4747
idToken: {},
4848
idTokenClaims: {},
4949
sid: 'abc',
50-
environment: "abc"
51-
}
52-
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValues(account)
53-
const name = service.getName()
54-
expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled;
55-
expect(name).toEqual(account.name)
50+
environment: 'abc'
51+
};
52+
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValues(account);
53+
54+
const name = service.getName();
55+
56+
expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled();
57+
expect(name).toEqual(account.name);
5658
});
5759

58-
it('should return true when user is login', () => {
60+
it('isLogin returns true if UserAgentApplication has a defined Account', () => {
5961
const account: Account = {
6062
accountIdentifier: 'abc',
6163
homeAccountIdentifier: 'abc',
@@ -64,19 +66,21 @@ describe('AzureAdB2CService', () => {
6466
idToken: {},
6567
idTokenClaims: {},
6668
sid: 'abc',
67-
environment: "abc"
68-
}
69-
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(account)
70-
const isLogin = service.isLogin()
71-
expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled;
72-
expect(isLogin).toEqual(true)
69+
environment: 'abc'
70+
};
71+
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(account);
72+
73+
const isLogin = service.isLogin();
74+
75+
expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled();
76+
expect(isLogin).toEqual(true);
7377
});
7478

75-
it('should return false when user is not login', () => {
76-
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(null)
77-
const isLogin = service.isLogin()
78-
expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled;
79-
expect(isLogin).toEqual(false)
79+
it('isLogin returns false if UserAgentApplication has a null value for Account', () => {
80+
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(null);
81+
const isLogin = service.isLogin();
82+
expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled();
83+
expect(isLogin).toEqual(false);
8084
});
8185

8286
});

0 commit comments

Comments
 (0)