-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Select Currency Linting (#2426)
* fixed linting * test: Code Coverage: My-Profile/ Select Currency #1 (#2427) * coverage at 95 * coverage at 100 * resolved comments --------- Co-authored-by: Jay Budhadev <[email protected]> --------- Co-authored-by: Jay Budhadev <[email protected]>
- Loading branch information
Showing
3 changed files
with
146 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 104 additions & 14 deletions
118
src/app/fyle/my-profile/select-currency/select-currency.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,116 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { IonicModule } from '@ionic/angular'; | ||
import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing'; | ||
import { IonicModule, ModalController } from '@ionic/angular'; | ||
|
||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | ||
import { of, take } from 'rxjs'; | ||
import { getElementRef } from 'src/app/core/dom-helpers'; | ||
import { apiAllCurrencies2, selectedCurrencies } from 'src/app/core/mock-data/currency.data'; | ||
import { CurrencyService } from 'src/app/core/services/currency.service'; | ||
import { LoaderService } from 'src/app/core/services/loader.service'; | ||
import { SelectCurrencyComponent } from './select-currency.component'; | ||
|
||
xdescribe('SelectCurrencyComponent', () => { | ||
describe('SelectCurrencyComponent', () => { | ||
let component: SelectCurrencyComponent; | ||
let fixture: ComponentFixture<SelectCurrencyComponent>; | ||
let currencyService: jasmine.SpyObj<CurrencyService>; | ||
let modalController: jasmine.SpyObj<ModalController>; | ||
let loaderService: jasmine.SpyObj<LoaderService>; | ||
|
||
beforeEach( | ||
waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [SelectCurrencyComponent], | ||
imports: [IonicModule.forRoot()], | ||
}).compileComponents(); | ||
beforeEach(waitForAsync(() => { | ||
const currencyServiceSpy = jasmine.createSpyObj('CurrencyService', ['getAll']); | ||
const modalControllerSpy = jasmine.createSpyObj('ModalController', ['dismiss']); | ||
const loaderServiceSpy = jasmine.createSpyObj('LoaderService', ['showLoader', 'hideLoader']); | ||
|
||
fixture = TestBed.createComponent(SelectCurrencyComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}) | ||
); | ||
TestBed.configureTestingModule({ | ||
declarations: [SelectCurrencyComponent], | ||
imports: [IonicModule.forRoot()], | ||
providers: [ | ||
{ | ||
provide: CurrencyService, | ||
useValue: currencyServiceSpy, | ||
}, | ||
{ | ||
provide: ModalController, | ||
useValue: modalControllerSpy, | ||
}, | ||
{ | ||
provide: LoaderService, | ||
useValue: loaderServiceSpy, | ||
}, | ||
], | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(SelectCurrencyComponent); | ||
component = fixture.componentInstance; | ||
|
||
currencyService = TestBed.inject(CurrencyService) as jasmine.SpyObj<CurrencyService>; | ||
modalController = TestBed.inject(ModalController) as jasmine.SpyObj<ModalController>; | ||
loaderService = TestBed.inject(LoaderService) as jasmine.SpyObj<LoaderService>; | ||
})); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('ngOnInit(): should setup currencies', fakeAsync(() => { | ||
loaderService.showLoader.and.resolveTo(); | ||
loaderService.hideLoader.and.resolveTo(); | ||
currencyService.getAll.and.returnValue(of(apiAllCurrencies2)); | ||
|
||
component.ngOnInit(); | ||
tick(500); | ||
|
||
expect(loaderService.showLoader).toHaveBeenCalledTimes(1); | ||
expect(loaderService.hideLoader).toHaveBeenCalledTimes(1); | ||
expect(currencyService.getAll).toHaveBeenCalledTimes(1); | ||
})); | ||
|
||
it('ngAfterViewInit(): should update the filteredCurrencies$', fakeAsync(() => { | ||
component.searchBarRef = getElementRef(fixture, '.selection-modal--search-input'); | ||
const inputElement = component.searchBarRef.nativeElement as HTMLInputElement; | ||
const mockCurrencies = [ | ||
{ shortCode: 'USD', longName: 'US Dollar' }, | ||
{ shortCode: 'INR', longName: 'Indian National Rupees' }, | ||
]; | ||
component.currencies$ = of(mockCurrencies); | ||
component.ngAfterViewInit(); | ||
tick(500); | ||
|
||
inputElement.value = ''; | ||
inputElement.dispatchEvent(new Event('keyup')); | ||
component.filteredCurrencies$.pipe(take(1)).subscribe((currencies) => { | ||
expect(currencies).toEqual(mockCurrencies); | ||
}); | ||
tick(500); | ||
|
||
inputElement.value = 'US'; | ||
inputElement.dispatchEvent(new Event('keyup')); | ||
component.filteredCurrencies$.pipe(take(1)).subscribe((currencies) => { | ||
expect(currencies).toEqual([mockCurrencies[0]]); | ||
}); | ||
tick(500); | ||
})); | ||
|
||
it('closeModal(): should close modal', () => { | ||
component.closeModal(); | ||
|
||
expect(modalController.dismiss).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('onCurrencySelect(): should select currency', () => { | ||
component.onCurrencySelect(selectedCurrencies[0]); | ||
|
||
expect(modalController.dismiss).toHaveBeenCalledOnceWith({ | ||
selectedCurrency: selectedCurrencies[0], | ||
}); | ||
}); | ||
|
||
it('clearValue(): should clear value', () => { | ||
component.searchBarRef = getElementRef(fixture, '.selection-modal--search-input'); | ||
component.clearValue(); | ||
|
||
expect(component.value).toEqual(''); | ||
expect(component.searchBarRef.nativeElement.value).toEqual(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters