From 8dab1e1b984e920d75b60b0a14a5673f88bdd36e Mon Sep 17 00:00:00 2001 From: Snehasish Jena <142651781+Sishhhh@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:32:31 +0530 Subject: [PATCH] chore:removing bulkfyle from mobile-app (#3241) * chore:removing bulkfyle from mobile-app * fix: fixing the lint errors * adding test cases to increase code coverage * fixing lint errors --------- Co-authored-by: Snehasish --- .../fyle/my-expenses/my-expenses.page.spec.ts | 20 +++--------- src/app/fyle/my-expenses/my-expenses.page.ts | 6 ---- .../camera-preview.component.html | 2 +- .../camera-preview.component.spec.ts | 18 +++++++++-- .../camera-preview.component.ts | 32 +++++++++---------- .../capture-receipt.component.html | 1 - .../capture-receipt.component.ts | 3 +- 7 files changed, 36 insertions(+), 46 deletions(-) diff --git a/src/app/fyle/my-expenses/my-expenses.page.spec.ts b/src/app/fyle/my-expenses/my-expenses.page.spec.ts index 0db5d00a94..3f6c405b63 100644 --- a/src/app/fyle/my-expenses/my-expenses.page.spec.ts +++ b/src/app/fyle/my-expenses/my-expenses.page.spec.ts @@ -515,7 +515,7 @@ describe('MyExpensesPage', () => { inputElement = component.simpleSearchInput.nativeElement; }); - it('should set isNewReportsFlowEnabled, isInstaFyleEnabled, isBulkFyleEnabled, isMileageEnabled and isPerDiemEnabled to true if orgSettings and orgUserSettings properties are enabled', fakeAsync(() => { + it('should set isNewReportsFlowEnabled, isInstaFyleEnabled, isMileageEnabled and isPerDiemEnabled to true if orgSettings and orgUserSettings properties are enabled', fakeAsync(() => { component.ionViewWillEnter(); tick(500); expect(component.expensesTaskCount).toBe(10); @@ -526,9 +526,6 @@ describe('MyExpensesPage', () => { component.isInstaFyleEnabled$.subscribe((isInstaFyleEnabled) => { expect(isInstaFyleEnabled).toBeTrue(); }); - component.isBulkFyleEnabled$.subscribe((isBulkFyleEnabled) => { - expect(isBulkFyleEnabled).toBeTrue(); - }); component.isMileageEnabled$.subscribe((isMileageEnabled) => { expect(isMileageEnabled).toBeTrue(); }); @@ -537,7 +534,7 @@ describe('MyExpensesPage', () => { }); })); - it('should set isNewReportsFlowEnabled, isInstaFyleEnabled, isBulkFyleEnabled, isMileageEnabled and isPerDiemEnabled to false if orgSettings and orgUserSettings properties are disabled', fakeAsync(() => { + it('should set isNewReportsFlowEnabled, isInstaFyleEnabled, isMileageEnabled and isPerDiemEnabled to false if orgSettings and orgUserSettings properties are disabled', fakeAsync(() => { const mockOrgUserSettingsData = cloneDeep(orgUserSettingsData); const mockOrgSettingsData = cloneDeep(orgSettingsRes); mockOrgUserSettingsData.insta_fyle_settings.enabled = false; @@ -557,9 +554,6 @@ describe('MyExpensesPage', () => { component.isInstaFyleEnabled$.subscribe((isInstaFyleEnabled) => { expect(isInstaFyleEnabled).toBeFalse(); }); - component.isBulkFyleEnabled$.subscribe((isBulkFyleEnabled) => { - expect(isBulkFyleEnabled).toBeFalse(); - }); component.isMileageEnabled$.subscribe((isMileageEnabled) => { expect(isMileageEnabled).toBeFalse(); }); @@ -568,7 +562,7 @@ describe('MyExpensesPage', () => { }); })); - it('should set isNewReportsFlowEnabled, isInstaFyleEnabled, isBulkFyleEnabled, isMileageEnabled and isPerDiemEnabled to false if orgSettings and orgUserSettings properties are not allowed', fakeAsync(() => { + it('should set isNewReportsFlowEnabled, isInstaFyleEnabled, isMileageEnabled and isPerDiemEnabled to false if orgSettings and orgUserSettings properties are not allowed', fakeAsync(() => { const mockOrgUserSettingsData = cloneDeep(orgUserSettingsData); mockOrgUserSettingsData.insta_fyle_settings.allowed = false; mockOrgUserSettingsData.bulk_fyle_settings.allowed = false; @@ -584,9 +578,6 @@ describe('MyExpensesPage', () => { component.isInstaFyleEnabled$.subscribe((isInstaFyleEnabled) => { expect(isInstaFyleEnabled).toBeFalse(); }); - component.isBulkFyleEnabled$.subscribe((isBulkFyleEnabled) => { - expect(isBulkFyleEnabled).toBeTrue(); - }); component.isMileageEnabled$.subscribe((isMileageEnabled) => { expect(isMileageEnabled).toBeTrue(); }); @@ -595,7 +586,7 @@ describe('MyExpensesPage', () => { }); })); - it('should set isInstaFyleEnabled, isBulkFyleEnabled, isMileageEnabled and isPerDiemEnabled to undefined if orgUserSettings and orgSettings are undefined', fakeAsync(() => { + it('should set isInstaFyleEnabled, isMileageEnabled and isPerDiemEnabled to undefined if orgUserSettings and orgSettings are undefined', fakeAsync(() => { orgUserSettingsService.get.and.returnValue(of(undefined)); orgSettingsService.get.and.returnValue(of(undefined)); @@ -609,9 +600,6 @@ describe('MyExpensesPage', () => { component.isInstaFyleEnabled$.subscribe((isInstaFyleEnabled) => { expect(isInstaFyleEnabled).toBeUndefined(); }); - component.isBulkFyleEnabled$.subscribe((isBulkFyleEnabled) => { - expect(isBulkFyleEnabled).toBeUndefined(); - }); component.isMileageEnabled$.subscribe((isMileageEnabled) => { expect(isMileageEnabled).toBeUndefined(); }); diff --git a/src/app/fyle/my-expenses/my-expenses.page.ts b/src/app/fyle/my-expenses/my-expenses.page.ts index 2159878cfb..25e0c43c2d 100644 --- a/src/app/fyle/my-expenses/my-expenses.page.ts +++ b/src/app/fyle/my-expenses/my-expenses.page.ts @@ -111,8 +111,6 @@ export class MyExpensesPage implements OnInit { isInstaFyleEnabled$: Observable; - isBulkFyleEnabled$: Observable; - isMileageEnabled$: Observable; isPerDiemEnabled$: Observable; @@ -465,10 +463,6 @@ export class MyExpensesPage implements OnInit { ) ); - this.isBulkFyleEnabled$ = getOrgUserSettingsService$.pipe( - map((orgUserSettings) => orgUserSettings?.bulk_fyle_settings?.enabled) - ); - this.orgSettings$ = this.orgSettingsService.get().pipe(shareReplay(1)); this.specialCategories$ = this.categoriesService.getMileageOrPerDiemCategories().pipe(shareReplay(1)); diff --git a/src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.html b/src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.html index 09105d9e2b..aaef3165c3 100644 --- a/src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.html +++ b/src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.html @@ -68,7 +68,7 @@ {{ isBulkMode ? 'Bulk Mode' : 'Single Mode' }} -
+
{ expect(component.permissionDenied.emit).toHaveBeenCalledTimes(1); expect(cameraService.requestCameraPermissions).toHaveBeenCalledTimes(1); })); + + it('should start camera preview if device platform is web', fakeAsync(() => { + (component as any).devicePlatform = 'web'; + spyOn(component, 'startCameraPreview'); + + fixture.detectChanges(); + component.setUpAndStartCamera(); + + expect(component.startCameraPreview).toHaveBeenCalledTimes(1); + expect(cameraService.requestCameraPermissions).not.toHaveBeenCalled(); + })); }); it('startCameraPreview(): should start camera preview', fakeAsync(() => { @@ -211,16 +223,16 @@ describe('CameraPreviewComponent', () => { isBulkMode: new SimpleChange(false, true, true), }); - expect(component.showModeChangedMessage).toEqual(true); + expect(component.showModeChangedMessage).toBeTrue(); tick(1500); - expect(component.showModeChangedMessage).toEqual(false); + expect(component.showModeChangedMessage).toBeFalse(); })); it('should not change state if no change detected', () => { component.showModeChangedMessage = false; component.ngOnChanges({}); - expect(component.showModeChangedMessage).toEqual(false); + expect(component.showModeChangedMessage).toBeFalse(); }); }); }); diff --git a/src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.ts b/src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.ts index f41e549651..eecfabc35e 100644 --- a/src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.ts +++ b/src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.ts @@ -18,8 +18,6 @@ export class CameraPreviewComponent implements OnInit, OnChanges { @Input() allowGalleryUploads = true; - @Input() allowBulkFyle = true; - @Input() lastCapturedReceipt: string; @Input() noOfReceipts = 0; @@ -54,11 +52,11 @@ export class CameraPreviewComponent implements OnInit, OnChanges { private cameraPreviewService: CameraPreviewService ) {} - get CameraState() { + get CameraState(): typeof CameraState { return CameraState; } - setUpAndStartCamera() { + setUpAndStartCamera(): void { this.isIos = this.devicePlatform === 'ios'; if (this.devicePlatform === 'web') { this.startCameraPreview(); @@ -79,7 +77,7 @@ export class CameraPreviewComponent implements OnInit, OnChanges { } } - startCameraPreview() { + startCameraPreview(): void { if (![CameraState.STARTING, CameraState.RUNNING].includes(this.cameraState)) { this.cameraState = CameraState.STARTING; const cameraPreviewOptions: CameraPreviewOptions = { @@ -91,22 +89,22 @@ export class CameraPreviewComponent implements OnInit, OnChanges { disableAudio: true, }; - from(this.cameraPreviewService.start(cameraPreviewOptions)).subscribe((_) => { + from(this.cameraPreviewService.start(cameraPreviewOptions)).subscribe(() => { this.cameraState = CameraState.RUNNING; this.getFlashModes(); }); } } - stopCamera() { + stopCamera(): void { //Stop camera only if it is in RUNNING state if (this.cameraState === CameraState.RUNNING) { this.cameraState = CameraState.STOPPING; - from(this.cameraPreviewService.stop()).subscribe((_) => (this.cameraState = CameraState.STOPPED)); + from(this.cameraPreviewService.stop()).subscribe(() => (this.cameraState = CameraState.STOPPED)); } } - getFlashModes() { + getFlashModes(): void { if (this.devicePlatform !== 'web') { from(this.cameraPreviewService.getSupportedFlashModes()).subscribe((flashModes) => { const requiredFlashModesPresent = flashModes.result?.includes('on') && flashModes.result?.includes('off'); @@ -118,7 +116,7 @@ export class CameraPreviewComponent implements OnInit, OnChanges { } } - onToggleFlashMode() { + onToggleFlashMode(): void { if (this.devicePlatform !== 'web') { let nextActiveFlashMode: 'on' | 'off' = 'on'; if (this.flashMode === 'on') { @@ -131,37 +129,37 @@ export class CameraPreviewComponent implements OnInit, OnChanges { } } - onGalleryUpload() { + onGalleryUpload(): void { this.stopCamera(); this.galleryUpload.emit(); } - onSwitchMode() { + onSwitchMode(): void { this.switchMode.emit(); } - openReceiptPreview() { + openReceiptPreview(): void { this.stopCamera(); this.receiptPreview.emit(); } - onDismissCameraPreview() { + onDismissCameraPreview(): void { this.stopCamera(); this.dismissCameraPreview.emit(); } - onCaptureReceipt() { + onCaptureReceipt(): void { if (this.cameraState === CameraState.RUNNING) { this.captureReceipt.emit(); } } - ngOnInit() { + ngOnInit(): void { //Component is initialized with camera in STOPPED state this.cameraState = CameraState.STOPPED; } - ngOnChanges(changes: SimpleChanges) { + ngOnChanges(changes: SimpleChanges): void { if (changes.isBulkMode?.previousValue !== undefined) { this.showModeChangedMessage = true; setTimeout(() => { diff --git a/src/app/shared/components/capture-receipt/capture-receipt.component.html b/src/app/shared/components/capture-receipt/capture-receipt.component.html index 8ecb89c3f6..2f693e73fb 100644 --- a/src/app/shared/components/capture-receipt/capture-receipt.component.html +++ b/src/app/shared/components/capture-receipt/capture-receipt.component.html @@ -3,7 +3,6 @@ [isBulkMode]="isBulkMode" [isOffline]="isOffline$ | async" [allowGalleryUploads]="allowGalleryUploads" - [allowBulkFyle]="allowBulkFyle" [lastCapturedReceipt]="lastCapturedReceipt" [noOfReceipts]="noOfReceipts" [isBulkModePromptShown]="isBulkModePromptShown" diff --git a/src/app/shared/components/capture-receipt/capture-receipt.component.ts b/src/app/shared/components/capture-receipt/capture-receipt.component.ts index f896e8cd32..f818df909f 100644 --- a/src/app/shared/components/capture-receipt/capture-receipt.component.ts +++ b/src/app/shared/components/capture-receipt/capture-receipt.component.ts @@ -25,6 +25,7 @@ import { CameraService } from 'src/app/core/services/camera.service'; import { CameraPreviewService } from 'src/app/core/services/camera-preview.service'; import { ReceiptPreviewData } from 'src/app/core/models/receipt-preview-data.model'; +// eslint-disable-next-line custom-rules/prefer-semantic-extension-name type Image = Partial<{ source: string; base64Image: string; @@ -42,8 +43,6 @@ export class CaptureReceiptComponent implements OnInit, OnDestroy, AfterViewInit @Input() allowGalleryUploads = true; - @Input() allowBulkFyle = true; - isBulkMode: boolean; noOfReceipts = 0;