From 3ad9acb8330e808e4a98defc99def7938b3a887e Mon Sep 17 00:00:00 2001 From: Mohammed farhan K Date: Sat, 1 Feb 2025 17:51:54 +0530 Subject: [PATCH 1/5] intial commit --- .../delegated-acc-message.component.html | 5 +++- .../delegated-acc-message.component.ts | 27 ++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html index a9f0091fa4..0b3b0e4522 100644 --- a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html +++ b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html @@ -1 +1,4 @@ - You're now managing {{ delegateeName | ellipsis: 15 }}'s account + + You're now managing {{ delegateeName | ellipsis : 15 }}'s account + Switch back + diff --git a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts index e28de51ce3..6216d69911 100644 --- a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts +++ b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts @@ -1,6 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, EventEmitter } from '@angular/core'; import { AuthService } from '../../../core/services/auth.service'; -import { from } from 'rxjs'; +import { from, concat } from 'rxjs'; +import { shareReplay } from 'rxjs/operators'; +import { Router } from '@angular/router'; +import { NetworkService } from '../../../core/services/network.service'; @Component({ selector: 'app-delegated-acc-message', @@ -8,13 +11,29 @@ import { from } from 'rxjs'; styleUrls: ['./delegated-acc-message.component.scss'], }) export class DelegatedAccMessageComponent implements OnInit { - delegateeName; + delegateeName: string; + isConnected$: any; - constructor(private authService: AuthService) {} + constructor(private authService: AuthService, private router: Router, private networkService: NetworkService) {} ngOnInit() { from(this.authService.getEou()).subscribe((res) => { this.delegateeName = res.us.full_name; }); + this.setupNetworkWatcher(); + } + + setupNetworkWatcher(): void { + const networkWatcherEmitter = this.networkService.connectivityWatcher(new EventEmitter()); + this.isConnected$ = concat(this.networkService.isOnline(), networkWatcherEmitter.asObservable()).pipe( + shareReplay(1) + ); + } + + switchBack() { + if (!this.isConnected$) { + return; + } + this.router.navigate(['/', 'enterprise', 'delegated_accounts', { switchToOwn: true }]); } } From 76a91e8d87f7b5101ec9816a181eb1f3509fb01c Mon Sep 17 00:00:00 2001 From: Mohammed farhan K Date: Sat, 1 Feb 2025 18:08:11 +0530 Subject: [PATCH 2/5] test fix --- .../delegated-acc-message.component.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.spec.ts b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.spec.ts index 5d03a5f91f..8d716522ab 100644 --- a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.spec.ts +++ b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.spec.ts @@ -1,10 +1,11 @@ -import { ComponentFixture, TestBed, async, fakeAsync, flush, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { IonicModule } from '@ionic/angular'; import { DelegatedAccMessageComponent } from './delegated-acc-message.component'; import { AuthService } from 'src/app/core/services/auth.service'; import { EllipsisPipe } from '../../pipes/ellipses.pipe'; +import { RouterTestingModule } from '@angular/router/testing'; +import { of } from 'rxjs'; import { apiEouRes } from 'src/app/core/mock-data/extended-org-user.data'; -import { getElementBySelector, getTextContent } from 'src/app/core/dom-helpers'; describe('DelegatedAccMessageComponent', () => { let component: DelegatedAccMessageComponent; @@ -13,9 +14,10 @@ describe('DelegatedAccMessageComponent', () => { beforeEach(waitForAsync(() => { const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); + authServiceSpy.getEou.and.returnValue(of(apiEouRes)); TestBed.configureTestingModule({ declarations: [DelegatedAccMessageComponent, EllipsisPipe], - imports: [IonicModule.forRoot()], + imports: [IonicModule.forRoot(), RouterTestingModule], providers: [ { provide: AuthService, @@ -26,8 +28,6 @@ describe('DelegatedAccMessageComponent', () => { fixture = TestBed.createComponent(DelegatedAccMessageComponent); component = fixture.componentInstance; - authService = TestBed.inject(AuthService) as jasmine.SpyObj; - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); fixture.detectChanges(); })); @@ -38,7 +38,7 @@ describe('DelegatedAccMessageComponent', () => { it("should display delegatee's name", () => { component.delegateeName = 'Abhishek Jain'; fixture.detectChanges(); - expect(getTextContent(getElementBySelector(fixture, '.delegated-acc'))).toEqual( + expect(fixture.nativeElement.querySelector('.delegated-acc').textContent).toContain( `You're now managing Abhishek Jain's account` ); }); From 52bf8d723ce004a90ef6660bd7b9895395a4a89b Mon Sep 17 00:00:00 2001 From: Mohammed farhan K Date: Sat, 1 Feb 2025 18:18:35 +0530 Subject: [PATCH 3/5] test fix --- .../delegated-acc-message.component.html | 2 +- .../delegated-acc-message.component.scss | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html index 0b3b0e4522..c521a0f3a1 100644 --- a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html +++ b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html @@ -1,4 +1,4 @@ You're now managing {{ delegateeName | ellipsis : 15 }}'s account - Switch back + Switch back diff --git a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.scss b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.scss index 488d91d7f1..042d7d2609 100644 --- a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.scss +++ b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.scss @@ -12,3 +12,11 @@ font-weight: bold; margin-top: env(safe-area-inset-top); } + +.u-link { + color: inherit; +} + +.u-link.disabled { + color: gray; +} From 043b49d47df3c3fab03f542ee6a2eed96110a1c2 Mon Sep 17 00:00:00 2001 From: Mohammed farhan K Date: Sat, 1 Feb 2025 18:21:51 +0530 Subject: [PATCH 4/5] test fix --- .../delegated-acc-message.component.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts index 6216d69911..770fedd75f 100644 --- a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts +++ b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit, EventEmitter } from '@angular/core'; import { AuthService } from '../../../core/services/auth.service'; -import { from, concat } from 'rxjs'; +import { from, concat, Observable } from 'rxjs'; import { shareReplay } from 'rxjs/operators'; import { Router } from '@angular/router'; import { NetworkService } from '../../../core/services/network.service'; @@ -12,11 +12,11 @@ import { NetworkService } from '../../../core/services/network.service'; }) export class DelegatedAccMessageComponent implements OnInit { delegateeName: string; - isConnected$: any; + isConnected$: Observable; constructor(private authService: AuthService, private router: Router, private networkService: NetworkService) {} - ngOnInit() { + ngOnInit(): void { from(this.authService.getEou()).subscribe((res) => { this.delegateeName = res.us.full_name; }); @@ -30,7 +30,7 @@ export class DelegatedAccMessageComponent implements OnInit { ); } - switchBack() { + switchBack(): void { if (!this.isConnected$) { return; } From 23d61da41e15ff12fa576932932ffd735db84b89 Mon Sep 17 00:00:00 2001 From: Mohammed farhan K Date: Sat, 1 Feb 2025 18:27:07 +0530 Subject: [PATCH 5/5] test fix --- .../delegated-acc-message/delegated-acc-message.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts index 770fedd75f..75dc53f9d9 100644 --- a/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts +++ b/src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts @@ -12,6 +12,7 @@ import { NetworkService } from '../../../core/services/network.service'; }) export class DelegatedAccMessageComponent implements OnInit { delegateeName: string; + isConnected$: Observable; constructor(private authService: AuthService, private router: Router, private networkService: NetworkService) {}