8000 MWPW-176257 Resolve Acrobat Unit Test Errors by sanjayms01 · Pull Request #501 · adobecom/unity · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MWPW-176257 Resolve Acrobat Unit Test Errors #501

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

Merged
merged 1 commit into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions test/core/workflow/workflow-acrobat/action-binder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,10 @@ describe('ActionBinder', () => {
beforeEach(() => {
actionBinder.serviceHandler = { postCallToService: sinon.stub().resolves({ url: 'https://test-redirect-url.com' }) };
actionBinder.acrobatApiConfig = { connectorApiEndPoint: 'https://test-api.com/connector' };
actionBinder.workflowCfg = { enabledFeatures: ['test-feature'] };
actionBinder.workflowCfg = {
enabledFeatures: ['test-feature'],
productName: 'test-product',
};
actionBinder.MULTI_FILE = false;
actionBinder.promiseStack = [];
actionBinder.dispatchErrorToast = sinon.stub().resolves();
Expand All @@ -830,7 +833,11 @@ describe('ActionBinder', () => {
expect(actionBinder.serviceHandler.postCallToService.calledWith(
actionBinder.acrobatApiConfig.connectorApiEndPoint,
{ body: JSON.stringify(cOpts) },
{ 'x-unity-dc-verb': 'test-feature' },
{
'x-unity-dc-verb': actionBinder.workflowCfg.enabledFeatures[0],
'x-unity-product': actionBinder.workflowCfg.productName,
'x-unity-action': actionBinder.workflowCfg.enabledFeatures[0],
},
)).to.be.true;
expect(actionBinder.redirectUrl).to.equal('https://test-redirect-url.com');
});
Expand Down
29 changes: 19 additions & 10 deletions test/core/workflow/workflow-acrobat/upload-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ describe('UploadHandler', () => {
let mockServiceHandler;
let mockTransitionScreen;

async function runWithFakeTimers(testFn, tickMs = 500) {
const clock = sinon.useFakeTimers();
try {
const promise = testFn();
clock.tick(tickMs);
await clock.runAllAsync();
return await promise;
} finally {
clock.restore();
}
}

before(async () => {
const originalImport = window.import;

Expand Down Expand Up @@ -89,6 +101,7 @@ describe('UploadHandler', () => {
delay: sinon.stub().resolves(),
setIsUploading: sinon.stub(),
dispatchGenericError: sinon.stub().resolves(),
getAdditionalHeaders: sinon.stub().returns({}),
};

mockServiceHandler = {
Expand Down Expand Up @@ -139,26 +152,22 @@ describe('UploadHandler', () => {
it('should validate normal page count', async () => {
const assetData = { id: 'asset-123' };
mockServiceHandler.getCallToService.resolves({ numPages: 50 });
const result = await uploadHandler.checkPageNumCount(assetData, false);
const result = await runWithFakeTimers(() => uploadHandler.checkPageNumCount(assetData, false));
expect(result).to.be.false;
});

it('should handle error in checkPageNumCount', async () => {
const clock = sinon.useFakeTimers();
uploadHandler.serviceHandler.getCallToService = sinon.stub().rejects(new Error('fail'));
const assetData = { id: 'asset-123' };
const promise = uploadHandler.checkPageNumCount(assetData, false);
clock.tick(5000); // Fast-forward timers to trigger setTimeout/setInterval
const result = await promise;
const result = await runWithFakeTimers(() => uploadHandler.checkPageNumCount(assetData, false), 5000);
expect(result).to.be.false;
clock.restore();
});

it('should handle max page count exceeded', async () => {
const assetData = { id: 'asset-123' };
uploadHandler.serviceHandler.getCallToService = sinon.stub().resolves({ numPages: 101 });
uploadHandler.actionBinder.limits = { pageLimit: { maxNumPages: 100, minNumPages: 1 } };
const result = await uploadHandler.checkPageNumCount(assetData, false);
const result = await runWithFakeTimers(() => uploadHandler.checkPageNumCount(assetData, false));
expect(result).to.be.true;
expect(uploadHandler.showSplashScreen.called).to.be.true;
expect(mockActionBinder.dispatchErrorToast.calledWith('upload_validation_error_max_page_count')).to.be.true;
Expand All @@ -168,7 +177,7 @@ describe('UploadHandler', () => {
const assetData = { id: 'asset-123' };
uploadHandler.serviceHandler.getCallToService = sinon.stub().resolves({ numPages: 0 });
uploadHandler.actionBinder.limits = { pageLimit: { maxNumPages: 100, minNumPages: 1 } };
const result = await uploadHandler.checkPageNumCount(assetData, false);
const result = await runWithFakeTimers(() => uploadHandler.checkPageNumCount(assetData, false));
expect(result).to.be.true;
expect(uploadHandler.showSplashScreen.called).to.be.true;
expect(mockActionBinder.dispatchErrorToast.calledWith('upload_validation_error_min_page_count')).to.be.true;
Expand All @@ -178,7 +187,7 @@ describe('UploadHandler', () => {
const assetData = { id: 'asset-123' };
uploadHandler.serviceHandler.getCallToService = sinon.stub().resolves({ numPages: 101 });
uploadHandler.actionBinder.limits = { pageLimit: { maxNumPages: 100, minNumPages: 1 } };
const result = await uploadHandler.checkPageNumCount(assetData, true);
const result = await runWithFakeTimers(() => uploadHandler.checkPageNumCount(assetData, true));
expect(result).to.be.true;
expect(uploadHandler.showSplashScreen.called).to.be.false;
});
Expand All @@ -187,7 +196,7 @@ describe('UploadHandler', () => {
const assetData = { id: 'asset-123' };
uploadHandler.serviceHandler.getCallToService = sinon.stub().resolves({ numPages: 0 });
uploadHandler.actionBinder.limits = { pageLimit: { maxNumPages: 100, minNumPages: 1 } };
const result = await uploadHandler.checkPageNumCount(assetData, true);
const result = await runWithFakeTimers(() => uploadHandler.checkPageNumCount(assetData, true));
expect(result).to.be.true;
});
});
Expand Down
Loading
0