Skip to content

Commit

Permalink
chore:removing bulkfyle from mobile-app (#3241)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Sishhhh and Snehasish authored Oct 25, 2024
1 parent 3c6949c commit 8dab1e1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 46 deletions.
20 changes: 4 additions & 16 deletions src/app/fyle/my-expenses/my-expenses.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
});
Expand All @@ -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;
Expand All @@ -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();
});
Expand All @@ -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;
Expand All @@ -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();
});
Expand All @@ -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));

Expand All @@ -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();
});
Expand Down
6 changes: 0 additions & 6 deletions src/app/fyle/my-expenses/my-expenses.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ export class MyExpensesPage implements OnInit {

isInstaFyleEnabled$: Observable<boolean>;

isBulkFyleEnabled$: Observable<boolean>;

isMileageEnabled$: Observable<boolean>;

isPerDiemEnabled$: Observable<boolean>;
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
{{ isBulkMode ? 'Bulk Mode' : 'Single Mode' }}
</div>
</div>
<div *ngIf="allowBulkFyle" class="camera-preview__bottom-container__icon-block text-center">
<div class="camera-preview__bottom-container__icon-block text-center">
<ng-container *ngIf="noOfReceipts === 0; else receiptPreviewIcon">
<div (click)="onSwitchMode()">
<img
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable custom-rules/prefer-resolve-to-reject-with */
import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';
import { CameraPreviewComponent } from './camera-preview.component';
Expand Down Expand Up @@ -89,6 +90,17 @@ describe('CameraPreviewComponent', () => {
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(() => {
Expand Down Expand Up @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export class CameraPreviewComponent implements OnInit, OnChanges {

@Input() allowGalleryUploads = true;

@Input() allowBulkFyle = true;

@Input() lastCapturedReceipt: string;

@Input() noOfReceipts = 0;
Expand Down Expand Up @@ -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();
Expand All @@ -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 = {
Expand All @@ -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');
Expand All @@ -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') {
Expand All @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[isBulkMode]="isBulkMode"
[isOffline]="isOffline$ | async"
[allowGalleryUploads]="allowGalleryUploads"
[allowBulkFyle]="allowBulkFyle"
[lastCapturedReceipt]="lastCapturedReceipt"
[noOfReceipts]="noOfReceipts"
[isBulkModePromptShown]="isBulkModePromptShown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,8 +43,6 @@ export class CaptureReceiptComponent implements OnInit, OnDestroy, AfterViewInit

@Input() allowGalleryUploads = true;

@Input() allowBulkFyle = true;

isBulkMode: boolean;

noOfReceipts = 0;
Expand Down

0 comments on commit 8dab1e1

Please sign in to comment.