Skip to content

Commit 846a353

Browse files
authored
Merge pull request #1223 from adobecom/MWPW-171056
MWPW-171056 Improve code coverage
2 parents 3a81e63 + c050533 commit 846a353

File tree

13 files changed

+1565
-404
lines changed

13 files changed

+1565
-404
lines changed

acrobat/blocks/verb-widget/verb-widget.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import { setLibs, getEnv, isOldBrowser } from '../../scripts/utils.js';
44

55
const miloLibs = setLibs('/libs');
6-
const {
7-
createTag, getConfig, loadBlock, getMetadata, loadIms, loadScript,
8-
} = await import(`${miloLibs}/utils/utils.js`);
6+
7+
let createTag;
8+
let getConfig;
9+
let loadBlock;
10+
let getMetadata;
11+
let loadIms;
12+
let loadScript;
913

1014
const fallBack = 'https://www.adobe.com/go/acrobat-overview';
1115
const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html';
@@ -789,6 +793,10 @@ window.addEventListener('analyticsLoad', async ({ detail }) => {
789793
});
790794

791795
export default async function init(element) {
796+
({
797+
createTag, getConfig, loadBlock, getMetadata, loadIms, loadScript,
798+
} = await import(`${miloLibs}/utils/utils.js`));
799+
792800
if (isOldBrowser()) {
793801
window.location.href = EOLBrowserPage;
794802
return;

acrobat/scripts/reactiveStore.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
"^http://localhost:6456/libs/(.*)$": "<rootDir>/test/mocks/milo/libs/$1",
102102
"^/libs/(.*)$": "<rootDir>/test/mocks/milo/libs/$1",
103103
"^https://main--milo--tsayadobe\\.hlx\\.live/libs/(.*)$": "<rootDir>/test/mocks/milo/libs/$1",
104-
"^https://main--milo--tsayadobe\\.hlx\\.page/libs/(.*)$": "<rootDir>/test/mocks/milo/libs/$1"
104+
"^https://main--milo--tsayadobe\\.hlx\\.page/libs/(.*)$": "<rootDir>/test/mocks/milo/libs/$1",
105+
"^https://main--unity--adobecom.hlx.live/unitylibs/(.*)$": "<rootDir>/test/mocks/unitylibs/$1"
105106
}
106107
}
107108
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<main>
2+
<div class="section">
3+
<div class="verb-widget fillsign">
4+
<div>
5+
<div>
6+
<h1 id="fill-and-sign-a-pdf">Fill and sign a PDF</h1>
7+
</div>
8+
</div>
9+
<div>
10+
<div>{{verb-widget-legal}}</div>
11+
</div>
12+
</div>
13+
<div class="unity workflow-acrobat"></div>
14+
</div>
15+
</main>

test/blocks/unity/mocks/head.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<link rel="icon" href="data:,">
2+
<link rel="stylesheet" href="/acrobat/styles/styles.css" />
3+
<link rel="stylesheet" href="/acrobat/blocks/verb-widget/verb-widget.css" />

test/blocks/unity/unity.jest.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
/* eslint-disable compat/compat */
5+
/* eslint-disable no-undef */
6+
import path from 'path';
7+
import fs from 'fs';
8+
9+
// Mock the workflow module before importing the unity module
10+
const mockWorkflowInit = jest.fn();
11+
12+
// Mock the dynamic import of the workflow module
13+
jest.mock('../../../test/mocks/unitylibs/core/workflow/workflow.js', () => mockWorkflowInit, { virtual: true });
14+
15+
describe('Unity block', () => {
16+
let init;
17+
18+
beforeAll(async () => {
19+
const module = await import('../../../acrobat/blocks/unity/unity.js');
20+
init = module.default;
21+
});
22+
23+
beforeEach(() => {
24+
document.head.innerHTML = fs.readFileSync(
25+
path.resolve(__dirname, './mocks/head.html'),
26+
'utf8',
27+
);
28+
document.body.innerHTML = fs.readFileSync(
29+
path.resolve(__dirname, './mocks/body-sign-pdf.html'),
30+
'utf8',
31+
);
32+
});
33+
34+
afterEach(() => {
35+
jest.clearAllMocks();
36+
});
37+
38+
it('initialize', async () => {
39+
delete window.location;
40+
window.location = new URL('https://localhost/acrobat/online/sign-pdf.html');
41+
42+
window.browser = { ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' };
43+
44+
const block = document.querySelector('.verb-widget');
45+
await init(block);
46+
47+
expect(mockWorkflowInit).toHaveBeenCalledWith(
48+
block,
49+
'acrobat',
50+
expect.stringContaining('/unitylibs'), // unitylibs path
51+
'v2', // unity version
52+
'us', // language region
53+
'en', // language code
54+
);
55+
});
56+
57+
it('initialize with jp', async () => {
58+
delete window.location;
59+
window.location = new URL('https://localhost/jp/acrobat/online/sign-pdf.html');
60+
61+
window.browser = { ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' };
62+
63+
const block = document.querySelector('.verb-widget');
64+
await init(block);
65+
66+
expect(mockWorkflowInit).toHaveBeenCalledWith(
67+
block,
68+
'acrobat',
69+
expect.stringContaining('/unitylibs'), // unitylibs path
70+
'v2', // unity version
71+
'jp', // language region
72+
'ja', // language code
73+
);
74+
});
75+
76+
it('initialize with mobile', async () => {
77+
delete window.location;
78+
window.location = new URL('https://localhost/acrobat/online/sign-pdf.html');
79+
80+
window.browser = { ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.1 Mobile/15E148 Safari/604.1' };
81+
82+
const block = document.querySelector('.verb-widget');
83+
await init(block);
84+
85+
expect(mockWorkflowInit).not.toHaveBeenCalled();
86+
});
87+
});

0 commit comments

Comments
 (0)