From 4bac1dd7c4c0981650938cecf0f6aecaba8e0d17 Mon Sep 17 00:00:00 2001 From: Suyash Patil <127177049+suyashpatil78@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:48:22 +0530 Subject: [PATCH] fix: QA fixes for commute deduction (#2835) * fix: header fix for commute details * minor * QA fixes * minor * tests added * minor correction in modal opening logic --- .../add-edit-mileage-5.spec.ts | 66 +++++++++- .../add-edit-mileage.page.html | 116 +++++++++--------- .../add-edit-mileage/add-edit-mileage.page.ts | 11 +- .../fy-select-commute-details.component.html | 2 +- .../fy-select-commute-details.component.scss | 4 + .../route-selector.component.html | 2 + 6 files changed, 138 insertions(+), 63 deletions(-) diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage-5.spec.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage-5.spec.ts index e027c62de5..291b6c716c 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage-5.spec.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage-5.spec.ts @@ -739,7 +739,7 @@ export function TestCases5(getTestBed) { expect(component.fg.get('commuteDeduction').value).toEqual(CommuteDeduction.ONE_WAY); })); - it('should call updateDistanceOnDeductionChange method if commuteDeduction form control value changes', fakeAsync(() => { + it('should call updateDistanceOnDeductionChange method if commuteDeduction form control value changes and commuteDetails is defined', fakeAsync(() => { component.mode = 'edit'; activatedRoute.snapshot.params.navigate_back = true; activatedRoute.snapshot.params.activeIndex = 0; @@ -760,7 +760,9 @@ export function TestCases5(getTestBed) { orgSettingsService.get.and.returnValue(of(mockOrgSettings)); employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData)); mileageService.getCommuteDeductionOptions.and.returnValue(commuteDeductionOptionsData1); + mileageService.isCommuteDeductionEnabled.and.returnValue(true); spyOn(component, 'updateDistanceOnDeductionChange'); + spyOn(component, 'openCommuteDetailsModal'); fixture.detectChanges(); component.ionViewWillEnter(); @@ -769,8 +771,49 @@ export function TestCases5(getTestBed) { setupMatchers(); + component.commuteDetails.id = 12345; component.fg.get('commuteDeduction').setValue(CommuteDeduction.ROUND_TRIP); + expect(component.updateDistanceOnDeductionChange).toHaveBeenCalledTimes(1); + expect(component.openCommuteDetailsModal).not.toHaveBeenCalled(); + })); + + it('should call openCommuteDetailsModal method if commuteDeduction form control value changes and commuteDetails is not defined', fakeAsync(() => { + component.mode = 'edit'; + activatedRoute.snapshot.params.navigate_back = true; + activatedRoute.snapshot.params.activeIndex = 0; + activatedRoute.snapshot.params.txnIds = JSON.stringify(['tx3qwe4ty', 'tx6sd7gh', 'txD3cvb6']); + activatedRoute.snapshot.params.id = 'tx3qwe4ty'; + spyOn(component, 'getRecentlyUsedValues').and.returnValue(of(null)); + statusService.find.and.returnValue(of(getEstatusApiResponse)); + mileageRatesService.getAllMileageRates.and.returnValue(of([])); + mileageService.getOrgUserMileageSettings.and.returnValue(of(null)); + mileageRatesService.filterEnabledMileageRates.and.returnValue([]); + const mockEtxn = cloneDeep(unflattenedTxnData); + mockEtxn.tx.commute_deduction = CommuteDeduction.ONE_WAY; + spyOn(component, 'getEditExpense').and.returnValue(of(mockEtxn)); + accountsService.getEtxnSelectedPaymentMode.and.returnValue(null); + mileageService.isCommuteDeductionEnabled.and.returnValue(true); + const mockOrgSettings = cloneDeep(orgSettingsRes); + mockOrgSettings.commute_deduction_settings = { allowed: true, enabled: true }; + orgSettingsService.get.and.returnValue(of(mockOrgSettings)); + employeesService.getCommuteDetails.and.returnValue(of(commuteDetailsResponseData)); + mileageService.getCommuteDeductionOptions.and.returnValue(commuteDeductionOptionsData1); + spyOn(component, 'updateDistanceOnDeductionChange'); + spyOn(component, 'openCommuteDetailsModal'); + fixture.detectChanges(); + + component.ionViewWillEnter(); + tick(1000); + fixture.detectChanges(); + + setupMatchers(); + + component.commuteDetails = null; + component.fg.get('commuteDeduction').setValue(CommuteDeduction.ROUND_TRIP); + + expect(component.updateDistanceOnDeductionChange).not.toHaveBeenCalled(); + expect(component.openCommuteDetailsModal).toHaveBeenCalledTimes(1); })); }); @@ -940,6 +983,27 @@ export function TestCases5(getTestBed) { expect(component.commuteDetails).toBeNull(); })); + + it('should set commuteDetails and change commute deduction form value to null if user does not save commute details from mileage page', fakeAsync(() => { + const commuteDetailsModalSpy = jasmine.createSpyObj('commuteDetailsModal', ['present', 'onWillDismiss']); + commuteDetailsModalSpy.onWillDismiss.and.resolveTo({ data: { action: 'cancel' } }); + modalController.create.and.resolveTo(commuteDetailsModalSpy); + + component.openCommuteDetailsModal(); + tick(100); + + expect(modalController.create).toHaveBeenCalledOnceWith({ + component: FySelectCommuteDetailsComponent, + mode: 'ios', + }); + expect(commuteDetailsModalSpy.present).toHaveBeenCalledTimes(1); + expect(commuteDetailsModalSpy.onWillDismiss).toHaveBeenCalledTimes(1); + expect(authService.getEou).not.toHaveBeenCalled(); + expect(employeesService.getCommuteDetails).not.toHaveBeenCalled(); + expect(mileageService.getCommuteDeductionOptions).not.toHaveBeenCalled(); + expect(component.showCommuteUpdatedPopover).not.toHaveBeenCalled(); + expect(component.fg.get('commuteDeduction').value).toBeNull(); + })); }); }); } diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.html b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.html index e8a79bb1b9..a008b0bf58 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.html +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.html @@ -144,72 +144,68 @@ [touchedInParent]="fg.controls.route.touched" [validInParent]="fg.controls.route.valid" (distanceChange)="updateDistanceOnLocationChange()" - > + > + + +
+ + + +
+
{{label}}
+
+ {{distance.toFixed(2) + ' ' + distanceUnit}} +
+
+ {{distance + ' ' + distanceUnit}} +
+
+ + Add Location +
+
+ check +
+
+
+ Please select commute deduction. +
+
+
+ - - -
- - - -
-
{{label}}
-
- {{distance.toFixed(2) + ' ' + distanceUnit}} -
-
- {{distance + ' ' + distanceUnit}} -
-
- - Add Location -
-
- check -
-
-
- Please select commute deduction. -
-
-
-
{ - this.updateDistanceOnDeductionChange(commuteDeductionType); + if (this.commuteDetails?.id) { + this.updateDistanceOnDeductionChange(commuteDeductionType); + } else { + if (!(commuteDeductionType === 'NO_DEDUCTION')) { + this.openCommuteDetailsModal(); + } + } }); this.fg.controls.route.valueChanges.pipe(distinctUntilKeyChanged('roundTrip')).subscribe(() => { @@ -2998,6 +3004,9 @@ export class AddEditMileagePage implements OnInit { this.fg.patchValue({ commuteDeduction: 'NO_DEDUCTION' }); this.showCommuteUpdatedPopover(); }); + } else { + // If user closes the modal without saving the commute details, reset the commute deduction field to null + this.fg.patchValue({ commuteDeduction: null }, { emitEvent: false }); } } } diff --git a/src/app/shared/components/fy-select-commute-details/fy-select-commute-details.component.html b/src/app/shared/components/fy-select-commute-details/fy-select-commute-details.component.html index 6eb970035a..7492945a7b 100644 --- a/src/app/shared/components/fy-select-commute-details/fy-select-commute-details.component.html +++ b/src/app/shared/components/fy-select-commute-details/fy-select-commute-details.component.html @@ -1,5 +1,5 @@ - + diff --git a/src/app/shared/components/fy-select-commute-details/fy-select-commute-details.component.scss b/src/app/shared/components/fy-select-commute-details/fy-select-commute-details.component.scss index 3660724b49..54fa8ff961 100644 --- a/src/app/shared/components/fy-select-commute-details/fy-select-commute-details.component.scss +++ b/src/app/shared/components/fy-select-commute-details/fy-select-commute-details.component.scss @@ -1,6 +1,10 @@ @import '../../../../theme/colors.scss'; .commute-details { + &--toolbar { + margin-top: calc(env(safe-area-inset-top)); + } + &--header { &-save { --color: $brand-primary; diff --git a/src/app/shared/components/route-selector/route-selector.component.html b/src/app/shared/components/route-selector/route-selector.component.html index c046330784..a283ff2a8d 100644 --- a/src/app/shared/components/route-selector/route-selector.component.html +++ b/src/app/shared/components/route-selector/route-selector.component.html @@ -137,6 +137,8 @@
+ +