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
6 changes: 4 additions & 2 deletions src/app/pages/edit-profile/edit-profile.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
<div class="main-wrapper">
<app-profile-image [profileImageData]='profileImageData' [uploadImage]="true"
(imageRemoveEvent)="removeCurrentPhoto($event)" (imageUploadEvent)="imageUploadEvent($event)"></app-profile-image>
<div *ngIf="showForm" class="mx-10">
@if (showFormSignal()) {
<div class="mx-10">
<app-dynamic-form [jsonFormData]="formData" #form1> </app-dynamic-form>
</div>
}
</div>
</ion-content>

<ion-footer class="ion-no-border footer-button" submitButton>
<ion-toolbar>
<ion-button [disabled]="form1 && !form1.myForm.valid" expand="full" (click)="onSubmit()">{{'SUBMIT' | translate}}</ion-button>
</ion-toolbar>
</ion-footer>
</ion-footer>
86 changes: 85 additions & 1 deletion src/app/pages/edit-profile/edit-profile.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ describe('EditProfilePage', () => {
await component.ngOnInit();
expect(mockChangeDetectorRef.detectChanges).toHaveBeenCalled();
});

it('should expose showForm through signal-backed getter/setter', () => {
component.showForm = false;
expect(component.showForm).toBeFalse();
expect(component.showFormSignal()).toBeFalse();

component.showForm = true;
expect(component.showForm).toBeTrue();
expect(component.showFormSignal()).toBeTrue();
});
});

describe('ionViewWillEnter', () => {
Expand Down Expand Up @@ -313,6 +323,49 @@ describe('EditProfilePage', () => {
const result = await component.canPageLeave();
expect(result).toBe(false);
});

it('should return true when form is pristine and image is uploaded with backButton true', async () => {
component.form1 = {
myForm: { pristine: true },
onSubmit: jasmine.createSpy('onSubmit'),
reset: jasmine.createSpy('reset')
} as any;
component.profileImageData.isUploaded = true;
component.headerConfig.backButton = true;

const mockAlert = {
present: jasmine.createSpy('present').and.returnValue(Promise.resolve()),
onDidDismiss: jasmine.createSpy('onDidDismiss').and.returnValue(Promise.resolve({ role: 'cancel' }))
};
mockAlertController.create.and.returnValue(Promise.resolve(mockAlert as any));

const result = await component.canPageLeave();

expect(mockAlert.present).not.toHaveBeenCalled();
expect(result).toBe(true);
});

it('should return false when form is pristine and backButton is false', async () => {
component.userDetails = { ...mockUserDetails, profile_mandatory_fields: ['field1'] };
component.form1 = {
myForm: { pristine: true },
onSubmit: jasmine.createSpy('onSubmit'),
reset: jasmine.createSpy('reset')
} as any;
component.profileImageData.isUploaded = true;
component.headerConfig.backButton = false;

const mockAlert = {
present: jasmine.createSpy('present').and.returnValue(Promise.resolve()),
onDidDismiss: jasmine.createSpy('onDidDismiss').and.returnValue(Promise.resolve({ role: 'cancel' }))
};
mockAlertController.create.and.returnValue(Promise.resolve(mockAlert as any));

const result = await component.canPageLeave();

expect(mockAlert.present).toHaveBeenCalled();
expect(result).toBe(false);
});
});

describe('onSubmit', () => {
Expand Down Expand Up @@ -416,6 +469,37 @@ describe('EditProfilePage', () => {

expect(mockProfileService.profileUpdate).toHaveBeenCalled();
});

it('should send fallback values when optional fields are missing', async () => {
component.formData = {
controls: [
{ name: 'about', value: '', multiple: false },
{ name: 'education_qualification', value: '', multiple: false },
{ name: 'experience', value: null, multiple: false }
]
};
component.entityNames = ['about', 'education_qualification', 'experience'];
component.userDetails = { ...mockUserDetails, profile_mandatory_fields: ['a'] };
component.form1 = {
myForm: {
valid: true,
value: { about: '', education_qualification: '', experience: null },
markAsPristine: jasmine.createSpy('markAsPristine')
},
onSubmit: jasmine.createSpy('onSubmit'),
reset: jasmine.createSpy('reset')
} as any;
component.profileImageData.isUploaded = true;
mockProfileService.profileUpdate.and.returnValue(Promise.resolve(true));

await component.onSubmit();

const payload = mockProfileService.profileUpdate.calls.mostRecent().args[0];
expect(payload.about).toBe('NA');
expect(payload.education_qualification).toBe('NA');
expect(payload.experience).toBe(0);
expect(component.userDetails.profile_mandatory_fields).toEqual([]);
});
});

describe('resetForm', () => {
Expand Down Expand Up @@ -529,4 +613,4 @@ describe('EditProfilePage', () => {
expect(result.length).toBe(2);
});
});
});
});
16 changes: 13 additions & 3 deletions src/app/pages/edit-profile/edit-profile.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { ChangeDetectorRef, Component, OnInit, ViewChild, signal } from '@angular/core';
import { HttpService } from 'src/app/core/services/http/http.service';
import {
DynamicFormComponent,
Expand Down Expand Up @@ -34,6 +34,7 @@ import { PlatformLocation, Location } from '@angular/common';
})
export class EditProfilePage implements OnInit, isDeactivatable {
private win: any = window;
private readonly showFormState = signal(false);
updated: boolean;
@ViewChild('form1') form1: DynamicFormComponent;
profileImageData: any = {
Expand All @@ -46,7 +47,16 @@ export class EditProfilePage implements OnInit, isDeactivatable {
};
path;
localImage;
showForm: any = false;
get showForm(): boolean {
return this.showFormState();
}

set showForm(value: boolean) {
this.showFormState.set(!!value);
}

showFormSignal = this.showFormState.asReadonly();

userDetails: any;
entityNames: any;
entityList: any;
Expand Down Expand Up @@ -91,12 +101,12 @@ export class EditProfilePage implements OnInit, isDeactivatable {
this.entityNames = await this.updateEntityArray(this.userDetails?.profile_mandatory_fields, entityNames);
this.entityList = await this.form.getEntities(this.entityNames, 'PROFILE');
this.formData = await this.form.populateEntity(this.formData, this.entityList)
this.changeDetRef.detectChanges();
if (this.userDetails) {
this.profileImageData.image = this.userDetails.image;
this.profileService.prefillData(this.userDetails, this.entityNames, this.formData);
this.showForm = true;
}
this.changeDetRef.detectChanges();
if(this.userDetails?.profile_mandatory_fields?.length || !this.userDetails?.about){
this.headerConfig.backButton = false;
let msg = {
Expand Down
Loading
Loading