// File imported from https://bitbucket.org/arrowecommerce/arrow-app-checkout import { DecimalPipe } from '@angular/common'; import { TestBed, async } from '@angular/core/testing'; import { ConfigService } from '@arrow/bom/config'; import { CartHandoverService, Utils } from '@arrow/bom/core'; import { of } from 'rxjs'; import { CurrencyConverterPipe } from './currency-converter.pipe'; describe('CurrencyConverterPipe', () => { let pipe: CurrencyConverterPipe; const configServiceSpyObj = jasmine.createSpyObj('ConfigService', ['getTarget']) as jasmine.SpyObj; // configServiceSpyObj.getTarget.and.returnValue('myarrow'); const utilsSpyObj = jasmine.createSpyObj('Utils', ['getCurrencySymbol']) as jasmine.SpyObj; beforeEach(async(() => { TestBed.configureTestingModule({ providers: [ CurrencyConverterPipe, { provide: CartHandoverService, useValue: {} }, { provide: ConfigService, useValue: configServiceSpyObj }, { provide: Utils, useValue: utilsSpyObj }, DecimalPipe ] }).compileComponents(); pipe = TestBed.inject(CurrencyConverterPipe); })); it('create an instance', () => { expect(pipe).toBeTruthy(); }); describe('transform', () => { it('should convert 1 for currency AUD', () => { utilsSpyObj.getCurrencySymbol.and.returnValue('AUD'); pipe.transform(1, '1.2-4').subscribe((result) => { expect(result).toEqual('AUD1.00'); }); }); // it('should convert 1 for currency AUD to 1.3195676040874926', () => { // expect(pipe.transform(1, 'AUD')).toBe(of(1.3195676040874926)); // }); // it('should convert 1 for currency BRL to 3.130478337089907', () => { // expect(pipe.transform(1, 'BRL')).toBe(of(3.130478337089907)); // }); // it('should convert 10 for currency BRL to 31.30478337089907', () => { // expect(pipe.transform(10, 'BRL')).toBe(of(3.130478337089907 * 10)); // }); // it('should convert 10 for currency USD to 10', () => { // expect(pipe.transform(10, 'USD')).toBe(of(10)); // }); // it('should convert 10 for currency BRL to 31.30478337089907 with multiple call', () => { // expect(pipe.transform(1, 'AUD')).toBe(of(1.3195676040874926)); // expect(pipe.transform(10, 'BRL')).toBe(of(3.130478337089907 * 10)); // }); }); });