From d35a20a8c1dd89d6d2fc0f301f1454eebc9d96b7 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 23 Sep 2024 19:46:32 +0200 Subject: [PATCH] [Editor] Don't show the ml toggle button when the ml is disabled (bug 1920515) --- test/integration/stamp_editor_spec.mjs | 68 ++++++++++++++++++++++++++ web/app.js | 1 + web/new_alt_text_manager.js | 2 +- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index 624f68e39096f..24e60499f7402 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -1122,6 +1122,74 @@ describe("Stamp Editor", () => { }); }); + describe("New alt-text flow (bug 1920515)", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait( + "empty.pdf", + ".annotationEditorLayer", + null, + { + eventBusSetup: eventBus => { + eventBus.on("annotationeditoruimanager", ({ uiManager }) => { + window.uiManager = uiManager; + }); + }, + }, + { + enableAltText: false, + enableFakeMLManager: false, + enableUpdatedAddImage: true, + enableGuessAltText: true, + } + ); + }); + + afterEach(async () => { + for (const [, page] of pages) { + if (await isVisible(page, "#newAltTextDialog")) { + await page.keyboard.press("Escape"); + await page.waitForSelector("#newAltTextDisclaimer", { + visible: false, + }); + } + await page.evaluate(() => { + window.uiManager.reset(); + }); + // Disable editing mode. + await switchToStamp(page, /* disable */ true); + } + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that the toggle button isn't displayed when there is no AI", async () => { + // Run sequentially to avoid clipboard issues. + for (const [, page] of pages) { + await switchToStamp(page); + + // Add an image. + await copyImage(page, "../images/firefox_logo.png", 0); + const editorSelector = getEditorSelector(0); + await page.waitForSelector(editorSelector); + await waitForSerialized(page, 1); + + // Wait for the dialog to be visible. + await page.waitForSelector("#newAltTextDialog.noAi", { visible: true }); + + // enableFakeMLManager is false, so it means that we don't have ML but + // we're using the new flow, hence we don't want to have the toggle + // button. + await page.waitForSelector("#newAltTextCreateAutomatically", { + hidden: true, + }); + } + }); + }); + describe("No auto-resize", () => { let pages; diff --git a/web/app.js b/web/app.js index 82a60be07ca28..5812e80ced432 100644 --- a/web/app.js +++ b/web/app.js @@ -350,6 +350,7 @@ const PDFViewerApplication = { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) { Object.assign(opts, { enableAltText: x => x === "true", + enableFakeMLManager: x => x === "true", enableGuessAltText: x => x === "true", enableUpdatedAddImage: x => x === "true", highlightEditorColors: x => x, diff --git a/web/new_alt_text_manager.js b/web/new_alt_text_manager.js index b4481b2a8372a..d9b7c80be406e 100644 --- a/web/new_alt_text_manager.js +++ b/web/new_alt_text_manager.js @@ -40,7 +40,7 @@ class NewAltTextManager { #guessedAltText; - #hasAI = false; + #hasAI = null; #isEditing = null;