Skip to content

Commit

Permalink
Merge pull request #411 from adobecom/unittestfix
Browse files Browse the repository at this point in the history
Fix unit test
  • Loading branch information
TsayAdobe authored Oct 13, 2023
2 parents e0fd78c + 50b1961 commit 79b5833
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"description": "Website foundation technology.",
"scripts": {
"test": "npm run wtr ; npm run jest",
"test": "npm run wtr && npm run jest",
"wtr": "wtr \"./test/**/*.test.(js|html)\" --node-resolve --port=2000 --coverage --concurrent-browsers 4",
"wtr:watch": "npm run wtr -- --watch",
"jest": "jest --coverage --coverageDirectory=coverage/jest",
Expand Down
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();
});
});
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 test/blocks/dc-converter-widget/mocks/body-rearrange-pdf.html
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>
3 changes: 2 additions & 1 deletion test/blocks/eventwrapper/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div>
<div data-section="widget" class="section">
<script id="adobe_dc_sdk_launcher" src="https://stage.acrobat.adobe.com/dc-hosted/3.8.0_2.15.2/dc-app-launcher.js" data-dropzone_id="CID" data-locale="en-us" data-server_env="stage" data-verb="compress-pdf" data-load_typekit="false" data-load_imslib="false" data-enable_unload_prompt="true"></script>
</div>
</div>
<button class="dialog-close"></button>
<div class="eventwrapper onload">
<div>
<div><a
Expand Down

0 comments on commit 79b5833

Please sign in to comment.