generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
import sinon from 'sinon'; | ||
import { delay } from '../../helpers/waitfor.js'; | ||
|
||
const { setConfig } = await import('../../../libs/utils/utils.js'); | ||
|
||
const mockConfig = { contentRoot: '/test/blocks/mobile-app-banner/mocks' }; | ||
setConfig(mockConfig); | ||
|
||
describe('mobile-app-banner', () => { | ||
beforeEach(async () => { | ||
document.body.innerHTML = await readFile({ path: './mocks/body.html' }); | ||
document.head.innerHTML = '<script/>'; // This block needs a script in head. | ||
}); | ||
|
||
it('should not call branch init if no branch-io-key.json', async () => { | ||
sinon.stub(window, 'fetch'); | ||
const res = new window.Response('Not found', { status: 404 }); | ||
window.fetch.returns(Promise.resolve(res)); | ||
|
||
const module = await import('../../../libs/blocks/mobile-app-banner/mobile-app-banner.js'); | ||
const banner = document.body.querySelector('.mobile-app-banner.product-test'); | ||
await module.default(banner); | ||
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent')); | ||
await delay(100); | ||
|
||
const scriptTags = document.querySelectorAll('head > script'); | ||
const scriptSrcs = []; | ||
scriptTags.forEach((scriptTag) => { | ||
scriptSrcs.push(scriptTag.getAttribute('src')); | ||
}); | ||
expect(scriptSrcs).to.not.include('https://cdn.branch.io/branch-latest.min.js'); | ||
sinon.restore(); | ||
}); | ||
|
||
it('should not call branch init if product not found in branch-io-key file', async () => { | ||
const module = await import('../../../libs/blocks/mobile-app-banner/mobile-app-banner.js'); | ||
const banner = document.body.querySelector('.mobile-app-banner.product-test1'); | ||
await module.default(banner); | ||
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent')); | ||
await delay(100); | ||
|
||
const scriptTags = document.querySelectorAll('head > script'); | ||
const scriptSrcs = []; | ||
scriptTags.forEach((scriptTag) => { | ||
if (scriptTag.getAttribute('src') !== null) scriptSrcs.push(scriptTag.getAttribute('src')); | ||
}); | ||
expect(scriptSrcs).to.not.include('https://cdn.branch.io/branch-latest.min.js'); | ||
}); | ||
|
||
it('should init by adding branchio script', async () => { | ||
window.adobePrivacy = { hasUserProvidedConsent: () => true }; | ||
const module = await import('../../../libs/blocks/mobile-app-banner/mobile-app-banner.js'); | ||
const banner = document.body.querySelector('.mobile-app-banner.product-test'); | ||
await module.default(banner); | ||
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyConsent')); | ||
await delay(100); | ||
window.dispatchEvent(new CustomEvent('adobePrivacy:PrivacyCustom')); // no init twice | ||
await delay(100); | ||
const scriptTags = document.querySelectorAll('head > script'); | ||
const scriptSrcs = []; | ||
scriptTags.forEach((scriptTag) => { | ||
if (scriptTag.getAttribute('src') !== null) scriptSrcs.push(scriptTag.getAttribute('src')); | ||
}); | ||
expect(scriptSrcs).to.include('https://cdn.branch.io/branch-latest.min.js'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<header class="global-navigation" daa-im="true" daa-lh="gnav|milo"><div class="feds-curtain"></div><div class="feds-topnav-wrapper"> | ||
</header> | ||
<div>Hello World</div> | ||
<div> | ||
<div class="mobile-app-banner product-test"> | ||
</div> | ||
<div> | ||
<div class="mobile-app-banner product-test1"> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"product": "test", | ||
"key": "key_test_eaNdoH8nTxeZXfOsgkELrjgpFrhm4q2m" | ||
} | ||
] | ||
} |