Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: TT-453 add test to coverage
  • Loading branch information
ararcos committed Dec 23, 2021
commit 0c22fdca377bfe8137917348fe36b84af5e569a3
8 changes: 5 additions & 3 deletions src/app/modules/login/services/login.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ describe('LoginService', () => {
});

it('should logout with social angularx-social-login', () => {
spyOn(cookieService, 'deleteAll').and.returnValue();

service.logout();
const cookies = cookieService.getAll();

expect(socialAuthService.signOut).toHaveBeenCalled();
expect(localStorage.length).toEqual(0);
expect(cookies).toEqual({});
expect(localStorage.clear).toHaveBeenCalled();
expect(cookieService.deleteAll).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('SidebarComponent', () => {
let component: SidebarComponent;
let fixture: ComponentFixture<SidebarComponent>;
let azureAdB2CServiceStubInjected;
let loginServiceStubInjected: LoginService;
let userInfoService: UserInfoService;
let router;
const routes: Routes = [{ path: 'time-clock', component: TimeClockComponent }];
Expand Down Expand Up @@ -61,6 +62,7 @@ describe('SidebarComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(SidebarComponent);
azureAdB2CServiceStubInjected = TestBed.inject(AzureAdB2CService);
loginServiceStubInjected = TestBed.inject(LoginService);
userInfoService = TestBed.inject(UserInfoService);
component = fixture.componentInstance;
fixture.detectChanges();
Expand Down Expand Up @@ -113,4 +115,11 @@ describe('SidebarComponent', () => {
component.logout();
expect(azureAdB2CServiceStubInjected.logout).toHaveBeenCalled();
});

it('should use the Login service on logout Locally', () => {
component.isProduction = false;
spyOn(loginServiceStubInjected, 'logout');
component.logout();
expect(loginServiceStubInjected.logout).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ describe('FeatureFilterProvider', () => {
fakeLoginService = new LoginService();
spyOn(fakeUserService, 'getUserEmail').and.returnValue('any-user-email');
spyOn(fakeUserService, 'getUserGroup').and.returnValue('any-user-group');
spyOn(fakeLoginService, 'getUserEmail').and.returnValue('any-user-email');
spyOn(fakeLoginService, 'getUserGroup').and.returnValue('any-user-group');
service = new FeatureFilterProvider(fakeUserService, fakeLoginService);
featureFilterConfiguration = { name: FeatureFilterTypes.TARGETING, parameters: {} };
});

it('filter model type is created based on the filter configuration', () => {
service.isProduction = true;
const filter = service.getFilterFromConfiguration(featureFilterConfiguration);

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

it('filter model type is created based on the filter configuration Locally', () => {
service.isProduction = false;
const filter = service.getFilterFromConfiguration(featureFilterConfiguration);

expect(filter.constructor.name).toBe(TargetingFeatureFilterModel.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { environment } from 'src/environments/environment';
})
export class FeatureFilterProvider {
constructor(private userService: AzureAdB2CService, private loginService: LoginService) {}
isProduction = environment.production;

getFilterFromConfiguration(featureFilterConfiguration: FeatureFilterConfiguration): FeatureFilterModel {
const featureName = featureFilterConfiguration.name;
Expand All @@ -22,7 +23,7 @@ export class FeatureFilterProvider {
let group: string;
if (this.userService) {
try {
if (environment.production) {
if (this.isProduction) {
username = this.userService.getUserEmail();
group = this.userService.getUserGroup();
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ describe('ProjectListHoverComponent', () => {
expect(component.activeEntrySubscription.unsubscribe).toHaveBeenCalled();
});

it('should set all parameters on ngOnInit', () => {
spyOn(store, 'dispatch');
spyOn(store, 'pipe').and.returnValue(of([{ id: 'p1', customer: { name: 'customer', description: 'nomatter' }, name: 'xyz' }]));

component.ngOnInit();

expect(component.listRecentProjects.length).toEqual(1);
});

it('sets customer name and project name on setSelectedProject', () => {
spyOn(component.projectsForm, 'setValue');
component.activeEntry = { project_id: 'p1' };
Expand Down