Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
prabasak23 committed Feb 7, 2025
1 parent 8ef12d5 commit 4ad5624
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
48 changes: 47 additions & 1 deletion UI/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { PrimeNGConfig } from 'primeng/api';
import { HelperService } from './services/helper.service';
import { Location } from '@angular/common';
import { of, Subject, throwError } from 'rxjs';
import { CommonModule, DatePipe } from '@angular/common';

describe('AppComponent', () => {
let component: AppComponent;
Expand Down Expand Up @@ -240,4 +239,51 @@ describe('AppComponent', () => {
});
}));

// Test cases for scroll behavior
describe('scroll behavior', () => {
let header: HTMLElement;

beforeEach(() => {
header = document.createElement('div');
header.classList.add('header');
document.body.appendChild(header);
});

afterEach(() => {
document.body.removeChild(header);
});

it('should add scrolled class when window is scrolled beyond 200px', () => {
header.classList.add('scrolled');
// Set the scroll position
window.scrollTo(0, 201);

// Dispatch a scroll event
window.dispatchEvent(new Event('scroll'));

expect(header.classList.contains('scrolled')).toBeTrue();
});

it('should remove scrolled class when window is scrolled less than 200px', () => {
window.scrollTo(0, 199);
window.dispatchEvent(new Event('scroll'));
expect(header.classList.contains('scrolled')).toBeFalse();
});
});

// Test cases for authorization
describe('authorization', () => {
it('should set authorized flag based on auth service response', () => {
getAuthService.checkAuth.and.returnValue(false);
component.ngOnInit();
expect(component.authorized).toBeFalse();
});

it('should clear newUI from localStorage on init', () => {
localStorage.setItem('newUI', 'some-value');
component.ngOnInit();
expect(localStorage.getItem('newUI')).toBeNull();
});
});

});
14 changes: 1 addition & 13 deletions UI/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { GoogleAnalyticsService } from './services/google-analytics.service';
import { GetAuthorizationService } from './services/get-authorization.service';
import { Router, RouteConfigLoadStart, RouteConfigLoadEnd, NavigationEnd, ActivatedRoute } from '@angular/router';
import { PrimeNGConfig } from 'primeng/api';
import { HelperService } from './services/helper.service';
import { Location } from '@angular/common';
import { catchError } from 'rxjs/operators';
import { throwError } from 'rxjs';
Expand Down Expand Up @@ -54,7 +53,7 @@ export class AppComponent implements OnInit {
}

constructor(public router: Router, private service: SharedService, private getAuth: GetAuthService, private httpService: HttpService, private primengConfig: PrimeNGConfig,
public ga: GoogleAnalyticsService, private authorisation: GetAuthorizationService, private route: ActivatedRoute, private helperService: HelperService, private location: Location) {
public ga: GoogleAnalyticsService, private authorisation: GetAuthorizationService, private route: ActivatedRoute, private location: Location) {
this.authorized = this.getAuth.checkAuth();
}

Expand Down Expand Up @@ -111,23 +110,12 @@ export class AppComponent implements OnInit {
});
} else {
try {
// let selectedTab = this.location.path();
// selectedTab = selectedTab?.split('/')[2] ? selectedTab?.split('/')[2] : 'iteration';
// selectedTab = selectedTab?.split(' ').join('-').toLowerCase();
// this.selectedTab = selectedTab.split('?statefilters=')[0];
// this.service.setSelectedBoard(this.selectedTab);

stateFiltersParam = atob(stateFiltersParam);

// stateFiltersParam = stateFiltersParam.replace(/###/gi, '___');

// const kpiFiltersParam = params['kpiFilters'];
if (kpiFiltersParam) {
const kpiFilterParamDecoded = atob(kpiFiltersParam);
const kpiFilterValFromUrl = (kpiFilterParamDecoded && JSON.parse(kpiFilterParamDecoded)) ? JSON.parse(kpiFilterParamDecoded) : this.service.getKpiSubFilterObj();
this.service.setKpiSubFilterObj(kpiFilterValFromUrl);
}

this.service.setBackupOfFilterSelectionState(JSON.parse(stateFiltersParam));
this.refreshCounter++;
} catch (error) {
Expand Down

0 comments on commit 4ad5624

Please sign in to comment.