feat(FN-3883): fix dependency-graph plugin exports and add CLI bundle entry
Fixed the `@fusion-plugin/dependency-graph` plugin's exports and build entry points so it bundles correctly with the CLI, added test coverage for plugin enable success and error-state toasts, and included the plugin's dist in the CLI bundle via tsup config. Fusion-Task-Id: FN-3883
This commit is contained in:
@@ -414,7 +414,13 @@ export function PluginManager({ addToast, projectId }: PluginManagerProps) {
|
||||
|
||||
const handleEnable = async (plugin: PluginInstallation) => {
|
||||
try {
|
||||
await enablePlugin(plugin.id, projectId);
|
||||
const enabledPlugin = await enablePlugin(plugin.id, projectId);
|
||||
if (enabledPlugin.state === "error") {
|
||||
addToast(`Failed to enable ${plugin.name}: ${enabledPlugin.error ?? "Unknown error"}`, "error");
|
||||
await loadPlugins();
|
||||
return;
|
||||
}
|
||||
|
||||
addToast(`${plugin.name} enabled for this project`, "success");
|
||||
await loadPlugins();
|
||||
} catch (err) {
|
||||
|
||||
@@ -517,7 +517,7 @@ describe("PluginManager", () => {
|
||||
|
||||
it("enables plugin when toggle is clicked", async () => {
|
||||
vi.mocked(fetchPlugins).mockResolvedValueOnce([{ ...mockPlugins[0], enabled: false }]);
|
||||
vi.mocked(enablePlugin).mockResolvedValueOnce({ ...mockPlugins[0], enabled: true });
|
||||
vi.mocked(enablePlugin).mockResolvedValueOnce({ ...mockPlugins[0], enabled: true, state: "started" });
|
||||
|
||||
render(<PluginManager addToast={addToast} />);
|
||||
|
||||
@@ -534,6 +534,53 @@ describe("PluginManager", () => {
|
||||
await waitFor(() => {
|
||||
expect(enablePlugin).toHaveBeenCalledWith("plugin-a", undefined);
|
||||
});
|
||||
|
||||
expect(addToast).toHaveBeenCalledWith("Test Plugin A enabled for this project", "success");
|
||||
expect(addToast).not.toHaveBeenCalledWith(expect.stringContaining("Failed to enable"), "error");
|
||||
});
|
||||
|
||||
it("shows loader error toast when enable returns error state", async () => {
|
||||
vi.mocked(fetchPlugins).mockResolvedValueOnce([{ ...mockPlugins[0], enabled: false }]);
|
||||
vi.mocked(enablePlugin).mockResolvedValueOnce({
|
||||
...mockPlugins[0],
|
||||
enabled: true,
|
||||
state: "error",
|
||||
error: "Cannot find module dependency-graph",
|
||||
});
|
||||
|
||||
render(<PluginManager addToast={addToast} />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Test Plugin A")).toBeTruthy();
|
||||
});
|
||||
|
||||
await userEvent.click(screen.getByRole("checkbox"));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(addToast).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Cannot find module dependency-graph"),
|
||||
"error",
|
||||
);
|
||||
});
|
||||
|
||||
expect(addToast).not.toHaveBeenCalledWith("Test Plugin A enabled for this project", "success");
|
||||
});
|
||||
|
||||
it("shows transport error toast when enable request rejects", async () => {
|
||||
vi.mocked(fetchPlugins).mockResolvedValueOnce([{ ...mockPlugins[0], enabled: false }]);
|
||||
vi.mocked(enablePlugin).mockRejectedValueOnce(new Error("network"));
|
||||
|
||||
render(<PluginManager addToast={addToast} />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("Test Plugin A")).toBeTruthy();
|
||||
});
|
||||
|
||||
await userEvent.click(screen.getByRole("checkbox"));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(addToast).toHaveBeenCalledWith("Failed to enable plugin: network", "error");
|
||||
});
|
||||
});
|
||||
|
||||
it("disables plugin when toggle is clicked", async () => {
|
||||
|
||||
Reference in New Issue
Block a user