Skip to content

Commit 7793111

Browse files
committed
fix: #147 Display correct username
1 parent 4ca6c8e commit 7793111

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/app/modules/shared/components/user/user.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
aria-haspopup="true"
88
aria-expanded="false"
99
>
10-
<i class="far fa-user-circle"></i> Dario Herrera
10+
<i class="far fa-user-circle"></i>
11+
{{name}}
1112
</a>
1213
<div class="dropdown-menu style-click" aria-labelledby="navbarDropdown">
1314
<a class="dropdown-item style-click" (click)="logout()">Sign Out</a>

src/app/modules/time-clock/pages/time-clock.component.spec.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import { ProjectState } from '../../project-management/store/project.reducer';
99
import { ProjectListHoverComponent } from '../components';
1010
import { ProjectService } from '../../project-management/services/project.service';
1111
import { FilterProjectPipe } from '../../shared/pipes';
12+
import {AzureAdB2CService} from '../../login/services/azure.ad.b2c.service';
1213

1314
describe('TimeClockComponent', () => {
1415
let component: TimeClockComponent;
1516
let fixture: ComponentFixture<TimeClockComponent>;
1617
let de: DebugElement;
1718
let store: MockStore<ProjectState>;
1819
let projectService: ProjectService;
20+
let azureAdB2CService: AzureAdB2CService;
1921
const state = {
2022
projects: {
2123
projectList: [{ id: 'id', name: 'name', description: 'description' }],
@@ -32,7 +34,7 @@ describe('TimeClockComponent', () => {
3234
TestBed.configureTestingModule({
3335
imports: [HttpClientTestingModule],
3436
declarations: [TimeClockComponent, ProjectListHoverComponent, FilterProjectPipe],
35-
providers: [ProjectService, provideMockStore({ initialState: state })],
37+
providers: [ProjectService, AzureAdB2CService, provideMockStore({ initialState: state })],
3638
}).compileComponents();
3739
store = TestBed.inject(MockStore);
3840
}));
@@ -43,12 +45,29 @@ describe('TimeClockComponent', () => {
4345
de = fixture.debugElement;
4446
fixture.detectChanges();
4547
projectService = TestBed.inject(ProjectService);
48+
azureAdB2CService = TestBed.inject(AzureAdB2CService);
4649
});
4750

4851
it('should be created', () => {
4952
expect(component).toBeTruthy();
5053
});
5154

55+
it('onInit checks if isLogin and gets the userName', () => {
56+
spyOn(azureAdB2CService, 'isLogin').and.returnValue(true);
57+
spyOn(azureAdB2CService, 'getName').and.returnValue('Name');
58+
component.ngOnInit();
59+
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
60+
expect(azureAdB2CService.getName).toHaveBeenCalled();
61+
});
62+
63+
it('onInit does not get the name if isLogin false', () => {
64+
spyOn(azureAdB2CService, 'isLogin').and.returnValue(false);
65+
spyOn(azureAdB2CService, 'getName').and.returnValue('Name');
66+
component.ngOnInit();
67+
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
68+
expect(azureAdB2CService.getName).toHaveBeenCalledTimes(0);
69+
});
70+
5271
it('Service injected via inject(...) and TestBed.get(...) should be the same instance', inject(
5372
[ProjectService],
5473
(injectService: ProjectService) => {

src/app/modules/time-clock/pages/time-clock.component.ts

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

34
@Component({
45
selector: 'app-time-clock',
@@ -7,7 +8,7 @@ import { Component, OnInit } from '@angular/core';
78
})
89
export class TimeClockComponent implements OnInit {
910
currentDate: Date = new Date();
10-
username = 'Dario';
11+
username: string;
1112
isClockIn: boolean;
1213
isEnterTechnology: boolean;
1314
showAlertEnterTecnology: boolean;
@@ -25,7 +26,7 @@ export class TimeClockComponent implements OnInit {
2526
isClockInEnable = false;
2627
isHidenForm = true;
2728

28-
constructor() {
29+
constructor(private azureAdB2CService: AzureAdB2CService) {
2930
this.isClockIn = true;
3031
this.isEnterTechnology = false;
3132
this.hourCounterRealTime = 0;
@@ -36,7 +37,9 @@ export class TimeClockComponent implements OnInit {
3637
this.seconds = 0;
3738
}
3839

39-
ngOnInit() {}
40+
ngOnInit() {
41+
this.username = this.azureAdB2CService.isLogin() ? this.azureAdB2CService.getName() : '';
42+
}
4043

4144
employeClockIn(): boolean {
4245
this.isClockInEnable = true;

0 commit comments

Comments
 (0)