Skip to content
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
34 changes: 34 additions & 0 deletions src/gui/MacroGUIs/CommandSequenceEditor.audit-macro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,40 @@ describe("CommandSequenceEditor silent-add feedback", () => {
editor.destroy();
});

// #2122: the first-macro walkthrough says "Add an Editor commands entry and
// choose ...", so Add is often clicked before anything is chosen.
it("does nothing when Add is clicked with nothing chosen", async () => {
const logError = vi.spyOn(log, "logError").mockImplementation(() => {});
const onCommandsChange = vi.fn();
const editor = new CommandSequenceEditor({
app: testApp(),
plugin: { settings: { choices: [] } } as unknown as QuickAdd,
commands: [],
choices: [],
onCommandsChange,
});
const container = document.createElement("div");
document.body.appendChild(container);
editor.render(container);

const editorCommands = container.querySelector("select");
if (!editorCommands) throw new Error("Editor commands dropdown not found");
for (const control of [
getInputByPlaceholder(container, "Obsidian command"),
editorCommands,
getInputByPlaceholder(container, "Choice"),
]) {
getAddButtonFor(control as HTMLInputElement).click();
}

expect(onCommandsChange).not.toHaveBeenCalled();
expect(noticeClass.instances).toEqual([]);
expect(logError).not.toHaveBeenCalled();

editor.destroy();
logError.mockRestore();
});

it("warns when adding a user-script name that resolves to nothing", async () => {
const onCommandsChange = vi.fn();
const editor = new CommandSequenceEditor({
Expand Down
3 changes: 3 additions & 0 deletions src/gui/MacroGUIs/CommandSequenceEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export class CommandSequenceEditor {

const addObsidianCommandFromInput = () => {
const value: string = input.getValue();
if (!value.trim()) return;
const obsidianCommand = this.obsidianCommands.find((v) => v.name === value);

if (!obsidianCommand) {
Expand Down Expand Up @@ -319,6 +320,7 @@ export class CommandSequenceEditor {
let dropdownComponent: DropdownComponent;

const addEditorCommandFromDropdown = () => {
if (!dropdownComponent.getValue()) return;
const Command = editorCommands.get(dropdownComponent.getValue());
if (!Command) {
log.logError("invalid editor command type");
Expand Down Expand Up @@ -426,6 +428,7 @@ export class CommandSequenceEditor {

const addChoiceFromInput = () => {
const value: string = input.getValue();
if (!value.trim()) return;
const choice = this.choices.find((c) => c.name === value);
if (!choice) {
new Notice(`QuickAdd: No choice named "${value}".`);
Expand Down
4 changes: 4 additions & 0 deletions tests/obsidian-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ export class DropdownComponent extends BaseComponent {
return this;
}

getValue(): string {
return this.selectEl.value;
}

onChange(cb: (value: string) => void): this {
this.selectEl.addEventListener("change", () => cb(this.selectEl.value));
return this;
Expand Down
Loading