Skip to content
Closed
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
19 changes: 11 additions & 8 deletions src/components/composer/formula_assistant/formula_assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ export class FunctionDescriptionProvider extends Component<Props, SpreadsheetChi
if (displayBrackets) {
result.push({ content: "]" });
}
result.push({ content: argSeparator + "[" });
for (let idx = 0; idx < repeatingArgNames.length; idx++) {
const name = repeatingArgNames[idx];
result.push({ content: name + ((repeatingArgGroupIndex ?? 0) + 2) });
// Add separator after each element except the last
if (idx < repeatingArgNames.length - 1) {
result.push({ content: argSeparator });
if (functionDescription.nbrArgRepeating <= 1) {
result.push({ content: argSeparator + "[" });
for (let idx = 0; idx < repeatingArgNames.length; idx++) {
const name = repeatingArgNames[idx];
result.push({ content: name + ((repeatingArgGroupIndex ?? 0) + 2) });
// Add separator after each element except the last
if (idx < repeatingArgNames.length - 1) {
result.push({ content: argSeparator });
}
}
result.push({ content: "]" });
}
result.push({ content: "]" + argSeparator + "... " });
result.push({ content: argSeparator + "... " });

// Skip the processed repeating args
i += functionDescription.nbrArgRepeating - 1;
Expand Down
29 changes: 29 additions & 0 deletions tests/composer/formula_assistant_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,35 @@ describe("formula assistant", () => {
expect(fixture.querySelectorAll(".o-formula-assistant-head")[0].textContent).toBe(
"FUNC3 ( f3ArgA, f3ArgB1, [f3ArgB2], ... )"
);

await typeInComposer(", ,", false);
expect(fixture.querySelectorAll(".o-formula-assistant-head")[0].textContent).toBe(
"FUNC3 ( f3ArgA, ... , [f3ArgB2], [f3ArgB3], ... )"
);
});

test("function with repeatable argument optional", async () => {
await typeInComposer("=FUNC3BIS(");
expect(fixture.querySelectorAll(".o-formula-assistant-head")[0].textContent).toBe(
"FUNC3BIS ( f3bisArgA, [f3bisArgB1], [f3bisArgB2], ... )"
);

await typeInComposer(", ,", false);
expect(fixture.querySelectorAll(".o-formula-assistant-head")[0].textContent).toBe(
"FUNC3BIS ( f3bisArgA, ... , [f3bisArgB2], [f3bisArgB3], ... )"
);
});

test("function with multiple repeatable arguments", async () => {
await typeInComposer("=UPTOWNFUNC(");
expect(fixture.querySelectorAll(".o-formula-assistant-head")[0].textContent).toBe(
"UPTOWNFUNC ( f4ArgA, f4ArgB1, f4ArgC1, ... )"
);

await typeInComposer(", , ,", false);
expect(fixture.querySelectorAll(".o-formula-assistant-head")[0].textContent).toBe(
"UPTOWNFUNC ( f4ArgA, ... , [f4ArgB2, f4ArgC2], ... )"
);
});

test("arguments separator is localized", async () => {
Expand Down