Skip to content

Commit

Permalink
fix: added survey for add-edit-expense
Browse files Browse the repository at this point in the history
  • Loading branch information
Z3RO-O committed Oct 22, 2024
1 parent 96b2288 commit 51355f4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
55 changes: 17 additions & 38 deletions src/app/core/services/refiner.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,44 +54,23 @@ describe('RefinerService', () => {
});

describe('getRegion', () => {
it('should return "India" for INR currency', () => {
expect(refinerService.getRegion('INR')).toEqual('India');
});

it('should return "International Americas" for USD', () => {
expect(refinerService.getRegion('USD')).toEqual('International Americas');
});

it('should return correct region for APAC currency', () => {
expect(refinerService.getRegion('AUD')).toEqual('International APAC');
});

it('should return correct region for Middle East Africa currency', () => {
expect(refinerService.getRegion('AED')).toEqual('International Africa');
});

it('should return correct region for Europe currency', () => {
expect(refinerService.getRegion('EUR')).toEqual('Europe');
});

it('should return "International Africa" for another Middle East Africa currency', () => {
expect(refinerService.getRegion('ZAR')).toEqual('International Africa');
});

it('should return "Undefined" for unsupported currency', () => {
expect(refinerService.getRegion('XYZ')).toEqual('Undefined');
});

it('should return "Undefined" for null currency', () => {
expect(refinerService.getRegion(null)).toEqual('Undefined');
});

it('should return "Undefined" for undefined currency', () => {
expect(refinerService.getRegion(undefined)).toEqual('Undefined');
});

it('should return "Undefined" for empty currency', () => {
expect(refinerService.getRegion('')).toEqual('Undefined');
const testCases = [
{ currency: 'INR', expected: 'India' },
{ currency: 'USD', expected: 'International Americas' },
{ currency: 'AUD', expected: 'International APAC' },
{ currency: 'AED', expected: 'International Africa' },
{ currency: 'EUR', expected: 'Europe' },
{ currency: 'ZAR', expected: 'International Africa' },
{ currency: 'XYZ', expected: 'Undefined' },
{ currency: null, expected: 'Undefined' },
{ currency: undefined, expected: 'Undefined' },
{ currency: '', expected: 'Undefined' },
];

testCases.forEach(({ currency, expected }) => {
it(`should return "${expected}" for currency "${currency}"`, () => {
expect(refinerService.getRegion(currency)).toEqual(expected);
});
});
});

Expand Down
34 changes: 27 additions & 7 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import { corporateCardTransaction } from 'src/app/core/models/platform/v1/cc-tra
import { PlatformFileGenerateUrlsResponse } from 'src/app/core/models/platform/platform-file-generate-urls-response.model';
import { SpenderFileService } from 'src/app/core/services/platform/v1/spender/file.service';
import { ExpenseTransactionStatus } from 'src/app/core/enums/platform/v1/expense-transaction-status.enum';
import { RefinerService } from 'src/app/core/services/refiner.service';

// eslint-disable-next-line
type FormValue = {
Expand Down Expand Up @@ -487,6 +488,7 @@ export class AddEditExpensePage implements OnInit {
private orgUserSettingsService: OrgUserSettingsService,
private storageService: StorageService,
private launchDarklyService: LaunchDarklyService,
private refinerService: RefinerService,
private platformHandlerService: PlatformHandlerService,
private expensesService: ExpensesService,
private advanceWalletsService: AdvanceWalletsService
Expand Down Expand Up @@ -3591,6 +3593,22 @@ export class AddEditExpensePage implements OnInit {
);
}

triggerNpsSurvey(): void {
const roles$ = from(this.authService.getRoles().pipe(shareReplay(1)));
const showNpsSurvey$ = this.launchDarklyService.getVariation('nps_survey', false);

forkJoin([roles$, showNpsSurvey$])
.pipe(
switchMap(([roles, showNpsSurvey]) => {
if (showNpsSurvey && !roles.includes('ADMIN')) {
this.refinerService.startSurvey({ actionName: 'Save Expense' });
}
return of(null);
})
)
.subscribe();
}

showSaveExpenseLoader(redirectedFrom: string): void {
this.saveExpenseLoader = redirectedFrom === 'SAVE_EXPENSE';
this.saveAndNewExpenseLoader = redirectedFrom === 'SAVE_AND_NEW_EXPENSE';
Expand All @@ -3603,6 +3621,8 @@ export class AddEditExpensePage implements OnInit {
this.saveAndNewExpenseLoader = false;
this.saveAndNextExpenseLoader = false;
this.saveAndPrevExpenseLoader = false;

this.triggerNpsSurvey();
}

checkIfReceiptIsMissingAndMandatory(redirectedFrom: string): Observable<boolean> {
Expand Down Expand Up @@ -4555,13 +4575,6 @@ export class AddEditExpensePage implements OnInit {
});
}

private filterVendor(vendor: string): string | null {
if (!vendor || this.vendorOptions?.length === 0) {
return vendor;
}
return this.vendorOptions?.find((option) => option.toLowerCase() === vendor.toLowerCase()) || null;
}

attachReceipts(data: { type: string; dataUrl: string | ArrayBuffer; actionSource?: string }): void {
if (data) {
const fileInfo = {
Expand Down Expand Up @@ -5234,4 +5247,11 @@ export class AddEditExpensePage implements OnInit {

await popover.present();
}

private filterVendor(vendor: string): string | null {
if (!vendor || this.vendorOptions?.length === 0) {
return vendor;
}
return this.vendorOptions?.find((option) => option.toLowerCase() === vendor.toLowerCase()) || null;
}
}
3 changes: 2 additions & 1 deletion src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { SpenderFileService } from 'src/app/core/services/platform/v1/spender/fi
import { AdvanceWalletsService } from 'src/app/core/services/platform/v1/spender/advance-wallets.service';
import { PAGINATION_SIZE } from 'src/app/constants';
import { SpenderService } from 'src/app/core/services/platform/v1/spender/spender.service';
import { HttpClientModule } from '@angular/common/http';

export function setFormValid(component) {
Object.defineProperty(component.fg, 'valid', {
Expand Down Expand Up @@ -230,7 +231,7 @@ describe('AddEditExpensePage', () => {

TestBed.configureTestingModule({
declarations: [AddEditExpensePage, MaskNumber, FySelectComponent, EllipsisPipe, DependentFieldComponent],
imports: [IonicModule.forRoot(), RouterTestingModule, RouterModule],
imports: [HttpClientModule, IonicModule.forRoot(), RouterTestingModule, RouterModule],
providers: [
FormBuilder,
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/fyle/view-team-report/view-team-report.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ describe('ViewTeamReportPageV2', () => {
});

it('should handle comments when user is not present', () => {
component.eou$ = of(null); // Simulate no user
component.eou$ = of(null);
component.setupComments({
...platformReportData,
comments: [
Expand All @@ -536,7 +536,7 @@ describe('ViewTeamReportPageV2', () => {
},
],
});
expect(component.estatuses.length).toBe(1); // Check that it processes correctly
expect(component.estatuses.length).toBe(1);
});
});

Expand Down

0 comments on commit 51355f4

Please sign in to comment.