-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from TsayAdobe/MWPW-134816
MWPW-134816 Improve Unit Test Coverage
- Loading branch information
Showing
9 changed files
with
376 additions
and
4 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
test/blocks/dc-converter-widget-ootb/dc-converter-widget-ootb.jest.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,135 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import init from '../../../acrobat/blocks/dc-converter-widget-ootb/dc-converter-widget-ootb'; | ||
|
||
describe('dc-converter-widget', () => { | ||
beforeEach(async () => { | ||
document.body.innerHTML = fs.readFileSync( | ||
path.resolve(__dirname, './mocks/body.html'), | ||
'utf8' | ||
); | ||
window.performance.mark = jest.fn(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('loads widget from prod env', async () => { | ||
let fetchUrl = ''; | ||
window.fetch = jest.fn((url) => { | ||
fetchUrl = url; | ||
return Promise.resolve({ | ||
status: 200, | ||
text: () => | ||
Promise.resolve( | ||
fs.readFileSync(path.resolve(__dirname, './mocks/widget.html')) | ||
), | ||
}); | ||
}); | ||
delete window.location; | ||
window.location = new URL('https://www.adobe.com'); | ||
const block = document.querySelector('.dc-converter-widget-ootb'); | ||
const widget = await init(block); | ||
document.dispatchEvent(new Event('milo:deferred')); | ||
const launcher = document.querySelector('#adobe_dc_sdk_launcher'); | ||
expect(launcher.getAttribute('src')).toMatch(/^https:\/\/acrobat.adobe.com\//); | ||
}); | ||
|
||
it.each` | ||
hostname | ||
${'stage--dc--adobecom.hlx.page'} | ||
${'main--dc--adobecom.hlx.page'} | ||
${'stage--dc--adobecom.hlx.live'} | ||
${'main--dc--adobecom.hlx.live'} | ||
${'www.stage.adobe.com'} | ||
`('loads widget from stage env', async ({ hostname }) => { | ||
let fetchUrl = ''; | ||
window.fetch = jest.fn((url) => { | ||
fetchUrl = url; | ||
return Promise.resolve({ | ||
status: 200, | ||
text: () => | ||
Promise.resolve( | ||
fs.readFileSync(path.resolve(__dirname, './mocks/widget.html')) | ||
), | ||
}); | ||
}); | ||
delete window.location; | ||
window.location = new URL(`https://${hostname}`); | ||
const block = document.querySelector('.dc-converter-widget-ootb'); | ||
const widget = await init(block); | ||
document.dispatchEvent(new Event('milo:deferred')); | ||
const launcher = document.querySelector('#adobe_dc_sdk_launcher'); | ||
expect(launcher.getAttribute('src')).toMatch(/^https:\/\/stage.acrobat.adobe.com\//); | ||
}); | ||
|
||
it('loads widget failed from prod env', async () => { | ||
window.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
status: 404, | ||
}) | ||
); | ||
delete window.location; | ||
window.location = new URL('https://www.adobe.com'); | ||
const block = document.querySelector('.dc-converter-widget-ootb'); | ||
const widget = await init(block); | ||
expect(document.querySelector('#CID').children).toHaveLength(3); | ||
}); | ||
|
||
it.each` | ||
hostname | ||
${'stage--dc--adobecom.hlx.page'} | ||
${'main--dc--adobecom.hlx.page'} | ||
${'stage--dc--adobecom.hlx.live'} | ||
${'www.stage.adobe.com'} | ||
`('redirects when signed in on stage', async ({ hostname }) => { | ||
window.fetch = jest.fn((url) => | ||
Promise.resolve({ | ||
status: 200, | ||
text: () => | ||
Promise.resolve( | ||
fs.readFileSync(path.resolve(__dirname, './mocks/widget.html')) | ||
), | ||
}) | ||
); | ||
window.adobeIMS = { | ||
isSignedInUser: jest.fn(() => true) | ||
}; | ||
delete window.location; | ||
window.location = new URL(`https://${hostname}`); | ||
const block = document.querySelector('.dc-converter-widget-ootb'); | ||
const widget = await init(block); | ||
window.dispatchEvent(new CustomEvent('IMS:Ready')); | ||
expect(window.location).toMatch(/^https:\/\/www.adobe.com\/go\/acrobat-/); | ||
}); | ||
|
||
it.each` | ||
hostname | ||
${'main--dc--adobecom.hlx.live'} | ||
${'www.adobe.com'} | ||
`('redirects when signed in', async ({ hostname }) => { | ||
window.fetch = jest.fn((url) => | ||
Promise.resolve({ | ||
status: 200, | ||
text: () => | ||
Promise.resolve( | ||
fs.readFileSync(path.resolve(__dirname, './mocks/widget.html')) | ||
), | ||
}) | ||
); | ||
window.adobeIMS = { | ||
isSignedInUser: jest.fn(() => true) | ||
}; | ||
delete window.location; | ||
window.location = new URL(`https://${hostname}`); | ||
const block = document.querySelector('.dc-converter-widget-ootb'); | ||
const widget = await init(block); | ||
window.dispatchEvent(new CustomEvent('IMS:Ready')); | ||
// Issue with jest and window.location | ||
//expect(window.location).toMatch(/https:\/\/www.adobe.com\/go\/testredirect/); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
test/blocks/dc-converter-widget-ootb/dc-converter-widget-ootb.test.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,62 @@ | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
import sinon from 'sinon'; | ||
import { waitForElement, delay } from '../../helpers/waitfor.js'; | ||
|
||
document.head.innerHTML = await readFile({ path: './mocks/head.html' }); | ||
document.body.innerHTML = await readFile({ path: './mocks/body_cache.html' }); | ||
const { default: init } = await import( | ||
'../../../acrobat/blocks/dc-converter-widget-ootb/dc-converter-widget-ootb' | ||
); | ||
|
||
describe('dc-converter-widget block', () => { | ||
before(() => { | ||
const block = document.body.querySelector('.dc-converter-widget-ootb'); | ||
init(block); | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('handles DC_Hosted:Ready event', async() => { | ||
window.dc_hosted = { | ||
getUserLimits: async () => ({ | ||
upload: { | ||
can_upload: true | ||
} | ||
}), | ||
}; | ||
window.dispatchEvent(new CustomEvent('DC_Hosted:Ready')); | ||
await delay(100); | ||
expect(window.doccloudPersonalization).to.be.exist; | ||
}); | ||
|
||
it('handles IMS:Ready event', async () => { | ||
window.adobeIMS = { | ||
isSignedInUser: () => false, | ||
}; | ||
window._satellite = { | ||
track: sinon.stub(), | ||
}; | ||
window.bowser = { | ||
getParser: () => ({ | ||
getBrowserName: () => 'Chrome', | ||
getBrowserVersion: () => '110', | ||
}), | ||
}; | ||
const widget = await readFile({ path: './mocks/widget.html' }); | ||
sinon.stub(window, 'fetch'); | ||
var res = new window.Response(widget, { | ||
status: 200 | ||
}); | ||
window.fetch.returns(Promise.resolve(res)); | ||
window.dispatchEvent(new CustomEvent('IMS:Ready')); | ||
await delay(1000); | ||
expect(document.querySelector('#CID')).to.be.exist; | ||
}); | ||
|
||
it('handles Bowser:Ready event', () => { | ||
window.dispatchEvent(new CustomEvent('Bowser:Ready')); | ||
}); | ||
}); |
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 @@ | ||
<main> | ||
<div class="dc-converter-widget-ootb"> | ||
<div> | ||
<div>pdf-to-ppt</div> | ||
</div> | ||
<div> | ||
<div>https://www.adobe.com/go/testredirect</div> | ||
</div> | ||
</div> | ||
</main> |
16 changes: 16 additions & 0 deletions
16
test/blocks/dc-converter-widget-ootb/mocks/body_cache.html
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,16 @@ | ||
<main> | ||
<div class="dc-converter-widget-ootb"> | ||
<div> | ||
<div>pdf-to-ppt</div> | ||
</div> | ||
<div> | ||
<div>https://www.adobe.com/go/testredirect</div> | ||
</div> | ||
<div> | ||
<div></div> | ||
</div> | ||
<div> | ||
<div>http://localhost:2000/test/blocks/dc-converter-widget-ootb/mocks/widget.html</div> | ||
</div> | ||
</div> | ||
</main> |
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,3 @@ | ||
<link rel="icon" href="data:,"> | ||
<link rel="stylesheet" href="/acrobat/styles/styles.css" /> | ||
<link rel="stylesheet" href="/acrobat/blocks/dc-converter-widget-ootb/dc-converter-widget-ootb.css" /> |
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,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<style> | ||
p { | ||
color: red; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="mockWidget"></div> | ||
</body> | ||
|
||
</html> |
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
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,77 @@ | ||
<main> | ||
<div> | ||
<div class="pricing-card"> | ||
<div> | ||
<div>title</div> | ||
<div> | ||
<h1 id="acrobat-pro2-2">Acrobat Pro2</h1> | ||
<p>For students & teachers</p> | ||
</div> | ||
</div> | ||
<div> | ||
<div>option1</div> | ||
<div>Annual, paid monthly2</div> | ||
</div> | ||
<div> | ||
<div>option2</div> | ||
<div>Annual, prepaid2</div> | ||
</div> | ||
<div> | ||
<div>option3</div> | ||
<div>Monthly2</div> | ||
</div> | ||
<div> | ||
<div>promotionText</div> | ||
<div>Best value2</div> | ||
</div> | ||
<div> | ||
<div>price1</div> | ||
<div>US$3339.99/m</div> | ||
</div> | ||
<div> | ||
<div>price2</div> | ||
<div>US$439.99/m</div> | ||
</div> | ||
<div> | ||
<div>price3</div> | ||
<div>US$539.99/m</div> | ||
</div> | ||
<div> | ||
<div>cta1</div> | ||
<div>link133</div> | ||
</div> | ||
<div> | ||
<div>cta2</div> | ||
<div>link233</div> | ||
</div> | ||
<div> | ||
<div>cta3</div> | ||
<div>link333</div> | ||
</div> | ||
<div> | ||
<div>disclaimer1</div> | ||
<div>Equal to US$5339.99/mo. Cancel within 14 days for a <a | ||
href="https://helpx.adobe.com/manage-account/using/cancel-subscription.html">full refund</a>. | ||
Windows and Mac.</div> | ||
</div> | ||
<div> | ||
<div>disclaimer2</div> | ||
<div>Equal to US$6339.99/mo. Cancel within 14 days for a <a | ||
href="https://helpx.adobe.com/manage-account/using/cancel-subscription.html">full refund</a>. | ||
Windows and Mac.</div> | ||
</div> | ||
<div> | ||
<div>disclaimer3</div> | ||
<div>Equal to US$7339.99/mo. Cancel within 14 days for a <a | ||
href="https://helpx.adobe.com/manage-account/using/cancel-subscription.html">full refund</a>. | ||
Windows and Mac.</div> | ||
</div> | ||
</div> | ||
<div class="section-metadata"> | ||
<div> | ||
<div data-valign="middle">style</div> | ||
<div data-valign="middle">pricing-card-columns, w-400</div> | ||
</div> | ||
</div> | ||
</div> | ||
</main> |
Oops, something went wrong.