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

[Editor] Remove the disclaimer when the user is editing the alt-text in the new alt-text modal (bug 1911764) #18670

Merged
merged 1 commit into from
Sep 4, 2024
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
44 changes: 44 additions & 0 deletions test/integration/stamp_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,50 @@ describe("Stamp Editor", () => {
tooltipSelector
);
expect(tooltipText).toEqual("Hello World");

// Click on the Review button.
await page.click(buttonSelector);
await page.waitForSelector("#newAltTextDialog", { visible: true });
await page.click("#newAltTextCreateAutomaticallyButton");
await page.click("#newAltTextCancel");
await page.waitForSelector("#newAltTextDialog", { visible: false });
}
});

it("must check the new alt text flow (part 2)", 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", { visible: true });

// Wait for the spinner to be visible.
await page.waitForSelector("#newAltTextDescriptionContainer.loading");

// Check we've the disclaimer.
await page.waitForSelector("#newAltTextDisclaimer", { visible: true });

// Click in the textarea in order to stop the guessing.
await page.click("#newAltTextDescriptionTextarea");
await page.waitForFunction(() =>
document
.getElementById("newAltTextTitle")
.textContent.startsWith("Add ")
);

// Check we haven't the disclaimer.
await page.waitForSelector("#newAltTextDisclaimer", { visible: false });

// Click on the Not Now button.
await page.click("#newAltTextNotNow");
await page.waitForSelector("#newAltTextDialog", { visible: false });
}
});
});
Expand Down
69 changes: 34 additions & 35 deletions web/new_alt_text_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class NewAltTextManager {

#guessedAltText;

#hasAI = false;

#isEditing = null;

#imagePreview;
Expand Down Expand Up @@ -128,16 +130,16 @@ class NewAltTextManager {
textarea.addEventListener("focus", () => {
this.#wasAILoading = this.#isAILoading;
this.#toggleLoading(false);
this.#toggleTitleAndDisclaimer();
});
textarea.addEventListener("blur", () => {
if (textarea.value) {
return;
if (!textarea.value) {
this.#toggleLoading(this.#wasAILoading);
}
this.#toggleLoading(this.#wasAILoading);
this.#toggleTitleAndDisclaimer();
});
textarea.addEventListener("input", () => {
this.#toggleTitle();
this.#toggleDisclaimer();
this.#toggleTitleAndDisclaimer();
});

eventBus._on("enableguessalttext", ({ value }) => {
Expand Down Expand Up @@ -169,20 +171,6 @@ class NewAltTextManager {
this.#dialog.classList.toggle("error", value);
}

#toggleTitle() {
const isEditing = this.#isAILoading || !!this.#textarea.value;
if (this.#isEditing === isEditing) {
return;
}
this.#isEditing = isEditing;
this.#title.setAttribute(
"data-l10n-id",
isEditing
? "pdfjs-editor-new-alt-text-dialog-edit-label"
: "pdfjs-editor-new-alt-text-dialog-add-label"
);
}

async #toggleGuessAltText(value, isInitial = false) {
if (!this.#uiManager) {
return;
Expand All @@ -199,8 +187,7 @@ class NewAltTextManager {
} else {
this.#toggleLoading(false);
this.#isAILoading = false;
this.#toggleTitle();
this.#toggleDisclaimer();
this.#toggleTitleAndDisclaimer();
}
}

Expand All @@ -210,19 +197,34 @@ class NewAltTextManager {
}

#toggleAI(value) {
if (!this.#uiManager || this.#hasAI === value) {
return;
}
this.#hasAI = value;
this.#dialog.classList.toggle("noAi", !value);
this.#toggleTitle();
this.#toggleTitleAndDisclaimer();
}

#toggleDisclaimer(value = null) {
if (!this.#uiManager) {
#toggleTitleAndDisclaimer() {
// Disclaimer is visible when the AI is loading or the user didn't change
// the guessed alt text.
const visible =
this.#isAILoading ||
(this.#guessedAltText && this.#guessedAltText === this.#textarea.value);
this.#disclaimer.hidden = !visible;

// The title changes depending if the text area is empty or not.
const isEditing = this.#isAILoading || !!this.#textarea.value;
if (this.#isEditing === isEditing) {
return;
}
const hidden =
value === null
? !this.#guessedAltText || this.#guessedAltText !== this.#textarea.value
: !value;
this.#disclaimer.classList.toggle("hidden", hidden);
this.#isEditing = isEditing;
this.#title.setAttribute(
"data-l10n-id",
isEditing
? "pdfjs-editor-new-alt-text-dialog-edit-label"
: "pdfjs-editor-new-alt-text-dialog-add-label"
);
}

async #mlGuessAltText(isInitial) {
Expand All @@ -245,14 +247,11 @@ class NewAltTextManager {
if (this.#previousAltText === null && this.#guessedAltText) {
// We have a guessed alt text and the user didn't change it.
this.#addAltText(this.#guessedAltText);
this.#toggleDisclaimer();
this.#toggleTitle();
return;
}

this.#toggleLoading(true);
this.#toggleTitle();
this.#toggleDisclaimer(true);
this.#toggleTitleAndDisclaimer();

let hasError = false;
try {
Expand All @@ -276,11 +275,10 @@ class NewAltTextManager {
}

this.#toggleLoading(false);
this.#toggleTitleAndDisclaimer();

if (hasError && this.#uiManager) {
this.#toggleError(true);
this.#toggleTitle();
this.#toggleDisclaimer();
}
}

Expand All @@ -289,6 +287,7 @@ class NewAltTextManager {
return;
}
this.#textarea.value = altText;
this.#toggleTitleAndDisclaimer();
}

#setProgress() {
Expand Down