Fix password keyup on togglevisible button empties password

This commit is contained in:
shamoon
2023-11-30 20:09:00 -08:00
parent b3941ddecf
commit 857deda833
2 changed files with 5 additions and 5 deletions

View File

@@ -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(

View File

@@ -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) => {