Skip to content

Commit

Permalink
test(Password): Remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreykwan committed Oct 9, 2023
1 parent 2c3df2b commit 6ad1fd2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EditPasswordComponent } from './edit-password.component';
import { UserService } from '../../../services/user.service';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, Observable, Subscriber } from 'rxjs';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ReactiveFormsModule } from '@angular/forms';
import { NO_ERRORS_SCHEMA } from '@angular/core';
Expand Down Expand Up @@ -221,20 +221,23 @@ function setPasswords(oldPass: string, newPass: string, newPassConfirm: string)
fixture.detectChanges();
}

function generateSuccessObservable(arg: string | any): Observable<any> {
return new Observable((observer) => {
observer.next(generateSuccessResponseValue(arg));
observer.complete();
});
function generateSuccessObservable(arg: string | any): Observable<void> {
return generateResponseObservable(arg, true);
}

function generateSuccessResponseValue(arg: string | any): any {
return typeof arg === 'string' ? { messageCode: arg } : arg;
}

function generateErrorObservable(arg: string | any): Observable<any> {
return new Observable((observer) => {
observer.error(generateErrorResponseValue(arg));
function generateErrorObservable(arg: string | any): Observable<void> {
return generateResponseObservable(arg, false);
}

function generateResponseObservable(arg: string | any, isSuccess: boolean): Observable<void> {
return new Observable((observer: Subscriber<void>) => {
isSuccess
? observer.next(generateSuccessResponseValue(arg))
: observer.error(generateErrorResponseValue(arg));
observer.complete();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ export class NewPasswordAndConfirmHarness extends ComponentHarness {
}

async setNewPassword(value: string): Promise<void> {
await this.setInputValue(await this.getNewPasswordInput(), value);
this.setPassword(value, false);
}

async setConfirmNewPassword(value: string): Promise<void> {
await this.setInputValue(await this.getConfirmNewPasswordInput(), value);
this.setPassword(value, true);
}

async setPassword(value: string, isConfirm: boolean): Promise<void> {
await this.setInputValue(
await (isConfirm ? this.getConfirmNewPasswordInput() : this.getNewPasswordInput()),
value
);
}

private async setInputValue(input: MatInputHarness, value: string): Promise<void> {
Expand Down

0 comments on commit 6ad1fd2

Please sign in to comment.