From 06ad5fe3ef4bb62703148dfe8d4c5081a360f479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Wed, 18 Sep 2024 15:57:41 +0200 Subject: [PATCH] [FIX] composer: don't auto-complete when hidden Steps to reproduce: - type in a formula =SU - close the aut-completes with the cross at the top right corner - hit Enter => the formula is completed to =SUM( closes odoo/o-spreadsheet#4972 Task: 4176433 Signed-off-by: Pierre Rousseau (pro) --- src/components/composer/composer/composer.ts | 2 +- .../autocomplete_dropdown_component.test.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/composer/composer/composer.ts b/src/components/composer/composer/composer.ts index a79157c977..fbe757fd05 100644 --- a/src/components/composer/composer/composer.ts +++ b/src/components/composer/composer/composer.ts @@ -789,7 +789,7 @@ export class Composer extends Component } private autoComplete(value: string) { - if (!value) { + if (!value || this.assistant.forcedClosed) { return; } this.autoCompleteState.provider?.selectProposal(value); diff --git a/tests/composer/autocomplete_dropdown_component.test.ts b/tests/composer/autocomplete_dropdown_component.test.ts index 232169a684..af1f991a02 100644 --- a/tests/composer/autocomplete_dropdown_component.test.ts +++ b/tests/composer/autocomplete_dropdown_component.test.ts @@ -336,6 +336,24 @@ describe("Functions autocomplete", () => { expect(fixture.querySelector(".o-formula-assistant-container")).toBeTruthy(); expect(fixture.querySelector("#formula-assistant-details")?.className).not.toContain("show"); }); + + test("cannot auto-complete when it is closed", async () => { + await typeInComposer("=SU"); + expect(document.activeElement).toBe(composerEl); + expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(1); + + // hide the auto-complete + await click(fixture, ".fa-times-circle"); + expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(0); + await keyDown({ key: "Enter" }); + expect(composerStore.currentContent).toBe("=SU"); + + // show it again + await click(fixture, ".fa-question-circle"); + expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(1); + await keyDown({ key: "Enter" }); + expect(composerStore.currentContent).toBe("=SUM("); + }); }); describe("autocomplete functions SUM IF", () => {