Skip to content

Commit 1bafbb8

Browse files
author
Edgar Guaman
committed
code-smell: TT-331 Fixing bugs and code-smells
1 parent 61b3874 commit 1bafbb8

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<div class="table-row bg-white border-r border-grey-500 shadow-sm" id="sidebar-wrapper">
33
<div class="table-cell">
44
<div class="relative flex items-center border-b border-grey-500 sidebar-heading">
5-
<img src="assets/img/ioet-logo-without-letters.png" width="50" height="auto" style="padding-top: 0.5rem; padding-left: 1rem;" alt="logo"/>
5+
<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>
88
<div class=" py-8 flex items-center pl-3">
9-
<img src="assets/icons/user.svg" width="40" height="40"/>
9+
<img src="assets/icons/user.svg" alt="user-icon" width="40" height="40"/>
1010
<span class="pl-1">
1111
<h2 class="font-sans text-base font-semibold">{{userName}}</h2>
1212
<p class="font-sans mt-1 text-xs font-medium text-grey dark:text-gray-400">{{userEmail}}</p>
@@ -20,13 +20,12 @@ <h2 class="font-sans text-base font-semibold">{{userName}}</h2>
2020
class="font-sans relative pl-4 py-3 bg-white"
2121
[ngClass]="{active: item.active}"
2222
>
23-
<img src="{{item.icon}}" width="22" height="22" class="absolute"/>
23+
<img src="{{item.icon}}" alt="icon-item" width="22" height="22" class="absolute"/>
2424
<h3 class="font-sans text-base ml-4 pl-3 text-left" >{{ item.text }}</h3>
25-
<!-- <i class="{{ item.icon }} pr-3"></i> {{ item.text }} -->
2625
</a>
2726
<div class="bg-white pt-2 pr-24 absolute bottom-0">
2827
<a class="flex pl-4 mb-4 text-black-dark hover:text-gray-800" href="#">
29-
<img src="assets/icons/signout.svg" width="25" height="25"/>
28+
<img src="assets/icons/signout.svg" alt="signout-icon" width="25" height="25"/>
3029
<span class="font-sans pl-4 font-medium" (click)="logout()">Sign out</span>
3130
</a>
3231
</div>
@@ -35,11 +34,11 @@ <h3 class="font-sans text-base ml-4 pl-3 text-left" >{{ item.text }}</h3>
3534
<div class="table-cell relative">
3635
<span class="absolute cursor-pointer inset-y-0 right-0 min-h-screen w-0.5 hover:z-0 hover:bg-blue-400" (click)="toggleSideBar()"></span>
3736
<span class="group cursor-pointer absolute w-5 top-20 -right-3">
38-
<img src="assets/icons/left-chevron.svg" id="hide-sidebar" (click)="toggleSideBar()" width="20" height="20" class="bg-black-light rounded-full hover:bg-opacity-50 hover:bg-info-light sm:hidden md:block lg:block shadow-sm"/>
37+
<img src="assets/icons/left-chevron.svg" alt="hide-chevron" id="hide-sidebar" (click)="toggleSideBar()" width="20" height="20" class="bg-black-light rounded-full hover:bg-opacity-50 hover:bg-info-light sm:hidden md:block lg:block shadow-sm"/>
3938
<div class="opacity-0 w-12 bg-black text-white text-center text-xs rounded-lg py-2 absolute z-10 group-hover:opacity-100 bottom-full left-1/4 ml-4 -mb-6 px-1 pointer-events-none">Hide</div>
4039
</span>
4140
<span class="group cursor-pointer absolute top-20 -right-5">
42-
<img src="assets/icons/right-chevron.svg" id="show-sidebar" (click)="toggleSideBar()" width="20" height="20" class="bg-black-light rounded-full hover:bg-opacity-50 hover:bg-info-light sm:block md:hidden lg:hidden"/>
41+
<img src="assets/icons/right-chevron.svg" alt="show-chevron" id="show-sidebar" (click)="toggleSideBar()" width="20" height="20" class="bg-black-light rounded-full hover:bg-opacity-50 hover:bg-info-light sm:block md:hidden lg:hidden"/>
4342
<div class="opacity-0 w-12 bg-black text-white text-center text-xs rounded-lg py-2 absolute z-10 group-hover:opacity-100 bottom-full left-1/4 ml-4 -mb-6 px-1 pointer-events-none">Show</div>
4443
</span>
4544
</div>

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ 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-
};
26-
2718
const userInfoServiceStub = {
2819
isAdmin: () => of(true),
2920
};
@@ -83,10 +74,33 @@ describe('SidebarComponent', () => {
8374
});
8475
});
8576

86-
it('uses the Azure service on logout', () => {
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+
101+
it('should use the Azure service on logout', () => {
87102
spyOn(azureAdB2CServiceStubInjected, 'logout');
88103
component.logout();
89104
expect(azureAdB2CServiceStubInjected.logout).toHaveBeenCalled();
90105
});
91-
92106
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class SidebarComponent implements OnInit, OnDestroy {
3232
if (this.azureAdB2CService.isLogin()) {
3333
this.userName = this.azureAdB2CService.getName();
3434
this.userEmail = this.azureAdB2CService.getUserEmail();
35+
this.azureAdB2CService.setTenantId();
3536
}
3637
}
3738

0 commit comments

Comments
 (0)