Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -30,7 +30,6 @@ describe('AccountSettingsComponent', () => {
let component: AccountSettingsComponent;
let fixture: ComponentFixture<AccountSettingsComponent>;

let routerSpy: jasmine.SpyObj<Router>;
let alertSpy: jasmine.SpyObj<AlertService>;

const userResponse = {
Expand All @@ -53,7 +52,7 @@ describe('AccountSettingsComponent', () => {
}
};

// Your existing mockService
// Mock GlobalService
const mockService: Partial<GlobalService> = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
get(_serviceConfig, _id: number, _routerParams?: Params): Observable<any> {
Expand All @@ -78,7 +77,6 @@ describe('AccountSettingsComponent', () => {
};

beforeEach(() => {
routerSpy = jasmine.createSpyObj('Router', ['navigate']);
alertSpy = jasmine.createSpyObj('AlertService', ['showSuccessMessage', 'showErrorMessage']);

TestBed.configureTestingModule({
Expand All @@ -105,10 +103,6 @@ describe('AccountSettingsComponent', () => {
provide: GlobalService,
useValue: mockService
},
{
provide: Router,
useValue: routerSpy
},
{
provide: AlertService,
useValue: alertSpy
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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();
});
});

Expand Down Expand Up @@ -283,6 +275,7 @@ describe('AccountSettingsComponent', () => {
confirmNewPassword: 'P4ssw0rd1234'
});
component.changepasswordFormGroup.updateValueAndValidity();
fixture.detectChanges();
expect(component.changepasswordFormGroup.hasError('passwordMismatch')).toBe(true);

// Set matching passwords
Expand All @@ -291,6 +284,7 @@ describe('AccountSettingsComponent', () => {
confirmNewPassword: 'password1234'
});
component.changepasswordFormGroup.updateValueAndValidity();
fixture.detectChanges();
expect(component.changepasswordFormGroup.hasError('passwordMismatch')).toBe(false);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
})
);
}
Expand Down
11 changes: 1 addition & 10 deletions src/app/core/_validators/password.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}