Skip to content

Commit 4e8e5ad

Browse files
author
Edgar Guaman
committed
code-smell: TT-331 Fixing bugs and code-smells
resolving merge conflicts
1 parent 9c2cc05 commit 4e8e5ad

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<div class="table-cell relative">
1818
<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>
1919
<span class="group cursor-pointer absolute w-5 top-20 -right-3">
20-
<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"/>
20+
<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"/>
2121
<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>
2222
</span>
2323
<span class="group cursor-pointer absolute top-20 -right-5">
24-
<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"/>
24+
<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"/>
2525
<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>
2626
</span>
2727
</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)