Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DCXY-20504: Don't pre-render dropzone when l2 limit is hit and upsell is shown #489

Merged
merged 21 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
80ce70d
DCXY-19397: don't prerender dropzone when l2 limit is hit and upsell …
kbenelli-adobe Nov 21, 2023
cc9a138
DCXY-19397: match org cookie
kbenelli-adobe Nov 21, 2023
7955712
destructure cookies from doc
kbenelli-adobe Nov 21, 2023
688369c
DCXY-19397-New: Update per comments. Don't need verbinclude l2 list a…
kbenelli-adobe Nov 22, 2023
5ff289a
DCXY-19397-New: include create pdf
kbenelli-adobe Nov 22, 2023
ee4dc94
faster string check
kbenelli-adobe Nov 22, 2023
379b69e
DCXY-19397-New: pdf convert is create pdf group
kbenelli-adobe Nov 22, 2023
51627c5
DCXY-19397-New: unit test coverage for skip prerender cases
kbenelli-adobe Nov 29, 2023
3d7517b
DCXY-19397-New: fixed eslint error
kbenelli-adobe Nov 29, 2023
8eeabad
DCXY-19397-New: don't need to work with this eslint fix
kbenelli-adobe Nov 29, 2023
7e8974e
DCXY-19397-New: don't need to work with this eslint fix
kbenelli-adobe Nov 30, 2023
841c61c
DCXY-19397-New: remove duplicate window location
kbenelli-adobe Nov 30, 2023
65541fc
DCXY-19397-New: Updated cookie names to avoid chrome viewer extension…
kbenelli-adobe Dec 1, 2023
24f5a30
DCXY-19397-New: Supports cname convention for 1 pass cookie search.
kbenelli-adobe Dec 1, 2023
f2a4761
DCXY-19397-New: Updated tests to match cnames
kbenelli-adobe Dec 1, 2023
33ffe16
DCXY-19397-New: simplify look up to to-pdf, pdf-to, or verb name
kbenelli-adobe Dec 1, 2023
6aae123
DCXY-19397-New: check and map env prefix respectively
kbenelli-adobe Dec 1, 2023
cb96217
edge worker inlined snippet, remove the snipped from dom if exhausted
kbenelli-adobe Dec 4, 2023
c9893e7
Merge branch 'stage' into DCXY-19397-New
kbenelli-adobe Dec 4, 2023
1ee08cd
don't allow for undefined cookie name
kbenelli-adobe Dec 5, 2023
36fbd72
Merge branch 'stage' into DCXY-19397-New
seanchoi-dev Dec 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions acrobat/blocks/dc-converter-widget/dc-converter-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,16 @@ const verbRedirMap = {
'number-pages': 'number',
};

const exhLimitCookieMap = {
'to-pdf': 'p_ac_cr_p_c',
'pdf-to': 'p_ac_ex_p_c',
'compress-pdf': 'p_ac_cm_p_ops',
'rotate-pages': 'p_ac_or_p_c',
createpdf: 'p_ac_cr_p_c',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hate to add more logic but we should use p_ s_ and d_ for prod, stage and dev, respectively. Perhaps remove the p_ from this map and prepend the right prefix to limitCookie at L220

Copy link
Collaborator Author

@kbenelli-adobe kbenelli-adobe Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, makes sense. Updated

};

const url = window.location;

const langFromPath = url.pathname.split('/')[1];
const pageLang = localeMap[langFromPath] || 'en-us';

Expand Down Expand Up @@ -206,20 +215,19 @@ export default async function init(element) {
widgetContainer.className = `fsw wapper-${VERB}`;
widget.appendChild(widgetContainer);

const isReturningUser = window.localStorage.getItem('pdfnow.auth');
const isRedirection = /redirect_(?:conversion|files)=true/.test(window.location.search);
const preRenderDropZone = !isReturningUser && !isRedirection;

const verbIncludeList = ['compress-pdf', 'fillsign', 'sendforsignature', 'add-comment',
'delete-pages', 'reorder-pages', 'split-pdf', 'insert-pdf', 'extract-pages', 'crop-pages', 'number-pages'];
const { cookie: cookies } = document;
const limitCookie = exhLimitCookieMap[VERB] || exhLimitCookieMap[VERB.match(/^pdf-to|to-pdf$/)?.[0]];
const isLimitExhausted = cookies.includes(limitCookie);
const preRenderDropZone = !isLimitExhausted && !isRedirection;

const INLINE_SNIPPET = widget.querySelector(':scope > section#edge-snippet');
if (INLINE_SNIPPET) {
widgetContainer.dataset.rendered = 'true';
widgetContainer.appendChild(...INLINE_SNIPPET.childNodes);
widget.removeChild(INLINE_SNIPPET);
performance.mark('milo-move-snippet');
} else if (verbIncludeList.includes(VERB) || preRenderDropZone) {
} else if (preRenderDropZone) {
const response = await fetch(DC_GENERATE_CACHE_URL || `${DC_DOMAIN}/dc-generate-cache/dc-hosted-${DC_GENERATE_CACHE_VERSION}/${VERB}-${pageLang}.html`);
switch (response.status) {
case 200: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import fs from 'fs';
describe('dc-converter-widget', () => {
beforeEach(async () => {
document.body.innerHTML = fs.readFileSync(
path.resolve(__dirname, './mocks/body-rearrange-pdf.html'),
path.resolve(__dirname, './mocks/body-variants/body-rearrange-pdf.html'),
'utf8',
);
jest.useFakeTimers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import fs from 'fs';
describe('dc-converter-widget', () => {
beforeEach(async () => {
document.body.innerHTML = fs.readFileSync(
path.resolve(__dirname, './mocks/body-rearrange-pdf.html'),
path.resolve(__dirname, './mocks/body-variants/body-rearrange-pdf.html'),
'utf8',
);
jest.useFakeTimers();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @jest-environment jsdom
*/
/* eslint-disable no-undef */
/* eslint-disable compat/compat */

import path from 'path';
import fs from 'fs';
import init from '../../../acrobat/blocks/dc-converter-widget/dc-converter-widget.js';

const skippedPreRenderCases = [
{
mockFilePath: './mocks/body-variants/body-compress-pdf.html',
url: 'https://www.adobe.com/acrobat/online/compress-pdf.html',
cookieValue: 'p_ac_cm_p_ops=true',
},
{
mockFilePath: './mocks/body-variants/body-convert-pdf.html',
url: 'https://www.adobe.com/acrobat/online/convert-pdf.html',
cookieValue: 'p_ac_cr_p_c=true',
},
{
mockFilePath: './mocks/body-variants/body-word-to-pdf.html',
url: 'https://www.adobe.com/acrobat/online/word-to-pdf.html',
cookieValue: 'p_ac_cr_p_c=true',
},
{
mockFilePath: './mocks/body-variants/body-pdf-to-word.html',
url: 'https://www.adobe.com/acrobat/online/pdf-to-word.html',
cookieValue: 'p_ac_ex_p_c=true',
},
{
mockFilePath: './mocks/body-variants/body-pdf-to-word.html',
url: 'https://www.adobe.com/acrobat/online/pdf-to-word.html',
cookieValue: 'p_ac_ex_p_c_st=true',
},
];

describe('DC Converter Widget Skip Prerender Verbs', () => {
window.fetch = jest.fn(() => Promise.resolve({
status: 200,
text: () => Promise.resolve(
fs.readFileSync(path.resolve(__dirname, './mocks/widget.html')),
),
}));
window.browser = { isMobile: true };
window.performance.mark = jest.fn();

beforeEach(() => {
jest.clearAllMocks();
document.cookie = '';
});

it.each(skippedPreRenderCases)(
'render widget when pre-render is skipped from limit exhausted cookie condition',
async ({ url, mockFilePath, cookieValue }) => {
document.cookie = cookieValue;
document.body.innerHTML = fs.readFileSync(
path.resolve(__dirname, mockFilePath),
'utf8',
);

delete window.location;
window.location = new URL(url);

const block = document.querySelector('.dc-converter-widget');
await init(block);
jest.runAllTimers();
},
);

afterAll(() => {
jest.clearAllMocks();
document.cookie = '';
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<main>
<div class="dc-converter-widget">
<div>
<div>compress-pdf</div>
</div>
<div>
<div>https://www.adobe.com/go/testredirect</div>
</div>
</div>
</main>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<main>
<div class="dc-converter-widget">
<div>
<div>createpdf</div>
</div>
<div>
<div>https://www.adobe.com/go/testredirect</div>
</div>
</div>
</main>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<main>
<div class="dc-converter-widget">
<div>
<div>pdf-to-word</div>
</div>
<div>
<div>https://www.adobe.com/go/testredirect</div>
</div>
</div>
</main>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<main>
<div class="dc-converter-widget">
<div>
<div>word-to-pdf</div>
</div>
<div>
<div>https://www.adobe.com/go/testredirect</div>
</div>
</div>
</main>