Skip to content

Commit

Permalink
Merge pull request #696 from ain/fix/price-alongside-price-suffix
Browse files Browse the repository at this point in the history
Fix #695 undefined displayed if price is empty
  • Loading branch information
ain authored Nov 1, 2023
2 parents b0c55d8 + 4a1fd67 commit d5bd85b
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/smartbanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ export default class SmartBanner {
return '';
}

get price() {
if (this.options.price && this.options.price !== '') {
return this.options.price;
} else {
return '';
}
}

get icon() {
if (this.platform === 'android') {
return this.options.iconGoogle;
Expand Down Expand Up @@ -139,7 +147,7 @@ export default class SmartBanner {
<div>
<div class="smartbanner__info__title">${this.options.title}</div>
<div class="smartbanner__info__author">${this.options.author}</div>
<div class="smartbanner__info__price">${this.options.price}${this.priceSuffix}</div>
<div class="smartbanner__info__price">${this.price}${this.priceSuffix}</div>
</div>
</div>
<a href="${this.buttonUrl}" target="_blank" class="smartbanner__button js_smartbanner__button" rel="noopener" aria-label="${this.options.button}"><span class="smartbanner__button__label">${this.options.button}</span></a>
Expand Down
125 changes: 125 additions & 0 deletions test/spec/smartbanner_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,60 @@ describe('SmartBanner', function() {
</body>
</html>`;

const HTML_WITH_EMPTY_PRICE = `<!doctype html>
<html style="margin-top:10px;">
<head>
<meta charset="utf-8">
<meta name="smartbanner:title" content="Smart Application">
<meta name="smartbanner:author" content="SmartBanner Contributors">
<meta name="smartbanner:price" content="">
<meta name="smartbanner:icon-apple" content="icon--apple.jpg">
<meta name="smartbanner:icon-google" content="icon--google.jpg">
<meta name="smartbanner:button" content="View">
<meta name="smartbanner:button-url-apple" content="https://itunes.apple.com/us/genre/ios/id36?mt=8">
<meta name="smartbanner:button-url-google" content="https://play.google.com/store">
<meta name="smartbanner:close-label" content="Close Smart App Banner">
</head>
<body>
</body>
</html>`;

const HTML_WITHOUT_PRICE = `<!doctype html>
<html style="margin-top:10px;">
<head>
<meta charset="utf-8">
<meta name="smartbanner:title" content="Smart Application">
<meta name="smartbanner:author" content="SmartBanner Contributors">
<meta name="smartbanner:icon-apple" content="icon--apple.jpg">
<meta name="smartbanner:icon-google" content="icon--google.jpg">
<meta name="smartbanner:button" content="View">
<meta name="smartbanner:button-url-apple" content="https://itunes.apple.com/us/genre/ios/id36?mt=8">
<meta name="smartbanner:button-url-google" content="https://play.google.com/store">
<meta name="smartbanner:close-label" content="Close Smart App Banner">
<meta name="smartbanner:price-suffix-apple" content=" - On the App Store">
<meta name="smartbanner:price-suffix-google" content=" - In Google Play">
</head>
<body>
</body>
</html>`;

const HTML_WITHOUT_PRICE_AND_SUFFIX = `<!doctype html>
<html style="margin-top:10px;">
<head>
<meta charset="utf-8">
<meta name="smartbanner:title" content="Smart Application">
<meta name="smartbanner:author" content="SmartBanner Contributors">
<meta name="smartbanner:icon-apple" content="icon--apple.jpg">
<meta name="smartbanner:icon-google" content="icon--google.jpg">
<meta name="smartbanner:button" content="View">
<meta name="smartbanner:button-url-apple" content="https://itunes.apple.com/us/genre/ios/id36?mt=8">
<meta name="smartbanner:button-url-google" content="https://play.google.com/store">
<meta name="smartbanner:close-label" content="Close Smart App Banner">
</head>
<body>
</body>
</html>`;

const SCRIPTS = `<script>window.conclude();</script>`;
const SCRIPTS_JQUERY_MOBILE = `<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
Expand Down Expand Up @@ -708,6 +762,77 @@ describe('SmartBanner', function() {

});

context('without price', function() {

context('with price suffixes', function() {

context('on unknown platform', function() {

before(function() {
const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_UNKNOWN });
global.window = new JSDOM(HTML_WITHOUT_PRICE, { resources: resourceLoader }).window;
global.document = window.document;
global.getComputedStyle = window.getComputedStyle;
global.Event = window.Event;
smartbanner = new SmartBanner();
});

it('expected to have no price', function() {
expect(smartbanner.price).to.be.empty;
});

it('expected to have no price suffix', function() {
expect(smartbanner.priceSuffix).to.be.empty;
});

});

context('on known platform', function() {

before(function() {
const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_IPOD });
global.window = new JSDOM(HTML_WITHOUT_PRICE, { resources: resourceLoader }).window;
global.document = window.document;
global.getComputedStyle = window.getComputedStyle;
global.Event = window.Event;
smartbanner = new SmartBanner();
});

it('expected to have no price', function() {
expect(smartbanner.price).to.be.empty;
});

it('expected to have price suffix', function() {
expect(smartbanner.priceSuffix).to.not.be.empty;
});

});

});

context('without price suffixes', function() {

before(function() {
const resourceLoader = new jsdom.ResourceLoader({ userAgent: USER_AGENT_UNKNOWN });
global.window = new JSDOM(HTML_WITHOUT_PRICE_AND_SUFFIX, { resources: resourceLoader }).window;
global.document = window.document;
global.getComputedStyle = window.getComputedStyle;
global.Event = window.Event;
smartbanner = new SmartBanner();
});

it('expected to have no price', function() {
expect(smartbanner.price).to.be.empty;
});

it('expected to have no price suffix', function() {
expect(smartbanner.priceSuffix).to.be.empty;
});

});

});

context('without platform-specific price suffixes', function() {

before(function() {
Expand Down

0 comments on commit d5bd85b

Please sign in to comment.