From 857deda8331a80b569501c316a7be06983e799cb Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 30 Nov 2023 20:09:00 -0800 Subject: [PATCH] Fix password keyup on togglevisible button empties password --- .../profile-edit-dialog.component.spec.ts | 8 ++++---- .../profile-edit-dialog/profile-edit-dialog.component.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts index 8a1901721..0b300bd74 100644 --- a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts @@ -13,7 +13,6 @@ import { NgbActiveModal, NgbModal, NgbModalModule, - NgbModalRef, } from '@ng-bootstrap/ng-bootstrap' import { HttpClientModule } from '@angular/common/http' import { TextComponent } from '../input/text/text.component' @@ -36,7 +35,6 @@ describe('ProfileEditDialogComponent', () => { let profileService: ProfileService let toastService: ToastService let clipboard: Clipboard - let modalService: NgbModal beforeEach(() => { TestBed.configureTestingModule({ @@ -57,7 +55,6 @@ describe('ProfileEditDialogComponent', () => { profileService = TestBed.inject(ProfileService) toastService = TestBed.inject(ToastService) clipboard = TestBed.inject(Clipboard) - modalService = TestBed.inject(NgbModal) fixture = TestBed.createComponent(ProfileEditDialogComponent) component = fixture.componentInstance fixture.detectChanges() @@ -138,7 +135,10 @@ describe('ProfileEditDialogComponent', () => { getSpy.mockReturnValue(of(profile)) component.ngOnInit() component.form.get('password').patchValue('new*pass') - component.onPasswordKeyUp({ target: { value: 'new*pass' } } as any) + component.onPasswordKeyUp({ + target: { value: 'new*pass', tagName: 'input' }, + } as any) + component.onPasswordKeyUp({ target: { tagName: 'button' } } as any) // coverage fixture.detectChanges() expect(component.form.get('password_confirm').enabled).toBeTruthy() expect(fixture.debugElement.nativeElement.textContent).toContain( diff --git a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.ts b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.ts index 2c98e3076..19391ce28 100644 --- a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.ts @@ -102,6 +102,7 @@ export class ProfileEditDialogComponent implements OnInit, OnDestroy { } onPasswordKeyUp(event: KeyboardEvent): void { + if ((event.target as HTMLElement).tagName !== 'input') return // toggle button can trigger this handler this.newPassword = (event.target as HTMLInputElement)?.value this.onPasswordChange() } @@ -162,7 +163,6 @@ export class ProfileEditDialogComponent implements OnInit, OnDestroy { generateAuthToken(): void { this.profileService.generateAuthToken().subscribe({ next: (token: string) => { - console.log(token) this.form.patchValue({ auth_token: token }) }, error: (error) => {