fix(test): update component tests to match current implementation

- Add JsonEditor mock to McpFormModal tests (component uses CodeMirror
  instead of Textarea)
- Fix assertion for missing command error message
- Update ImportExportSection tests for new button behavior and file
  display format
This commit is contained in:
Jason
2025-11-28 16:20:18 +08:00
parent 3878a16c4f
commit f4c284f86c
2 changed files with 19 additions and 8 deletions
@@ -32,17 +32,17 @@ describe("ImportExportSection Component", () => {
it("should disable import button and show placeholder when no file selected", () => {
render(<ImportExportSection {...baseProps} />);
expect(screen.getByText("settings.noFileSelected")).toBeInTheDocument();
// When no file selected, button shows "selectConfigFile" and clicking it opens file dialog
expect(
screen.getByRole("button", { name: "settings.import" }),
).toBeDisabled();
screen.getByRole("button", { name: /settings\.selectConfigFile/ }),
).toBeInTheDocument();
fireEvent.click(
screen.getByRole("button", { name: "settings.exportConfig" }),
);
expect(baseProps.onExport).toHaveBeenCalledTimes(1);
fireEvent.click(
screen.getByRole("button", { name: "settings.selectConfigFile" }),
screen.getByRole("button", { name: /settings\.selectConfigFile/ }),
);
expect(baseProps.onSelectFile).toHaveBeenCalledTimes(1);
});
@@ -55,15 +55,15 @@ describe("ImportExportSection Component", () => {
/>,
);
expect(screen.getByText("config.json")).toBeInTheDocument();
expect(screen.getByText(/config\.json/)).toBeInTheDocument();
const importButton = screen.getByRole("button", {
name: "settings.import",
name: /settings\.import/,
});
expect(importButton).toBeEnabled();
fireEvent.click(importButton);
expect(baseProps.onImport).toHaveBeenCalledTimes(1);
fireEvent.click(screen.getByRole("button", { name: "common.clear" }));
fireEvent.click(screen.getByRole("button", { name: "Clear selection" }));
expect(baseProps.onClear).toHaveBeenCalledTimes(1);
});