diff --git a/src/app/account/settings/acc-settings/acc-settings.component.spec.ts b/src/app/account/settings/acc-settings/acc-settings.component.spec.ts index a2942298..d7d8fce5 100644 --- a/src/app/account/settings/acc-settings/acc-settings.component.spec.ts +++ b/src/app/account/settings/acc-settings/acc-settings.component.spec.ts @@ -20,7 +20,7 @@ import { MatSelectModule } from '@angular/material/select'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { By } from '@angular/platform-browser'; import { provideAnimations } from '@angular/platform-browser/animations'; -import { Params, Router } from '@angular/router'; +import { Params } from '@angular/router'; import { AlertService } from '@services/shared/alert.service'; @@ -30,7 +30,6 @@ describe('AccountSettingsComponent', () => { let component: AccountSettingsComponent; let fixture: ComponentFixture; - let routerSpy: jasmine.SpyObj; let alertSpy: jasmine.SpyObj; const userResponse = { @@ -53,7 +52,7 @@ describe('AccountSettingsComponent', () => { } }; - // Your existing mockService + // Mock GlobalService const mockService: Partial = { // eslint-disable-next-line @typescript-eslint/no-unused-vars get(_serviceConfig, _id: number, _routerParams?: Params): Observable { @@ -78,7 +77,6 @@ describe('AccountSettingsComponent', () => { }; beforeEach(() => { - routerSpy = jasmine.createSpyObj('Router', ['navigate']); alertSpy = jasmine.createSpyObj('AlertService', ['showSuccessMessage', 'showErrorMessage']); TestBed.configureTestingModule({ @@ -105,10 +103,6 @@ describe('AccountSettingsComponent', () => { provide: GlobalService, useValue: mockService }, - { - provide: Router, - useValue: routerSpy - }, { provide: AlertService, useValue: alertSpy @@ -188,7 +182,6 @@ describe('AccountSettingsComponent', () => { expect(component['gs'].update).toHaveBeenCalledWith(SERV.USERS, component['gs'].userId, component.form.value); expect(component['alert'].showSuccessMessage).toHaveBeenCalled(); - expect(routerSpy.navigate).toHaveBeenCalledOnceWith(['users/all-users']); }); it('does not submit form with invalid email', () => { @@ -204,7 +197,6 @@ describe('AccountSettingsComponent', () => { expect(component.form.valid).toBeFalse(); expect(updateSpy).not.toHaveBeenCalled(); expect(component['alert'].showSuccessMessage).not.toHaveBeenCalled(); - expect(routerSpy.navigate).not.toHaveBeenCalled(); }); }); @@ -283,6 +275,7 @@ describe('AccountSettingsComponent', () => { confirmNewPassword: 'P4ssw0rd1234' }); component.changepasswordFormGroup.updateValueAndValidity(); + fixture.detectChanges(); expect(component.changepasswordFormGroup.hasError('passwordMismatch')).toBe(true); // Set matching passwords @@ -291,6 +284,7 @@ describe('AccountSettingsComponent', () => { confirmNewPassword: 'password1234' }); component.changepasswordFormGroup.updateValueAndValidity(); + fixture.detectChanges(); expect(component.changepasswordFormGroup.hasError('passwordMismatch')).toBe(false); }); diff --git a/src/app/account/settings/acc-settings/acc-settings.component.ts b/src/app/account/settings/acc-settings/acc-settings.component.ts index 25259671..1a9427bc 100644 --- a/src/app/account/settings/acc-settings/acc-settings.component.ts +++ b/src/app/account/settings/acc-settings/acc-settings.component.ts @@ -159,7 +159,6 @@ export class AccountSettingsComponent implements OnInit, OnDestroy { this.gs.update(SERV.USERS, this.gs.userId, this.form.value).subscribe(() => { this.alert.showSuccessMessage('User saved'); this.isUpdatingLoading = false; - void this.router.navigate(['users/all-users']); }) ); } diff --git a/src/app/core/_validators/password.validator.ts b/src/app/core/_validators/password.validator.ts index 42e43658..1120c91b 100644 --- a/src/app/core/_validators/password.validator.ts +++ b/src/app/core/_validators/password.validator.ts @@ -5,15 +5,6 @@ export function passwordMatchValidator(): ValidatorFn { const newPassword = control.get('newPassword')?.value; const confirmNewPassword = control.get('confirmNewPassword')?.value; - if (newPassword !== confirmNewPassword) { - control.get('confirmNewPassword')?.setErrors({ passwordMismatch: true }); - return { passwordMismatch: true }; - } else { - const confirmCtrl = control.get('confirmNewPassword'); - if (confirmCtrl?.hasError('passwordMismatch')) { - confirmCtrl.updateValueAndValidity({ onlySelf: true, emitEvent: false }); - } - return null; - } + return newPassword && confirmNewPassword && newPassword !== confirmNewPassword ? { passwordMismatch: true } : null; }; }