Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha committed Feb 21, 2024
1 parent 68e0217 commit daf794d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 34 deletions.
4 changes: 4 additions & 0 deletions src/app/core/mock-data/virtual-cards-combined-request.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const virtualCardCombinedRequest = {
virtualCardIds: ['vcgNQmrZvGhL'],
includeCurrentAmount: true,
};
9 changes: 3 additions & 6 deletions src/app/core/services/virtual-cards.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CardDetailsResponse } from '../models/card-details-response.model';
import { virtualCardResponse, virtualCardUndefinedResponse } from '../mock-data/virtual-card-response.data';
import { VirtualCardsCombinedRequest } from '../models/virtual-cards-combined-request.model';
import { cardDetailsRes } from '../mock-data/platform-corporate-card-detail.data';
import { virtualCardCombinedRequest } from '../mock-data/virtual-cards-combined-request.data';

describe('VirtualCardsService', () => {
let virtualCardsService: VirtualCardsService;
Expand Down Expand Up @@ -113,11 +114,7 @@ describe('VirtualCardsService', () => {
});
});

it('getCardDetailsInSerial(): should return serialised card details', () => {
const virtualCardsCombinedRequest: VirtualCardsCombinedRequest = {
virtualCardIds: ['vcgNQmrZvGhL'],
includeCurrentAmount: true,
};
it('getCardDetailsMap(): should return serialised card details', () => {
const expectedCardDetailsResponse = {
cardDetails: virtualCardDetailsResponse.data,
currentAmount: virtualCardCurrentAmountResponse.data,
Expand All @@ -133,7 +130,7 @@ describe('VirtualCardsService', () => {
};

spyOn(virtualCardsService, 'getCombinedCardDetails').and.returnValue(of(expectedCardDetailsResponse));
virtualCardsService.getCardDetailsInSerial(virtualCardsCombinedRequest).subscribe((res) => {
virtualCardsService.getCardDetailsMap(virtualCardCombinedRequest).subscribe((res) => {
expect(res).toEqual(expectedResponse);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(addCardClick)="openAddCorporateCardPopover()"
></app-spent-cards>
</ng-container>
<ng-container *ngIf="isVirtualCardsEnabled.enabled === true">
<ng-container *ngIf="isVirtualCardsEnabled.enabled">
<ng-container *ngIf="virtualCardDetails$ | async as cardDetails">
<app-spent-cards
[cardDetails]="cardDetails"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('CardStatsComponent', () => {
'clearCache',
]);
const popoverControllerSpy = jasmine.createSpyObj('PopoverController', ['create']);
const virtualCardsServiceSpy = jasmine.createSpyObj('VirtualCardsService', ['getCardDetailsInSerial']);
const virtualCardsServiceSpy = jasmine.createSpyObj('VirtualCardsService', ['getCardDetailsMap']);

TestBed.configureTestingModule({
declarations: [CardStatsComponent, MockSpentCardsComponent, MockAddCardComponent],
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('CardStatsComponent', () => {
it('should display the cards swiper when cards are present for the user', () => {
component.ngOnInit();
component.init();

component.isVirtualCardsEnabled$ = of({ enabled: false });

fixture.detectChanges();
Expand All @@ -203,7 +203,7 @@ describe('CardStatsComponent', () => {
it('should set virtualCardDetails$ when isVirtualCardsEnabled is true', fakeAsync(() => {
component.isVirtualCardsEnabled$ = of({ enabled: true });

virtualCardsService.getCardDetailsInSerial.and.returnValue(of(virtualCardCombinedResponse));
virtualCardsService.getCardDetailsMap.and.returnValue(of(virtualCardCombinedResponse));

component.ngOnInit();
component.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ion-header>

<div *ngIf="isVirtualCardsEnabled$ | async as isVirtualCardsEnabled">
<div *ngIf="isVirtualCardsEnabled.enabled === true" class="manage-corporate-cards__segment-container">
<div *ngIf="isVirtualCardsEnabled.enabled" class="manage-corporate-cards__segment-container">
<ion-segment (ionChange)="segmentChanged($event)" [value]="segmentValue" class="manage-corporate-cards__segment">
<ion-segment-button [value]="Segment.CORPORATE_CARDS" class="text-capitalize">Corporate Cards</ion-segment-button>
<ion-segment-button [value]="Segment.VIRTUAL_CARDS" class="text-capitalize">Virtual Cards</ion-segment-button>
Expand Down Expand Up @@ -63,9 +63,7 @@
*ngIf="isVirtualCardsEnabled$ | async as isVirtualCardsEnabled"
class="manage-corporate-cards__cards manage-corporate-cards__cards-list"
>
<ng-container
*ngIf="isVirtualCardsEnabled.enabled === true && corporateCards$ | async as corporateCards; else shimmers"
>
<ng-container *ngIf="isVirtualCardsEnabled.enabled && corporateCards$ | async as corporateCards; else shimmers">
<ng-container *ngIf="virtualCardDetails$ | async as virtualCardDetails; else shimmers">
<div *ngFor="let corporateCard of corporateCards" class="manage-corporate-cards__virtual-card">
<app-virtual-card
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('ManageCorporateCardsPage', () => {
const orgUserSettingsServiceSpy = jasmine.createSpyObj('OrgUserSettingsService', ['get']);
const realTimeFeedServiceSpy = jasmine.createSpyObj('RealTimeFeedService', ['getCardType', 'unenroll']);
const trackingServiceSpy = jasmine.createSpyObj('TrackingService', ['cardUnenrolled']);
const virtualCardsServiceSpy = jasmine.createSpyObj('TrackingService', ['getCardDetailsInSerial']);
const virtualCardsServiceSpy = jasmine.createSpyObj('TrackingService', ['getCardDetailsMap']);

TestBed.configureTestingModule({
declarations: [ManageCorporateCardsPage, MockCorporateCardComponent],
Expand Down Expand Up @@ -203,14 +203,14 @@ describe('ManageCorporateCardsPage', () => {

describe('segmentChanged():', () => {
it('should show Virtual Card page', () => {
component.ionViewWillEnter();
component.segmentChanged({
detail: {
value: '1',
},
} as SegmentCustomEvent);
expect(component.segmentValue).toEqual(ManageCardsPageSegment.VIRTUAL_CARDS);
});

it('should show Corporate Card page', () => {
component.segmentChanged({
detail: {
Expand All @@ -226,7 +226,7 @@ describe('ManageCorporateCardsPage', () => {
corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([virtualCard]));
component.isVirtualCardsEnabled$ = of({ enabled: true });

virtualCardsService.getCardDetailsInSerial.and.returnValue(of(virtualCardCombinedResponse));
virtualCardsService.getCardDetailsMap.and.returnValue(of(virtualCardCombinedResponse));

component.ionViewWillEnter();
component.virtualCardDetails$.subscribe((virtualCardDetailsRes) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,26 @@ describe('VirtualCardComponent', () => {
expect(component).toBeTruthy();
});

it('copyToClipboard(): Should copy content to clipboard and trigger toast message', fakeAsync(() => {
spyOn(component, 'copyToClipboard').and.callThrough();
clipboardService.writeString.and.resolveTo();
component.copyToClipboard('1234');
describe('copyToClipboard(): ', () => {
it('should copy content to clipboard and trigger toast message', fakeAsync(() => {
spyOn(component, 'copyToClipboard').and.callThrough();
clipboardService.writeString.and.resolveTo();
component.copyToClipboard('1234');

expect(component.copyToClipboard).toHaveBeenCalledOnceWith('1234');
expect(clipboardService.writeString).toHaveBeenCalledOnceWith('1234');
}));
expect(component.copyToClipboard).toHaveBeenCalledOnceWith('1234');
expect(clipboardService.writeString).toHaveBeenCalledOnceWith('1234');
}));

it('should copy cvv on cvv copy icon tap', () => {
component.cvv = '1234';
const cvvCopyIcon = getElementBySelector(fixture, '.virtual-card__card-fields__cvv-copy-icon');
const tapSpy = spyOn(component, 'copyToClipboard');

cvvCopyIcon.dispatchEvent(new Event('tap'));

expect(tapSpy).toHaveBeenCalledOnceWith(component.cvv);
});
});

it('showToastMessage(): Should show toast message', () => {
const message = 'Copied Successfully!';
Expand Down Expand Up @@ -76,16 +88,6 @@ describe('VirtualCardComponent', () => {
);
});

it('copyToClipboard(): should copy cvv on cvv copy icon tap', () => {
component.cvv = '1234';
const cvvCopyIcon = getElementBySelector(fixture, '.virtual-card__card-fields__cvv-copy-icon');
const tapSpy = spyOn(component, 'copyToClipboard');

cvvCopyIcon.dispatchEvent(new Event('tap'));

expect(tapSpy).toHaveBeenCalledOnceWith(component.cvv);
});

describe('template', () => {
it('should hide cvv and call method to copy text to clipboard', () => {
component.cvv = '1234';
Expand Down

0 comments on commit daf794d

Please sign in to comment.