UNPKG

@vendasta/store

Version:

Components and data for Store

161 lines (160 loc) 6.31 kB
import { VaPricingComponent } from './pricing.component'; describe('fromApi', function () { var testPricingComponent; describe('isFree', function () { beforeEach(function () { testPricingComponent = new VaPricingComponent(); }); it('returns null when pricing prices list is null', function () { var testPrice = { currency: 'EUR', prices: null }; testPricingComponent.pricing = testPrice; expect(testPricingComponent.isFree).toBe(null); }); it('returns null when pricing is null', function () { expect(testPricingComponent.isFree).toBe(null); }); it('return true when prices list contains a price of value 0', function () { var testPrice = { currency: 'EUR', prices: [ { price: 100, frequency: 'Once' }, { price: 0, frequency: null } ] }; testPricingComponent.pricing = testPrice; expect(testPricingComponent.isFree).toBe(true); }); it('return false when prices list contains prices that have values', function () { var testPrice = { currency: 'EUR', prices: [ { price: 100, frequency: 'Once' }, { price: 20, frequency: null } ] }; testPricingComponent.pricing = testPrice; expect(testPricingComponent.isFree).toBe(false); }); }); describe('shouldContactSales', function () { beforeEach(function () { testPricingComponent = new VaPricingComponent(); }); it('returns true if pricing doesnt exist', function () { expect(testPricingComponent.shouldContactSales).toBe(true); }); it('returns true if pricing prices list doesnt exist', function () { var testPrice = { currency: 'EUR', prices: null }; testPricingComponent.pricing = testPrice; expect(testPricingComponent.shouldContactSales).toBe(true); }); it('returns true if pricing prices list is empty', function () { var testPrice = { currency: 'EUR', prices: [] }; testPricingComponent.pricing = testPrice; expect(testPricingComponent.shouldContactSales).toBe(true); }); it('returns false if pricing prices list contains all prices', function () { var testPrice = { currency: 'EUR', prices: [ { price: 100, frequency: 'Once' }, { price: 20, frequency: null } ] }; testPricingComponent.pricing = testPrice; expect(testPricingComponent.shouldContactSales).toBe(false); }); }); describe('getCurrencySymbol', function () { beforeEach(function () { testPricingComponent = new VaPricingComponent(); }); it('returns default currency symbol for null input', function () { var result = testPricingComponent.getCurrencySymbol(null); expect(result).toBe('$'); }); it('returns default currency symbol for unrecognized symbol', function () { var result = testPricingComponent.getCurrencySymbol('YASSS'); expect(result).toBe('$'); }); it('returns EUR unicode currency symbol for EUR input', function () { var result = testPricingComponent.getCurrencySymbol('EUR'); expect(result).toBe('\u20AC'); }); }); describe('getDisplayPrice', function () { beforeEach(function () { testPricingComponent = new VaPricingComponent(); }); it('returns null for null input', function () { var result = testPricingComponent.getDisplayPrice(null); expect(result).toBe(null); }); it('returns formatted price for real number', function () { var result = testPricingComponent.getDisplayPrice(100); expect(result).toBe(result); }); }); describe('currencyString', function () { beforeEach(function () { testPricingComponent = new VaPricingComponent(); }); it('returns string of CAD for pricing.currency = CAD', function () { var testPrice = { currency: 'CAD', prices: [ { price: 100, frequency: 'Once' }, { price: 20, frequency: null } ] }; testPricingComponent.pricing = testPrice; var result = testPricingComponent.currencyString; expect(result).toBe('CAD'); }); it('returns null string for USD pricing.currency', function () { var testPrice = { currency: 'USD', prices: [ { price: 100, frequency: 'Once' }, { price: 20, frequency: null } ] }; testPricingComponent.pricing = testPrice; var result = testPricingComponent.currencyString; expect(result).toBe(''); }); it('returns null string for null input', function () { var testPrice = { currency: null, prices: [ { price: 100, frequency: 'Once' }, { price: 20, frequency: null } ] }; testPricingComponent.pricing = testPrice; var result = testPricingComponent.currencyString; expect(result).toBe(''); }); it('returns BRL for BRL currency', function () { var testPrice = { currency: 'BRL', prices: [ { price: 100, frequency: 'Once' }, { price: 20, frequency: null } ] }; testPricingComponent.pricing = testPrice; var result = testPricingComponent.currencyString; expect(result).toBe('BRL'); }); }); });