From 1ace73305446a8ca0443b938616867a5315cd2c7 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Fri, 22 Mar 2024 11:08:26 +0100 Subject: [PATCH] [bulk] Publishing a single un-previewed resource with bulk selection fires an error (#696) * fix: handle 404 for single entry bulk publish * chore: corresponding test * chore: simplify changes * chore: not only --- src/extension/module.js | 16 +++++++++++++--- test/bulk-publish.test.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/extension/module.js b/src/extension/module.js index 0034fe6c8..6b5a1b616 100644 --- a/src/extension/module.js +++ b/src/extension/module.js @@ -1836,6 +1836,7 @@ import sampleRUM from './rum.js'; } try { if (paths.length === 1) { + let level = 0; // single operation const [path] = paths; const url = getAdminUrl(config, route, path); @@ -1845,7 +1846,12 @@ import sampleRUM from './rum.js'; method, }); if (!resp.ok) { - throw new Error(resp.headers['x-error']); + if (resp.status === 404 && operation === 'publish') { + level = 1; + throw new Error(getBulkText([1], 'result', operation, 'error_no_source')); + } else { + throw new Error(resp.headers['x-error']); + } } else { showBulkOperationSummary({ operation, @@ -1854,13 +1860,17 @@ import sampleRUM from './rum.js'; }); } } catch (e) { - console.error(`bulk ${operation} failed: ${e.message}`); + if (level > 0) { + console.warn(`bulk ${operation} failed: ${e.message}`); + } else { + console.error(`bulk ${operation} failed: ${e.message}`); + } sk.showModal({ message: [ getBulkText([1], 'result', operation, 'failure'), e.message || i18n(sk, 'bulk_error'), ], - level: 0, + level, sticky: true, }); } diff --git a/test/bulk-publish.test.js b/test/bulk-publish.test.js index c3d1fdd60..882121415 100644 --- a/test/bulk-publish.test.js +++ b/test/bulk-publish.test.js @@ -20,6 +20,7 @@ import { SidekickTest } from './SidekickTest.js'; const SHAREPOINT_FIXTURE = 'admin-sharepoint.html'; const GDRIVE_FIXTURE = 'admin-gdrive.html'; + const TESTS = [{ env: 'sharepoint', setup: new Setup('blog'), @@ -225,6 +226,44 @@ describe('Test bulk publish plugin', () => { assert.strictEqual(clipboardText.split('\n').length, 3, `3 URLs not copied to clipboard in ${env}: \n${clipboardText}`); assert.strictEqual(openedWindows.length, 3, `3 URLs not opened in ${env}: \n${openedWindows.join('\n')}`); }).timeout(IT_DEFAULT_TIMEOUT); + + it(`Bulk publish plugin tells users to preview first in ${env} (single selection)`, async () => { + nock.sidekick(setup); + nock.admin(setup, { + route: 'status', + type: 'admin', + persist: true, + }); + nock.admin(setup, { + route: 'live', + method: 'post', + status: [404], + }); + const { notification } = await new SidekickTest({ + browser, + page, + fixture, + sidekickConfig: setup.sidekickConfig, + configJson: setup.configJson, + url: setup.getUrl('edit', 'admin'), + plugin: 'bulk-publish', + pluginSleep: 5000, + loadModule: true, + acceptDialogs: true, + pre: (p) => p.evaluate(() => { + // user deselects one, keep one + document.getElementById('file-pdf').click(); + }), + }).run(); + assert.ok( + notification?.message.endsWith('File must be previewed first'), + 'Inform user to preview first', + ); + assert.ok( + notification.className.includes('level-1'), + 'Dialog should only be a warning', + ); + }).timeout(IT_DEFAULT_TIMEOUT); }); it('Bulk publish plugin previews single selection without creating a job', async () => {