-
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 #411 from adobecom/unittestfix
Fix unit test
- Loading branch information
Showing
5 changed files
with
88 additions
and
2 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
40 changes: 40 additions & 0 deletions
40
test/blocks/dc-converter-widget/dc-converter-widget-rearrange-pdf-200.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,40 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable compat/compat */ | ||
|
||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
describe('dc-converter-widget', () => { | ||
beforeEach(async () => { | ||
document.body.innerHTML = fs.readFileSync( | ||
path.resolve(__dirname, './mocks/body-rearrange-pdf.html'), | ||
'utf8', | ||
); | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('loads rearrange-pdf widget', async () => { | ||
const { default: init } = await import('../../../acrobat/blocks/dc-converter-widget/dc-converter-widget.js'); | ||
window.fetch = jest.fn(() => Promise.resolve({ | ||
status: 200, | ||
text: () => Promise.resolve( | ||
fs.readFileSync(path.resolve(__dirname, './mocks/widget.html')), | ||
), | ||
})); | ||
window.browser = { isMobile: true }; | ||
delete window.location; | ||
window.location = new URL('https://www.adobe.com/acrobat/online/rearrange-pdf.html'); | ||
const block = document.querySelector('.dc-converter-widget'); | ||
window.performance.mark = jest.fn(); | ||
await init(block); | ||
jest.runAllTimers(); | ||
expect(document.querySelector('.skeleton-wrapper')).toBeTruthy(); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
test/blocks/dc-converter-widget/dc-converter-widget-rearrange-pdf-404.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,38 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable compat/compat */ | ||
|
||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
describe('dc-converter-widget', () => { | ||
beforeEach(async () => { | ||
document.body.innerHTML = fs.readFileSync( | ||
path.resolve(__dirname, './mocks/body-rearrange-pdf.html'), | ||
'utf8', | ||
); | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('loads rearrange-pdf widget 404', async () => { | ||
const { default: init } = await import('../../../acrobat/blocks/dc-converter-widget/dc-converter-widget.js'); | ||
window.fetch = jest.fn(() => Promise.resolve({ | ||
status: 404, | ||
text: () => Promise.resolve('Not Found'), | ||
})); | ||
window.browser = { isMobile: true }; | ||
delete window.location; | ||
window.location = new URL('https://www.adobe.com/acrobat/online/rearrange-pdf.html'); | ||
const block = document.querySelector('.dc-converter-widget'); | ||
window.performance.mark = jest.fn(); | ||
await init(block); | ||
jest.runAllTimers(); | ||
expect(document.querySelector('.skeleton-wrapper')).toBeTruthy(); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/blocks/dc-converter-widget/mocks/body-rearrange-pdf.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,7 @@ | ||
<main> | ||
<div class="dc-converter-widget"> | ||
<div> | ||
<div>reorder-pages</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