Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dts 42293 urlshortening gp #1857

Merged
merged 45 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5d1b41d
DTS-42293:urlShortening
gipathak Dec 19, 2024
6007de9
DTS-42293:urlshortening.
gipathak Jan 3, 2025
996c377
DTS-42293:String shortening.
gipathak Jan 9, 2025
18b4195
DTS-42293:String shortening.
gipathak Jan 13, 2025
8d3c3d9
DTS-42293:String shortening.
gipathak Jan 13, 2025
8a3cbbb
DTS-42293:String shortening.
gipathak Jan 22, 2025
c5146a4
DTS-42293:String shortening.
gipathak Jan 22, 2025
2cc8c2b
Merge branch 'develop' into feature/DTS-42293-urlshortening-GP
prabasak23 Jan 22, 2025
6cf49f5
copied url is shortened, redirecting short url to long url is pending
prabasak23 Jan 23, 2025
1dc0e62
Merge branch 'develop' of https://github.com/PublicisSapient/PSknowHO…
gipathak Jan 27, 2025
7d08682
DTS-42293:Test case coverage fix.
gipathak Jan 28, 2025
94b845c
Merge branch 'feature/DTS-42293-urlshortening-GP' of https://github.c…
prabasak23 Jan 29, 2025
a01f9a9
DTS-42293:Test case coverage fix.
gipathak Jan 29, 2025
107f221
Merge branch 'feature/DTS-42293-urlshortening-GP' of https://github.c…
prabasak23 Jan 30, 2025
5b8a11b
short to long url redirection, logged in and logged out users
prabasak23 Jan 30, 2025
f21fb3f
Update app.component.ts
prabasak23 Jan 31, 2025
8d2198b
Merge branch 'develop' into feature/DTS-42293-urlshortening-GP
prabasak23 Jan 31, 2025
9cae86f
for logged in user, no project access redirect to error page
prabasak23 Feb 2, 2025
092a750
Update shared.service.ts
prabasak23 Feb 2, 2025
b608503
unit test case handle
prabasak23 Feb 2, 2025
45929e8
DTS-42293:added edge cases
gipathak Feb 3, 2025
4133857
DTS-42293:added edge cases
gipathak Feb 3, 2025
f607eeb
Update app.component.ts
prabasak23 Feb 4, 2025
a7008f2
unit test update, latest response changes
prabasak23 Feb 4, 2025
ef404c1
update filter
prabasak23 Feb 4, 2025
4c8b42c
unit test cases
prabasak23 Feb 4, 2025
f37303b
handling bugs and sonar issues
prabasak23 Feb 4, 2025
4f1d4c0
unit test case, sonar issues
prabasak23 Feb 5, 2025
7544a19
Update app.component.ts
prabasak23 Feb 5, 2025
d927d63
DTS-42293:corrected wrong commit
gipathak Feb 5, 2025
2d8d26b
Merge branch 'develop' into feature/DTS-42293-urlshortening-GP
prabasak23 Feb 5, 2025
98400d0
central login flow - dev test
prabasak23 Feb 5, 2025
f833853
Update app-initializer.service.ts
prabasak23 Feb 5, 2025
6361622
Update app-initializer.service.ts
prabasak23 Feb 5, 2025
7247857
debugging
prabasak23 Feb 5, 2025
12498a6
Update app-initializer.service.ts
prabasak23 Feb 5, 2025
c128230
debugging contd
prabasak23 Feb 5, 2025
734722a
debugging contd
prabasak23 Feb 5, 2025
0cfd7f1
debugging contd..
prabasak23 Feb 5, 2025
bcadb93
debugging contd
prabasak23 Feb 5, 2025
6ca124a
Update app.component.ts
prabasak23 Feb 6, 2025
da84cd3
Merge branch 'develop' of https://github.com/PublicisSapient/PSknowHO…
prabasak23 Feb 6, 2025
4f917a9
Update app-initializer.service.ts
prabasak23 Feb 6, 2025
8ef12d5
url shortening shareable with invalid url redirection and filter rete…
prabasak23 Feb 6, 2025
4ad5624
code clean up
prabasak23 Feb 7, 2025
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
154 changes: 83 additions & 71 deletions UI/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { SharedService } from './services/shared.service';
import { GetAuthService } from './services/getauth.service';
Expand All @@ -9,8 +9,7 @@ import { Router, ActivatedRoute, NavigationEnd, RouteConfigLoadEnd, RouteConfigL
import { PrimeNGConfig } from 'primeng/api';
import { HelperService } from './services/helper.service';
import { Location } from '@angular/common';
import { of, Subject } from 'rxjs';
import { CommonModule, DatePipe } from '@angular/common';
import { of, Subject, throwError } from 'rxjs';

describe('AppComponent', () => {
let component: AppComponent;
Expand Down Expand Up @@ -40,7 +39,7 @@ describe('AppComponent', () => {
]);

getAuthServiceMock = jasmine.createSpyObj('GetAuthService', ['checkAuth']);
const httpServiceMock = jasmine.createSpyObj('HttpService', [], { currentVersion: '1.0.0' });
const httpServiceMock = jasmine.createSpyObj('HttpService', ['handleRestoreUrl'], { currentVersion: '1.0.0' });
const googleAnalyticsServiceMock = jasmine.createSpyObj('GoogleAnalyticsService', ['setPageLoad']);
const getAuthorizationServiceMock = jasmine.createSpyObj('GetAuthorizationService', ['getRole']);
const helperServiceMock = jasmine.createSpyObj('HelperService', ['setBackupOfUrlFilters']);
Expand Down Expand Up @@ -159,11 +158,6 @@ describe('AppComponent', () => {
});
});

xit('should decode and set state filters from URL hash', () => {
component.ngOnInit();
expect(sharedService.setBackupOfUrlFilters).toHaveBeenCalledWith('SomeEncodedData');
});

it('should navigate to dashboard if no shared link exists', () => {
localStorage.removeItem('shared_link');

Expand All @@ -172,50 +166,6 @@ describe('AppComponent', () => {
expect(router.navigate).toHaveBeenCalledWith(['./dashboard/']);
});

xit('should navigate to error page if user lacks project access', () => {
const validStateFilters = btoa(JSON.stringify({ primary_level: [{ basicProjectConfigId: '123' }] }));
localStorage.setItem('shared_link', `http://example.com?stateFilters=${validStateFilters}`);
localStorage.setItem(
'currentUserDetails',
JSON.stringify({
projectsAccess: [
{
projects: [{ projectId: '456' }],
},
],
authorities: ['ROLE_SUPERADMIN']
})
);

component.ngOnInit();

expect(router.navigate).toHaveBeenCalledWith(['/dashboard/Error']);
/* expect(sharedService.raiseError).toHaveBeenCalledWith({
status: 901,
message: 'No project access.',
}); */
});

xit('should navigate to shared link if user has access to all projects', () => {
const validStateFilters = btoa(JSON.stringify({ primary_level: [{ basicProjectConfigId: '123' }] }));
localStorage.setItem('shared_link', `http://example.com?stateFilters=${validStateFilters}`);
localStorage.setItem(
'currentUserDetails',
JSON.stringify({
projectsAccess: [
{
projects: [{ basicProjectConfigId: '123' }],
},
],
authorities: ['ROLE_SUPERADMIN']
})
);

component.ngOnInit();

expect(router.navigate).toHaveBeenCalledWith([`http://example.com?stateFilters=${validStateFilters}`]);
});

it('should initialize component correctly and call ngOnInit', () => {
// const routerSpy = spyOn(router, 'navigate');
// const getAuthSpy = spyOn(getAuthService, 'checkAuth').and.returnValue(true);
Expand All @@ -242,36 +192,98 @@ describe('AppComponent', () => {
expect(header.classList.contains('scrolled')).toBeFalse();
});

xit('should decode stateFilters and set backup filter state', () => {
const mockParam = btoa(JSON.stringify({ primary_level: [{ labelName: 'Test', nodeId: 'node-1' }] }));
localStorage.setItem('shared_link', `http://example.com/?stateFilters=${mockParam}`);
// const serviceSpy = spyOn(sharedService, 'setBackupOfFilterSelectionState');
it('should navigate to default dashboard if no shared link is found', () => {
localStorage.removeItem('shared_link');
// const routerSpy = spyOn(router, 'navigate');

component.ngOnInit();

expect(sharedServiceMock.setBackupOfFilterSelectionState).toHaveBeenCalledWith({ primary_level: [{ labelName: 'Test', nodeId: 'node-1' }] });
expect(routerMock.navigate).toHaveBeenCalledWith(['./dashboard/']);
});

xit('should handle invalid URL and redirect to error page', () => {
const invalidParam = '12asdasd213131';
localStorage.setItem('shared_link', `http://example.com/?stateFilters=${invalidParam}`);
it('should navigate to the provided URL if the user has access to all projects', fakeAsync(() => {
const decodedStateFilters = JSON.stringify({
parent_level: { basicProjectConfigId: 'project1', labelName: 'Project' },
primary_level: []
});
const currentUserProjectAccess = [{ projectId: 'project1' }];
const url = 'http://example.com';

spyOn(component, 'urlRedirection').and.callThrough();

component.ngOnInit();
component.urlRedirection(decodedStateFilters, currentUserProjectAccess, url, true);

tick();
expect(component.urlRedirection).toHaveBeenCalledWith(decodedStateFilters, currentUserProjectAccess, url, true);
expect(router.navigate).toHaveBeenCalledWith([url]);
}));

expect(routerMock.navigate).toHaveBeenCalledWith(['/dashboard/Error']);
it('should navigate to the error page if the user does not have access to the project', fakeAsync(() => {
const decodedStateFilters = JSON.stringify({
parent_level: { basicProjectConfigId: 'project1', labelName: 'Project' },
primary_level: []
});
const currentUserProjectAccess = [{ projectId: 'project2' }];
const url = 'http://example.com';

spyOn(component, 'urlRedirection').and.callThrough();

component.urlRedirection(decodedStateFilters, currentUserProjectAccess, url, false);

tick();
expect(component.urlRedirection).toHaveBeenCalledWith(decodedStateFilters, currentUserProjectAccess, url, false);
expect(router.navigate).toHaveBeenCalledWith(['/dashboard/Error']);
expect(sharedServiceMock.raiseError).toHaveBeenCalledWith({
status: 900,
message: 'Invalid URL.',
status: 901,
message: 'No project access.'
});
});
}));

it('should navigate to default dashboard if no shared link is found', () => {
localStorage.removeItem('shared_link');
// const routerSpy = spyOn(router, 'navigate');
// Test cases for scroll behavior
describe('scroll behavior', () => {
let header: HTMLElement;

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

expect(routerMock.navigate).toHaveBeenCalledWith(['./dashboard/']);
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();
});
});

});
Loading