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

fix: cli description #12192

Merged
merged 3 commits into from
Aug 8, 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
4 changes: 3 additions & 1 deletion packages/cli/src/userInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class CLIUserInteraction implements UserInteraction {
const choices = (option as OptionItem[]).map((op) => {
return {
id: op.id,
title: labelClean(op.label),
title: !op.description
? labelClean(op.label)
: labelClean(op.label) + ` (${op.description})`,
detail: op.detail,
};
});
Expand Down
30 changes: 30 additions & 0 deletions packages/cli/tests/unit/ui.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ describe("User Interaction Tests", function () {
}
});

it("Add description in title", async () => {
const config: SingleSelectConfig = {
name: "test",
title: "test",
options: [{ id: "id1", description: "some description", label: "label" }],
};
sandbox.stub(UI, "loadSelectDynamicData").resolves(ok({} as any));
sandbox.stub(UI, "singleSelect").resolves(ok("id1"));
const result = await UI.selectOption(config);
expect(result.isOk());
if (result.isOk()) {
expect(result.value.result).equal("id1");
}
});

it("No description in title", async () => {
const config: SingleSelectConfig = {
name: "test",
title: "test",
options: [{ id: "id1", label: "label" }],
};
sandbox.stub(UI, "loadSelectDynamicData").resolves(ok({} as any));
sandbox.stub(UI, "singleSelect").resolves(ok("id1"));
const result = await UI.selectOption(config);
expect(result.isOk());
if (result.isOk()) {
expect(result.value.result).equal("id1");
}
});

it("invalid option", async () => {
sandbox.stub(UI, "singleSelect").resolves(ok("c"));
const config: SingleSelectConfig = {
Expand Down
Loading