Skip to content

Commit

Permalink
Fix #695 undefined displayed if price is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ain committed Nov 1, 2023
1 parent b0c55d8 commit 9cc5f19
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 != '') {

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected indentation of 4 spaces but found 3

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected '!==' and instead saw '!='

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected indentation of 4 spaces but found 3

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected '!==' and instead saw '!='

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected indentation of 4 spaces but found 3

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected '!==' and instead saw '!='

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Expected indentation of 4 spaces but found 3

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Expected '!==' and instead saw '!='

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected indentation of 4 spaces but found 3

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected '!==' and instead saw '!='

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected indentation of 4 spaces but found 3

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected '!==' and instead saw '!='

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected indentation of 4 spaces but found 3

Check failure on line 113 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected '!==' and instead saw '!='
return this.options.price;
} else {

Check failure on line 115 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected indentation of 4 spaces but found 3

Check failure on line 115 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected indentation of 4 spaces but found 3

Check failure on line 115 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected indentation of 4 spaces but found 3

Check failure on line 115 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Expected indentation of 4 spaces but found 3

Check failure on line 115 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected indentation of 4 spaces but found 3

Check failure on line 115 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected indentation of 4 spaces but found 3

Check failure on line 115 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected indentation of 4 spaces but found 3
return '';

Check failure on line 116 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected indentation of 6 spaces but found 5

Check failure on line 116 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected indentation of 6 spaces but found 5

Check failure on line 116 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected indentation of 6 spaces but found 5

Check failure on line 116 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Expected indentation of 6 spaces but found 5

Check failure on line 116 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected indentation of 6 spaces but found 5

Check failure on line 116 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected indentation of 6 spaces but found 5

Check failure on line 116 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected indentation of 6 spaces but found 5
}

Check failure on line 117 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected indentation of 4 spaces but found 3

Check failure on line 117 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected indentation of 4 spaces but found 3

Check failure on line 117 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected indentation of 4 spaces but found 3

Check failure on line 117 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

Expected indentation of 4 spaces but found 3

Check failure on line 117 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

Expected indentation of 4 spaces but found 3

Check failure on line 117 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

Expected indentation of 4 spaces but found 3

Check failure on line 117 in src/smartbanner.js

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 19)

Expected indentation of 4 spaces but found 3
}

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 9cc5f19

Please sign in to comment.