|
1 | 1 | import { describe, expect, it, vi } from "vitest"; |
2 | 2 | import { fireEvent, render } from "@testing-library/svelte"; |
| 3 | +import { tick } from "svelte"; |
3 | 4 |
|
4 | 5 | import { App } from "obsidian"; |
5 | 6 | import CommandList from "./CommandList.svelte"; |
@@ -68,3 +69,48 @@ describe("CommandList conditional branch persistence", () => { |
68 | 69 | expect(saveCommands).not.toHaveBeenCalled(); |
69 | 70 | }); |
70 | 71 | }); |
| 72 | + |
| 73 | +// A step added in this session is a class instance, which $state does not |
| 74 | +// proxy, so an in-place edit only shows if the list gets a new object (#2147). |
| 75 | +describe("CommandList conditional label after an edit", () => { |
| 76 | + function renderWith(handlers: Partial<Parameters<typeof createCommandListProps>[0]>) { |
| 77 | + const props = createCommandListProps({ |
| 78 | + commands: [new ConditionalCommand()], |
| 79 | + app: new App() as never, |
| 80 | + plugin: {} as never, |
| 81 | + deleteCommand: vi.fn(), |
| 82 | + saveCommands: vi.fn(), |
| 83 | + ...handlers, |
| 84 | + }); |
| 85 | + return render(CommandList, { props }); |
| 86 | + } |
| 87 | + |
| 88 | + it("shows the new condition once its dialog is saved", async () => { |
| 89 | + const { getByLabelText, container } = renderWith({ |
| 90 | + onConfigureCondition: (command) => { |
| 91 | + command.condition = { ...command.condition, variableName: "mood" } as typeof command.condition; |
| 92 | + return true; |
| 93 | + }, |
| 94 | + }); |
| 95 | + |
| 96 | + await fireEvent.click(getByLabelText("Edit condition for (missing variable) is truthy")); |
| 97 | + await tick(); |
| 98 | + |
| 99 | + expect(container.querySelector(".conditionalSummary")?.textContent).toBe("$mood is truthy"); |
| 100 | + expect(getByLabelText("Edit then branch for $mood is truthy")).toBeTruthy(); |
| 101 | + }); |
| 102 | + |
| 103 | + it("shows the new branch count once its page is left", async () => { |
| 104 | + const { getByLabelText, container } = renderWith({ |
| 105 | + onEditThenBranch: (command, onEdited) => { |
| 106 | + command.thenCommands = [new WaitCommand(100)]; |
| 107 | + onEdited(); |
| 108 | + }, |
| 109 | + }); |
| 110 | + |
| 111 | + await fireEvent.click(getByLabelText("Edit then branch for (missing variable) is truthy")); |
| 112 | + await tick(); |
| 113 | + |
| 114 | + expect(container.querySelector(".conditionalBranches")?.textContent).toContain("Then: 1"); |
| 115 | + }); |
| 116 | +}); |
0 commit comments