Skip to content

Commit

Permalink
test: some branches in add-edit-mileage page (#2521)
Browse files Browse the repository at this point in the history
* test: some branches in add-edit-mileage page

* minor
  • Loading branch information
suyashpatil78 authored Oct 17, 2023
1 parent de09c10 commit 8b0ee2d
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 41 deletions.
15 changes: 15 additions & 0 deletions src/app/core/mock-data/org-category.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1160,3 +1160,18 @@ export const expectedOrgCategoryByName2: OrgCategory = {
sub_category: 'Business',
updated_at: new Date('2022-07-01T05:51:31.800Z'),
};

export const mileageCategoryWithoutId: OrgCategory[] = [
{
code: '93',
created_at: new Date('2021-05-18T11:40:38.576Z'),
displayName: 'Business',
enabled: true,
fyle_category: 'Mileage',
id: undefined,
name: 'Business',
org_id: 'orrjqbDbeP9p',
sub_category: 'Business',
updated_at: new Date('2022-07-01T05:51:31.800Z'),
},
];
8 changes: 8 additions & 0 deletions src/app/core/mock-data/unflattened-txn.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3554,3 +3554,11 @@ export const newMileageExpFromForm3: UnflattenedTransaction = {
],
},
};

export const unflattenedMileageDataWithPolicyAmount: UnflattenedTransaction = {
...unflattenedTxnData,
tx: {
...unflattenedTxnData.tx,
policy_amount: 100,
},
};
18 changes: 17 additions & 1 deletion src/app/fyle/add-edit-mileage/add-edit-mileage-1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { policyExpense2 } from 'src/app/core/mock-data/expense.data';
import { individualExpPolicyStateData2 } from 'src/app/core/mock-data/individual-expense-policy-state.data';
import { locationData1, locationData2, locationData3 } from 'src/app/core/mock-data/location.data';
import { properties } from 'src/app/core/mock-data/modal-properties.data';
import { mileageCategories, transformedOrgCategoryById } from 'src/app/core/mock-data/org-category.data';
import {
mileageCategories,
mileageCategoryWithoutId,
transformedOrgCategoryById,
} from 'src/app/core/mock-data/org-category.data';
import { orgUserSettingsData } from 'src/app/core/mock-data/org-user-settings.data';
import { outboxQueueData1 } from 'src/app/core/mock-data/outbox-queue.data';
import { splitPolicyExp4 } from 'src/app/core/mock-data/policy-violation.data';
Expand Down Expand Up @@ -402,6 +406,18 @@ export function TestCases1(getTestBed) {
done();
});
});

it('should return undefined if category id is not defined', (done) => {
categoriesService.getAll.and.returnValue(of(mileageCategoryWithoutId));

const projectCategoryIds = component.getProjectCategoryIds();

projectCategoryIds.subscribe((expectedProjectCategoryIds) => {
expect(expectedProjectCategoryIds).toEqual([undefined]);
expect(categoriesService.getAll).toHaveBeenCalledTimes(1);
done();
});
});
});

describe('saveExpenseAndGotoNext():', () => {
Expand Down
37 changes: 37 additions & 0 deletions src/app/fyle/add-edit-mileage/add-edit-mileage-2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,43 @@ export function TestCases2(getTestBed) {
});
});

it('should get a new expense object if org user mileage service settings returns undefined', (done) => {
const date = new Date('2023-08-21T07:43:15.592Z');
jasmine.clock().mockDate(date);
transactionService.getDefaultVehicleType.and.returnValue(of('CAR'));
mileageService.getOrgUserMileageSettings.and.returnValue(of(undefined));
orgSettingsService.get.and.returnValue(of(cloneDeep(orgSettingsParams2)));
orgUserSettingsService.get.and.returnValue(of(orgUserSettingsData));
component.recentlyUsedValues$ = of(recentlyUsedRes);
component.mileageRates$ = of(unfilteredMileageRatesData);
spyOn(component, 'getMileageByVehicleType').and.returnValue(filterEnabledMileageRatesData[0]);
authService.getEou.and.resolveTo(apiEouRes);
locationService.getCurrentLocation.and.returnValue(of(coordinatesData1));
spyOn(component, 'getMileageCategories').and.returnValue(
of({
defaultMileageCategory: mileageCategories2[0],
mileageCategories: [mileageCategories2[1]],
})
);
component.homeCurrency$ = of('USD');
fixture.detectChanges();

const newExpense = component.getNewExpense();

newExpense.subscribe((expectedNewExpense) => {
expect(expectedNewExpense).toEqual(newExpenseMileageData1);
expect(transactionService.getDefaultVehicleType).toHaveBeenCalledTimes(1);
expect(mileageService.getOrgUserMileageSettings).toHaveBeenCalledTimes(1);
expect(orgSettingsService.get).toHaveBeenCalledTimes(3);
expect(orgUserSettingsService.get).toHaveBeenCalledTimes(2);
expect(locationService.getCurrentLocation).toHaveBeenCalledTimes(1);
expect(authService.getEou).toHaveBeenCalledTimes(2);
expect(component.getMileageByVehicleType).toHaveBeenCalledOnceWith(unfilteredMileageRatesData, 'bicycle');
expect(component.getMileageCategories).toHaveBeenCalledTimes(1);
done();
});
});

afterEach(function () {
jasmine.clock().uninstall();
});
Expand Down
Loading

0 comments on commit 8b0ee2d

Please sign in to comment.