Skip to content

Commit 0c22fdc

Browse files
committed
test: TT-453 add test to coverage
1 parent 2d108a3 commit 0c22fdc

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

src/app/modules/login/services/login.service.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ describe('LoginService', () => {
119119
});
120120

121121
it('should logout with social angularx-social-login', () => {
122+
spyOn(cookieService, 'deleteAll').and.returnValue();
123+
122124
service.logout();
123-
const cookies = cookieService.getAll();
125+
124126
expect(socialAuthService.signOut).toHaveBeenCalled();
125-
expect(localStorage.length).toEqual(0);
126-
expect(cookies).toEqual({});
127+
expect(localStorage.clear).toHaveBeenCalled();
128+
expect(cookieService.deleteAll).toHaveBeenCalled();
127129
});
128130
});

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('SidebarComponent', () => {
1212
let component: SidebarComponent;
1313
let fixture: ComponentFixture<SidebarComponent>;
1414
let azureAdB2CServiceStubInjected;
15+
let loginServiceStubInjected: LoginService;
1516
let userInfoService: UserInfoService;
1617
let router;
1718
const routes: Routes = [{ path: 'time-clock', component: TimeClockComponent }];
@@ -61,6 +62,7 @@ describe('SidebarComponent', () => {
6162
beforeEach(() => {
6263
fixture = TestBed.createComponent(SidebarComponent);
6364
azureAdB2CServiceStubInjected = TestBed.inject(AzureAdB2CService);
65+
loginServiceStubInjected = TestBed.inject(LoginService);
6466
userInfoService = TestBed.inject(UserInfoService);
6567
component = fixture.componentInstance;
6668
fixture.detectChanges();
@@ -113,4 +115,11 @@ describe('SidebarComponent', () => {
113115
component.logout();
114116
expect(azureAdB2CServiceStubInjected.logout).toHaveBeenCalled();
115117
});
118+
119+
it('should use the Login service on logout Locally', () => {
120+
component.isProduction = false;
121+
spyOn(loginServiceStubInjected, 'logout');
122+
component.logout();
123+
expect(loginServiceStubInjected.logout).toHaveBeenCalled();
124+
});
116125
});

src/app/modules/shared/feature-toggles/filters/feature-filter-provider.service.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ describe('FeatureFilterProvider', () => {
1717
fakeLoginService = new LoginService();
1818
spyOn(fakeUserService, 'getUserEmail').and.returnValue('any-user-email');
1919
spyOn(fakeUserService, 'getUserGroup').and.returnValue('any-user-group');
20+
spyOn(fakeLoginService, 'getUserEmail').and.returnValue('any-user-email');
21+
spyOn(fakeLoginService, 'getUserGroup').and.returnValue('any-user-group');
2022
service = new FeatureFilterProvider(fakeUserService, fakeLoginService);
2123
featureFilterConfiguration = { name: FeatureFilterTypes.TARGETING, parameters: {} };
2224
});
2325

2426
it('filter model type is created based on the filter configuration', () => {
27+
service.isProduction = true;
28+
const filter = service.getFilterFromConfiguration(featureFilterConfiguration);
29+
30+
expect(filter.constructor.name).toBe(TargetingFeatureFilterModel.name);
31+
});
32+
33+
it('filter model type is created based on the filter configuration Locally', () => {
34+
service.isProduction = false;
2535
const filter = service.getFilterFromConfiguration(featureFilterConfiguration);
2636

2737
expect(filter.constructor.name).toBe(TargetingFeatureFilterModel.name);

src/app/modules/shared/feature-toggles/filters/feature-filter-provider.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { environment } from 'src/environments/environment';
1313
})
1414
export class FeatureFilterProvider {
1515
constructor(private userService: AzureAdB2CService, private loginService: LoginService) {}
16+
isProduction = environment.production;
1617

1718
getFilterFromConfiguration(featureFilterConfiguration: FeatureFilterConfiguration): FeatureFilterModel {
1819
const featureName = featureFilterConfiguration.name;
@@ -22,7 +23,7 @@ export class FeatureFilterProvider {
2223
let group: string;
2324
if (this.userService) {
2425
try {
25-
if (environment.production) {
26+
if (this.isProduction) {
2627
username = this.userService.getUserEmail();
2728
group = this.userService.getUserGroup();
2829
}else{

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ describe('ProjectListHoverComponent', () => {
127127
expect(component.activeEntrySubscription.unsubscribe).toHaveBeenCalled();
128128
});
129129

130+
it('should set all parameters on ngOnInit', () => {
131+
spyOn(store, 'dispatch');
132+
spyOn(store, 'pipe').and.returnValue(of([{ id: 'p1', customer: { name: 'customer', description: 'nomatter' }, name: 'xyz' }]));
133+
134+
component.ngOnInit();
135+
136+
expect(component.listRecentProjects.length).toEqual(1);
137+
});
138+
130139
it('sets customer name and project name on setSelectedProject', () => {
131140
spyOn(component.projectsForm, 'setValue');
132141
component.activeEntry = { project_id: 'p1' };

0 commit comments

Comments
 (0)