-
Notifications
You must be signed in to change notification settings - Fork 15
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
fix: Delegatee switch back top header #3466
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
<span class="delegated-acc"> You're now managing {{ delegateeName | ellipsis: 15 }}'s account </span> | ||
<span class="delegated-acc"> | ||
You're now managing {{ delegateeName | ellipsis : 15 }}'s account | ||
<u class="u-link" [ngClass]="{ disabled: !isConnected$ | async }" (click)="switchBack()">Switch back</u> | ||
</span> | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,3 +12,11 @@ | |||||||||||||||||||||||||||||||||
font-weight: bold; | ||||||||||||||||||||||||||||||||||
margin-top: env(safe-area-inset-top); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.u-link { | ||||||||||||||||||||||||||||||||||
color: inherit; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.u-link.disabled { | ||||||||||||||||||||||||||||||||||
color: gray; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
Comment on lines
+16
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Style with a Bang: Enhance Pointer Visuals Superstar, your link styles are almost legendary! To further impress, add visual cues by setting .u-link {
- color: inherit;
+ color: inherit;
+ cursor: pointer;
}
.u-link.disabled {
- color: gray;
+ color: gray;
+ cursor: not-allowed;
} This will ensure that users know when the element is clickable and when it's not, just like a Rajinikanth punch! 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification NetworkService missing its spotlight in the test arena! I checked the component, and it's clear that NetworkService plays a crucial role there. However, the test file doesn't cast this actor, leaving the switch-back functionality without complete coverage. Ensure you add a proper mock or stub for NetworkService in the test setup for the component.
🔗 Analysis chainMind-blowing additions, but where's the network service test setup, partner? You've added RouterTestingModule for navigation testing, but I notice you haven't set up the NetworkService that's needed for the new switchBack functionality. Just like how I make a grand entrance in every scene, your tests should cover all the important actors! Let me help you verify if NetworkService is used in the component: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check if NetworkService is used in the component
ast-grep --pattern 'class DelegatedAccMessageComponent {
$$$
constructor($$$) {
$$$
}
$$$
}'
Length of output: 106 Script: #!/bin/bash
# Search for NetworkService usage in the component implementation file
rg "NetworkService" src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts
Length of output: 290 Script: #!/bin/bash
# Check if NetworkService is mocked or provided in the test configuration inside the spec file
rg "NetworkService" src/app/shared/components/delegated-acc-message/delegated-acc-message.component.spec.ts
Length of output: 107 |
||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion The transformation from Promise to Observable is stylish, but incomplete! Like how I transform from a simple bus conductor to a superstar, you've transformed the auth service mock from Promise to Observable. But where are the test cases for the new switchBack feature? The RouterTestingModule is ready for action, but no one's called "Action!" yet! Add these test cases to make your test suite as powerful as my punch dialogues: it('should handle switch back when connected', () => {
component.isConnected$ = of(true);
component.switchBack();
// Add router navigation assertions
});
it('should not switch back when disconnected', () => {
component.isConnected$ = of(false);
component.switchBack();
// Verify no navigation occurs
}); Also applies to: 20-20 |
||
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>; | ||
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` | ||
); | ||
Comment on lines
+41
to
43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) The selector change is sharp, but let's make it sharper! You've changed the element selection like how I changed the style of action scenes in cinema! But remember, in testing, like in movies, we need to be precise with our expectations. Let's make it even more precise: const messageElement = fixture.nativeElement.querySelector('.delegated-acc');
expect(messageElement).toBeTruthy();
expect(messageElement.textContent.trim()).toBe(`You're now managing Abhishek Jain's account`); |
||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
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, Observable } 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', | ||
templateUrl: './delegated-acc-message.component.html', | ||
styleUrls: ['./delegated-acc-message.component.scss'], | ||
}) | ||
export class DelegatedAccMessageComponent implements OnInit { | ||
delegateeName; | ||
delegateeName: string; | ||
|
||
constructor(private authService: AuthService) {} | ||
isConnected$: Observable<boolean>; | ||
|
||
ngOnInit() { | ||
constructor(private authService: AuthService, private router: Router, private networkService: NetworkService) {} | ||
|
||
ngOnInit(): void { | ||
from(this.authService.getEou()).subscribe((res) => { | ||
this.delegateeName = res.us.full_name; | ||
}); | ||
this.setupNetworkWatcher(); | ||
} | ||
|
||
setupNetworkWatcher(): void { | ||
const networkWatcherEmitter = this.networkService.connectivityWatcher(new EventEmitter<boolean>()); | ||
this.isConnected$ = concat(this.networkService.isOnline(), networkWatcherEmitter.asObservable()).pipe( | ||
shareReplay(1) | ||
); | ||
} | ||
|
||
switchBack(): void { | ||
if (!this.isConnected$) { | ||
return; | ||
} | ||
this.router.navigate(['/', 'enterprise', 'delegated_accounts', { switchToOwn: true }]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Punch It Right: Fix the Async Pipe and Click Guard
Boss, the style is cool but be careful! Wrap the async pipe evaluation in parentheses so the negation applies to its result—not the observable itself. Use this:
This way you ensure that the disabled style is applied correctly and the click event only fires when connected.