Skip to content

Commit e198c22

Browse files
author
Edgar Guaman
committed
fix: TT-331 Changes in user and sidebar components
1 parent 1bafbb8 commit e198c22

File tree

6 files changed

+34
-69
lines changed

6 files changed

+34
-69
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
<img src="assets/img/ioet-logo-without-letters.png" alt="ioet-logo" width="50" height="auto" style="padding-top: 0.5rem; padding-left: 1rem;"/>
66
<h1 class="pl-2 pt-2" style="font-family:spinnaker,sans-serif">ioet</h1>
77
</div>
8-
<div class=" py-8 flex items-center pl-3">
9-
<img src="assets/icons/user.svg" alt="user-icon" width="40" height="40"/>
10-
<span class="pl-1">
11-
<h2 class="font-sans text-base font-semibold">{{userName}}</h2>
12-
<p class="font-sans mt-1 text-xs font-medium text-grey dark:text-gray-400">{{userEmail}}</p>
13-
</span>
14-
</div>
8+
<app-user></app-user>
159
<div class="list-group list-group-flush">
1610
<a
1711
*ngFor="let item of itemsSidebar"

src/app/modules/shared/components/sidebar/sidebar.component.spec.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ describe('SidebarComponent', () => {
1515
let router;
1616
const routes: Routes = [{ path: 'time-clock', component: TimeClockComponent }];
1717

18+
const azureAdB2CServiceStub = {
19+
isLogin() {
20+
return true;
21+
},
22+
isAdmin() {
23+
return true;
24+
},
25+
logout(){
26+
return true;
27+
}
28+
};
29+
1830
const userInfoServiceStub = {
1931
isAdmin: () => of(true),
2032
};
@@ -24,7 +36,7 @@ describe('SidebarComponent', () => {
2436
TestBed.configureTestingModule({
2537
declarations: [SidebarComponent],
2638
providers: [
27-
AzureAdB2CService,
39+
{ provide: AzureAdB2CService, useValue: azureAdB2CServiceStub },
2840
{ provide: UserInfoService, useValue: userInfoServiceStub },
2941
],
3042
imports: [RouterTestingModule.withRoutes(routes)],
@@ -41,19 +53,19 @@ describe('SidebarComponent', () => {
4153
fixture.detectChanges();
4254
});
4355

44-
it('should be created', () => {
56+
it('component should be created', () => {
4557
spyOn(azureAdB2CServiceStubInjected, 'isAdmin').and.returnValue(false);
4658
expect(component).toBeTruthy();
4759
});
4860

49-
it('admin users have six menu items', () => {
61+
it('admin users should have six menu items', () => {
5062
component.getSidebarItems().subscribe(() => {
5163
const menuItems = component.itemsSidebar;
5264
expect(menuItems.length).toBe(6);
5365
});
5466
});
5567

56-
it('non admin users have two menu items', () => {
68+
it('non admin users should have two menu items', () => {
5769
spyOn(userInfoServiceStub, 'isAdmin').and.returnValue(of(false));
5870

5971
component.getSidebarItems().subscribe(() => {
@@ -62,7 +74,7 @@ describe('SidebarComponent', () => {
6274
});
6375
});
6476

65-
it('when item is selected is should be set as active and the others as inactive', () => {
77+
it('when item is selected should be set as active and the others as inactive', () => {
6678
const route = 'time-clock';
6779
router.navigate([route]);
6880

@@ -74,30 +86,6 @@ describe('SidebarComponent', () => {
7486
});
7587
});
7688

77-
it('onInit checks if isLogin is true and gets the name, email and sets the tenantid in the Storage', () => {
78-
spyOn(azureAdB2CServiceStubInjected, 'isLogin').and.returnValue(true);
79-
spyOn(azureAdB2CServiceStubInjected, 'getName').and.returnValue('Name');
80-
spyOn(azureAdB2CServiceStubInjected, 'getUserEmail').and.returnValue('Email');
81-
spyOn(azureAdB2CServiceStubInjected, 'setTenantId');
82-
component.ngOnInit();
83-
expect(azureAdB2CServiceStubInjected.isLogin).toHaveBeenCalled();
84-
expect(azureAdB2CServiceStubInjected.getName).toHaveBeenCalled();
85-
expect(azureAdB2CServiceStubInjected.getUserEmail).toHaveBeenCalled();
86-
expect(azureAdB2CServiceStubInjected.setTenantId).toHaveBeenCalled();
87-
});
88-
89-
it('onInit does not get the name and the email if isLogin is false', () => {
90-
spyOn(azureAdB2CServiceStubInjected, 'isLogin').and.returnValue(false);
91-
spyOn(azureAdB2CServiceStubInjected, 'getName').and.returnValue('Name');
92-
spyOn(azureAdB2CServiceStubInjected, 'getUserEmail').and.returnValue('Email');
93-
spyOn(azureAdB2CServiceStubInjected, 'setTenantId');
94-
component.ngOnInit();
95-
expect(azureAdB2CServiceStubInjected.isLogin).toHaveBeenCalled();
96-
expect(azureAdB2CServiceStubInjected.getName).toHaveBeenCalledTimes(0);
97-
expect(azureAdB2CServiceStubInjected.getUserEmail).toHaveBeenCalledTimes(0);
98-
expect(azureAdB2CServiceStubInjected.setTenantId).not.toHaveBeenCalled();
99-
});
100-
10189
it('should use the Azure service on logout', () => {
10290
spyOn(azureAdB2CServiceStubInjected, 'logout');
10391
component.logout();

src/app/modules/shared/components/sidebar/sidebar.component.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service'
1111
styleUrls: ['./sidebar.component.scss'],
1212
})
1313
export class SidebarComponent implements OnInit, OnDestroy {
14-
itemsSidebar: ItemSidebar[];
14+
itemsSidebar: ItemSidebar[] = [];
1515
navStart;
1616
sidebarItems$: Subscription;
17-
userName: string;
18-
userEmail: string;
1917

2018
constructor(private router: Router, private userInfoService: UserInfoService, private azureAdB2CService: AzureAdB2CService) {
2119
this.navStart = this.router.events.pipe(
@@ -29,11 +27,6 @@ export class SidebarComponent implements OnInit, OnDestroy {
2927
this.navStart.subscribe((evt) => {
3028
this.highlightMenuOption(evt.url);
3129
});
32-
if (this.azureAdB2CService.isLogin()) {
33-
this.userName = this.azureAdB2CService.getName();
34-
this.userEmail = this.azureAdB2CService.getUserEmail();
35-
this.azureAdB2CService.setTenantId();
36-
}
3730
}
3831

3932
ngOnDestroy(): void {
@@ -68,7 +61,6 @@ export class SidebarComponent implements OnInit, OnDestroy {
6861
);
6962
}
7063

71-
7264
highlightMenuOption(route) {
7365
this.itemsSidebar.map((item) => (item.active = false));
7466
this.itemsSidebar.filter((item) => item.route === route).map((item) => (item.active = true));
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
<li class="nav-item active dropdown">
2-
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
3-
aria-haspopup="true" aria-expanded="false">
4-
<i class="far fa-user-circle"></i>
5-
{{name}}
6-
</a>
7-
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
8-
<a class="dropdown-item" href="#" (click)="logout()">Sign Out</a>
9-
</div>
10-
</li>
1+
<div class=" py-8 flex items-center pl-3">
2+
<img src="assets/icons/user.svg" alt="user-icon" width="40" height="40"/>
3+
<span class="pl-1">
4+
<h2 class="font-sans text-base font-semibold">{{userName}}</h2>
5+
<p class="font-sans mt-1 text-xs font-medium text-grey dark:text-gray-400">{{userEmail}}</p>
6+
</span>
7+
</div>

src/app/modules/shared/components/user/user.component.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,24 @@ describe('UserComponent', () => {
4040
it('onInit checks if isLogin and gets the name and set tenantIn in the storage', () => {
4141
spyOn(azureAdB2CService, 'isLogin').and.returnValue(true);
4242
spyOn(azureAdB2CService, 'getName').and.returnValue('Name');
43+
spyOn(azureAdB2CService, 'getUserEmail').and.returnValue('Email');
4344
spyOn(azureAdB2CService, 'setTenantId');
4445
component.ngOnInit();
4546
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
4647
expect(azureAdB2CService.getName).toHaveBeenCalled();
48+
expect(azureAdB2CService.getUserEmail).toHaveBeenCalled();
4749
expect(azureAdB2CService.setTenantId).toHaveBeenCalled();
4850
});
4951

5052
it('onInit does not get the name if isLogin false', () => {
5153
spyOn(azureAdB2CService, 'isLogin').and.returnValue(false);
5254
spyOn(azureAdB2CService, 'getName').and.returnValue('Name');
55+
spyOn(azureAdB2CService, 'getUserEmail').and.returnValue('Email');
5356
spyOn(azureAdB2CService, 'setTenantId');
5457
component.ngOnInit();
5558
expect(azureAdB2CService.isLogin).toHaveBeenCalled();
5659
expect(azureAdB2CService.getName).toHaveBeenCalledTimes(0);
60+
expect(azureAdB2CService.getUserEmail).toHaveBeenCalledTimes(0);
5761
expect(azureAdB2CService.setTenantId).not.toHaveBeenCalled();
5862
});
59-
60-
it('uses the Azure service on logout', () => {
61-
spyOn(azureAdB2CService, 'logout');
62-
63-
component.logout();
64-
65-
expect(azureAdB2CService.logout).toHaveBeenCalled();
66-
});
6763
});

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service'
77
styleUrls: ['./user.component.scss'],
88
})
99
export class UserComponent implements OnInit {
10-
name: string;
10+
userName: string;
11+
userEmail: string;
1112

1213
constructor(private azureAdB2CService: AzureAdB2CService) {}
1314

1415
ngOnInit(): void {
1516
if (this.azureAdB2CService.isLogin()) {
16-
this.name = this.azureAdB2CService.getName();
17+
this.userName = this.azureAdB2CService.getName();
18+
this.userEmail = this.azureAdB2CService.getUserEmail();
1719
this.azureAdB2CService.setTenantId();
1820
}
1921
}
20-
21-
logout() {
22-
this.azureAdB2CService.logout();
23-
}
2422
}

0 commit comments

Comments
 (0)