1 | import { VaPricingComponent } from './pricing.component';
|
2 | describe('fromApi', function () {
|
3 | var testPricingComponent;
|
4 | describe('isFree', function () {
|
5 | beforeEach(function () {
|
6 | testPricingComponent = new VaPricingComponent();
|
7 | });
|
8 | it('returns null when pricing prices list is null', function () {
|
9 | var testPrice = {
|
10 | currency: 'EUR',
|
11 | prices: null
|
12 | };
|
13 | testPricingComponent.pricing = testPrice;
|
14 | expect(testPricingComponent.isFree).toBe(null);
|
15 | });
|
16 | it('returns null when pricing is null', function () {
|
17 | expect(testPricingComponent.isFree).toBe(null);
|
18 | });
|
19 | it('return true when prices list contains a price of value 0', function () {
|
20 | var testPrice = {
|
21 | currency: 'EUR',
|
22 | prices: [
|
23 | { price: 100, frequency: 'Once' },
|
24 | { price: 0, frequency: null }
|
25 | ]
|
26 | };
|
27 | testPricingComponent.pricing = testPrice;
|
28 | expect(testPricingComponent.isFree).toBe(true);
|
29 | });
|
30 | it('return false when prices list contains prices that have values', function () {
|
31 | var testPrice = {
|
32 | currency: 'EUR',
|
33 | prices: [
|
34 | { price: 100, frequency: 'Once' },
|
35 | { price: 20, frequency: null }
|
36 | ]
|
37 | };
|
38 | testPricingComponent.pricing = testPrice;
|
39 | expect(testPricingComponent.isFree).toBe(false);
|
40 | });
|
41 | });
|
42 | describe('shouldContactSales', function () {
|
43 | beforeEach(function () {
|
44 | testPricingComponent = new VaPricingComponent();
|
45 | });
|
46 | it('returns true if pricing doesnt exist', function () {
|
47 | expect(testPricingComponent.shouldContactSales).toBe(true);
|
48 | });
|
49 | it('returns true if pricing prices list doesnt exist', function () {
|
50 | var testPrice = {
|
51 | currency: 'EUR',
|
52 | prices: null
|
53 | };
|
54 | testPricingComponent.pricing = testPrice;
|
55 | expect(testPricingComponent.shouldContactSales).toBe(true);
|
56 | });
|
57 | it('returns true if pricing prices list is empty', function () {
|
58 | var testPrice = {
|
59 | currency: 'EUR',
|
60 | prices: []
|
61 | };
|
62 | testPricingComponent.pricing = testPrice;
|
63 | expect(testPricingComponent.shouldContactSales).toBe(true);
|
64 | });
|
65 | it('returns false if pricing prices list contains all prices', function () {
|
66 | var testPrice = {
|
67 | currency: 'EUR',
|
68 | prices: [
|
69 | { price: 100, frequency: 'Once' },
|
70 | { price: 20, frequency: null }
|
71 | ]
|
72 | };
|
73 | testPricingComponent.pricing = testPrice;
|
74 | expect(testPricingComponent.shouldContactSales).toBe(false);
|
75 | });
|
76 | });
|
77 | describe('getCurrencySymbol', function () {
|
78 | beforeEach(function () {
|
79 | testPricingComponent = new VaPricingComponent();
|
80 | });
|
81 | it('returns default currency symbol for null input', function () {
|
82 | var result = testPricingComponent.getCurrencySymbol(null);
|
83 | expect(result).toBe('$');
|
84 | });
|
85 | it('returns default currency symbol for unrecognized symbol', function () {
|
86 | var result = testPricingComponent.getCurrencySymbol('YASSS');
|
87 | expect(result).toBe('$');
|
88 | });
|
89 | it('returns EUR unicode currency symbol for EUR input', function () {
|
90 | var result = testPricingComponent.getCurrencySymbol('EUR');
|
91 | expect(result).toBe('\u20AC');
|
92 | });
|
93 | });
|
94 | describe('getDisplayPrice', function () {
|
95 | beforeEach(function () {
|
96 | testPricingComponent = new VaPricingComponent();
|
97 | });
|
98 | it('returns null for null input', function () {
|
99 | var result = testPricingComponent.getDisplayPrice(null);
|
100 | expect(result).toBe(null);
|
101 | });
|
102 | it('returns formatted price for real number', function () {
|
103 | var result = testPricingComponent.getDisplayPrice(100);
|
104 | expect(result).toBe(result);
|
105 | });
|
106 | });
|
107 | describe('currencyString', function () {
|
108 | beforeEach(function () {
|
109 | testPricingComponent = new VaPricingComponent();
|
110 | });
|
111 | it('returns string of CAD for pricing.currency = CAD', function () {
|
112 | var testPrice = {
|
113 | currency: 'CAD',
|
114 | prices: [
|
115 | { price: 100, frequency: 'Once' },
|
116 | { price: 20, frequency: null }
|
117 | ]
|
118 | };
|
119 | testPricingComponent.pricing = testPrice;
|
120 | var result = testPricingComponent.currencyString;
|
121 | expect(result).toBe('CAD');
|
122 | });
|
123 | it('returns null string for USD pricing.currency', function () {
|
124 | var testPrice = {
|
125 | currency: 'USD',
|
126 | prices: [
|
127 | { price: 100, frequency: 'Once' },
|
128 | { price: 20, frequency: null }
|
129 | ]
|
130 | };
|
131 | testPricingComponent.pricing = testPrice;
|
132 | var result = testPricingComponent.currencyString;
|
133 | expect(result).toBe('');
|
134 | });
|
135 | it('returns null string for null input', function () {
|
136 | var testPrice = {
|
137 | currency: null,
|
138 | prices: [
|
139 | { price: 100, frequency: 'Once' },
|
140 | { price: 20, frequency: null }
|
141 | ]
|
142 | };
|
143 | testPricingComponent.pricing = testPrice;
|
144 | var result = testPricingComponent.currencyString;
|
145 | expect(result).toBe('');
|
146 | });
|
147 | it('returns BRL for BRL currency', function () {
|
148 | var testPrice = {
|
149 | currency: 'BRL',
|
150 | prices: [
|
151 | { price: 100, frequency: 'Once' },
|
152 | { price: 20, frequency: null }
|
153 | ]
|
154 | };
|
155 | testPricingComponent.pricing = testPrice;
|
156 | var result = testPricingComponent.currencyString;
|
157 | expect(result).toBe('BRL');
|
158 | });
|
159 | });
|
160 | });
|