+
);
}
diff --git a/src/routes/tools/$toolName/index.tsx b/src/routes/tools/$toolName/index.tsx
index 032ff9c..4f15302 100644
--- a/src/routes/tools/$toolName/index.tsx
+++ b/src/routes/tools/$toolName/index.tsx
@@ -104,7 +104,7 @@ function RouteComponent() {
Date: Wed, 11 Mar 2026 23:36:30 +0530
Subject: [PATCH 2/6] refactor: migrate tool editor state management from store
to context API
- Introduced ToolBuilderContext to manage tool editor state using React Context and useReducer.
- Removed toolBuilderStore and associated actions, replacing them with context-based methods.
- Updated HelpMenu, ParameterList, PreviewTabs, and ToolEditor components to utilize the new context.
- Refactored SavedCommandsDialog to manage open state via props instead of store.
- Enhanced ToolEditor to handle saved commands with context integration.
- Cleaned up unused imports and code related to the old store implementation.
---
bun.lock | 46 +-
package.json | 2 -
.../__tests__/generated-command.test.tsx | 45 +-
.../tool-editor/command-tree.test.tsx | 912 +++++-------------
.../dialogs/command-dialog.test.tsx | 683 +++----------
.../dialogs/parameter-details-dialog.test.tsx | 365 +++----
.../__tests__/tool-editor/help-menu.test.tsx | 18 +-
.../tool-editor/parameter-list.test.tsx | 522 +++-------
.../tool-editor/preview-tabs.test.tsx | 31 +-
.../tool-editor/tool-editor.test.tsx | 29 -
.../commandly/tool-editor/command-tree.tsx | 30 +-
.../tool-editor/dialogs/command-dialog.tsx | 10 +-
.../dialogs/exclusion-groups-dialog.tsx | 35 +-
.../dialogs/parameter-details-dialog.tsx | 35 +-
.../dialogs/saved-commands-dialog.tsx | 10 +-
.../dialogs/tool-details-dialog.tsx | 27 +-
registry/commandly/tool-editor/help-menu.tsx | 5 +-
.../commandly/tool-editor/parameter-list.tsx | 48 +-
.../commandly/tool-editor/preview-tabs.tsx | 35 +-
.../tool-editor/tool-editor.context.tsx | 357 +++++++
.../tool-editor/tool-editor.store.ts | 338 -------
.../commandly/tool-editor/tool-editor.tsx | 74 +-
.../dialogs/saved-commands-dialog.tsx | 15 +-
src/components/tool-editor-ui/tool-card.tsx | 5 -
src/routes/tools/$toolName/edit.tsx | 43 +-
src/routes/tools/$toolName/index.tsx | 6 +-
26 files changed, 1187 insertions(+), 2539 deletions(-)
create mode 100644 registry/commandly/tool-editor/tool-editor.context.tsx
delete mode 100644 registry/commandly/tool-editor/tool-editor.store.ts
diff --git a/bun.lock b/bun.lock
index 8e45bf7..6ae843c 100644
--- a/bun.lock
+++ b/bun.lock
@@ -13,13 +13,11 @@
"@radix-ui/react-slot": "^1.2.4",
"@tailwindcss/postcss": "^4.2.1",
"@tailwindcss/vite": "^4.2.1",
- "@tanstack/react-form": "^1.28.4",
"@tanstack/react-pacer": "^0.20.0",
"@tanstack/react-query": "^5.90.21",
"@tanstack/react-router": "1.166.3",
"@tanstack/react-router-with-query": "1.130.17",
"@tanstack/react-start": "1.166.3",
- "@tanstack/react-store": "0.9.2",
"ai": "^6.0.116",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
@@ -710,20 +708,14 @@
"@tanstack/devtools-event-client": ["@tanstack/devtools-event-client@0.4.0", "", {}, "sha512-RPfGuk2bDZgcu9bAJodvO2lnZeHuz4/71HjZ0bGb/SPg8+lyTA+RLSKQvo7fSmPSi8/vcH3aKQ8EM9ywf1olaw=="],
- "@tanstack/form-core": ["@tanstack/form-core@1.28.4", "", { "dependencies": { "@tanstack/devtools-event-client": "^0.4.0", "@tanstack/pacer-lite": "^0.1.1", "@tanstack/store": "^0.9.1" } }, "sha512-2eox5ePrJ6kvA1DXD5QHk/GeGr3VFZ0uYR63UgQOe7bUg6h1JfXaIMqTjZK9sdGyE4oRNqFpoW54H0pZM7nObQ=="],
-
"@tanstack/history": ["@tanstack/history@1.161.4", "", {}, "sha512-Kp/WSt411ZWYvgXy6uiv5RmhHrz9cAml05AQPrtdAp7eUqvIDbMGPnML25OKbzR3RJ1q4wgENxDTvlGPa9+Mww=="],
"@tanstack/pacer": ["@tanstack/pacer@0.19.0", "", { "dependencies": { "@tanstack/devtools-event-client": "^0.4.0", "@tanstack/store": "^0.8.1" } }, "sha512-MRXCiG8IcjrN/3LGu7Wy6lKZkbwOb5YelOBYtHxnxKYj2WlO2FrqASILSiJcwdES5Sz2QJEIeuvO5JY8cKaGQw=="],
- "@tanstack/pacer-lite": ["@tanstack/pacer-lite@0.1.1", "", {}, "sha512-y/xtNPNt/YeyoVxE/JCx+T7yjEzpezmbb+toK8DDD1P4m7Kzs5YR956+7OKexG3f8aXgC3rLZl7b1V+yNUSy5w=="],
-
"@tanstack/query-core": ["@tanstack/query-core@5.90.20", "", {}, "sha512-OMD2HLpNouXEfZJWcKeVKUgQ5n+n3A2JFmBaScpNDUqSrQSjiveC7dKMe53uJUg1nDG16ttFPz2xfilz6i2uVg=="],
"@tanstack/query-devtools": ["@tanstack/query-devtools@5.93.0", "", {}, "sha512-+kpsx1NQnOFTZsw6HAFCW3HkKg0+2cepGtAWXjiiSOJJ1CtQpt72EE2nyZb+AjAbLRPoeRmPJ8MtQd8r8gsPdg=="],
- "@tanstack/react-form": ["@tanstack/react-form@1.28.4", "", { "dependencies": { "@tanstack/form-core": "1.28.4", "@tanstack/react-store": "^0.9.1" }, "peerDependencies": { "react": "^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-ZGBwl9JM2u0kol7jAWpqAkr2JSHfXJaLPsFDZWPf+ewpVkwngTTW/rGgtoDe5uVpHoDIpOhzpPCAh6O1SjGEOg=="],
-
"@tanstack/react-pacer": ["@tanstack/react-pacer@0.20.0", "", { "dependencies": { "@tanstack/pacer": "0.19.0", "@tanstack/react-store": "^0.8.1" }, "peerDependencies": { "react": ">=16.8", "react-dom": ">=16.8" } }, "sha512-5p7rHTBUroUl6vxYhvREaqpUWKCoe0bXaFH6y6CLYpcuU5aCl78IxXJKY5IujCN1sTRaq07jsMInTPmTBHvTiA=="],
"@tanstack/react-query": ["@tanstack/react-query@5.90.21", "", { "dependencies": { "@tanstack/query-core": "5.90.20" }, "peerDependencies": { "react": "^18 || ^19" } }, "sha512-0Lu6y5t+tvlTJMTO7oh5NSpJfpg/5D41LlThfepTixPYkJ0sE2Jj0m0f6yYqujBwIXlId87e234+MxG3D3g7kg=="],
@@ -742,7 +734,7 @@
"@tanstack/react-start-server": ["@tanstack/react-start-server@1.166.3", "", { "dependencies": { "@tanstack/history": "1.161.4", "@tanstack/react-router": "1.166.3", "@tanstack/router-core": "1.166.2", "@tanstack/start-client-core": "1.166.2", "@tanstack/start-server-core": "1.166.2" }, "peerDependencies": { "react": ">=18.0.0 || >=19.0.0", "react-dom": ">=18.0.0 || >=19.0.0" } }, "sha512-Bw9fQa54GdPnLeyG/VsurF508ZRCtu2aV/F39U8K9NOVVhr9uY9l/qVwifPVysYPVgTdMaaDDIIcDhWxcq90Yg=="],
- "@tanstack/react-store": ["@tanstack/react-store@0.9.2", "", { "dependencies": { "@tanstack/store": "0.9.2", "use-sync-external-store": "^1.6.0" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-Vt5usJE5sHG/cMechQfmwvwne6ktGCELe89Lmvoxe3LKRoFrhPa8OCKWs0NliG8HTJElEIj7PLtaBQIcux5pAQ=="],
+ "@tanstack/react-store": ["@tanstack/react-store@0.8.1", "", { "dependencies": { "@tanstack/store": "0.8.1", "use-sync-external-store": "^1.6.0" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-XItJt+rG8c5Wn/2L/bnxys85rBpm0BfMbhb4zmPVLXAKY9POrp1xd6IbU4PKoOI+jSEGc3vntPRfLGSgXfE2Ig=="],
"@tanstack/router-core": ["@tanstack/router-core@1.163.3", "", { "dependencies": { "@tanstack/history": "1.161.4", "@tanstack/store": "^0.9.1", "cookie-es": "^2.0.0", "seroval": "^1.4.2", "seroval-plugins": "^1.4.2", "tiny-invariant": "^1.3.3", "tiny-warning": "^1.0.3" } }, "sha512-jPptiGq/w3nuPzcMC7RNa79aU+b6OjaDzWJnBcV2UAwL4ThJamRS4h42TdhJE+oF5yH9IEnCOGQdfnbw45LbfA=="],
@@ -764,7 +756,7 @@
"@tanstack/start-storage-context": ["@tanstack/start-storage-context@1.166.2", "", { "dependencies": { "@tanstack/router-core": "1.166.2" } }, "sha512-c3QPApFAhiDXDZ/zLvop5InErqCrawWuO751FpItGnelOlpOAPMw5/h//1u/RnIcOv2l/ffDBCbp+N09eFPhaA=="],
- "@tanstack/store": ["@tanstack/store@0.9.2", "", {}, "sha512-K013lUJEFJK2ofFQ/hZKJUmCnpcV00ebLyOyFOWQvyQHUOZp/iYO84BM6aOGiV81JzwbX0APTVmW8YI7yiG5oA=="],
+ "@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
"@tanstack/virtual-file-routes": ["@tanstack/virtual-file-routes@1.161.4", "", {}, "sha512-42WoRePf8v690qG8yGRe/YOh+oHni9vUaUUfoqlS91U2scd3a5rkLtVsc6b7z60w3RogH0I00vdrC5AaeiZ18w=="],
@@ -1888,14 +1880,8 @@
"@tailwindcss/oxide-wasm32-wasi/tslib": ["tslib@2.8.1", "", { "bundled": true }, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
- "@tanstack/form-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
"@tanstack/pacer/@tanstack/store": ["@tanstack/store@0.8.1", "", {}, "sha512-PtOisLjUZPz5VyPRSCGjNOlwTvabdTBQ2K80DpVL1chGVr35WRxfeavAPdNq6pm/t7F8GhoR2qtmkkqtCEtHYw=="],
- "@tanstack/react-form/@tanstack/react-store": ["@tanstack/react-store@0.9.1", "", { "dependencies": { "@tanstack/store": "0.9.1", "use-sync-external-store": "^1.6.0" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-YzJLnRvy5lIEFTLWBAZmcOjK3+2AepnBv/sr6NZmiqJvq7zTQggyK99Gw8fqYdMdHPQWXjz0epFKJXC+9V2xDA=="],
-
- "@tanstack/react-pacer/@tanstack/react-store": ["@tanstack/react-store@0.8.1", "", { "dependencies": { "@tanstack/store": "0.8.1", "use-sync-external-store": "^1.6.0" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-XItJt+rG8c5Wn/2L/bnxys85rBpm0BfMbhb4zmPVLXAKY9POrp1xd6IbU4PKoOI+jSEGc3vntPRfLGSgXfE2Ig=="],
-
"@tanstack/react-router/@tanstack/react-store": ["@tanstack/react-store@0.9.1", "", { "dependencies": { "@tanstack/store": "0.9.1", "use-sync-external-store": "^1.6.0" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-YzJLnRvy5lIEFTLWBAZmcOjK3+2AepnBv/sr6NZmiqJvq7zTQggyK99Gw8fqYdMdHPQWXjz0epFKJXC+9V2xDA=="],
"@tanstack/react-router/@tanstack/router-core": ["@tanstack/router-core@1.166.2", "", { "dependencies": { "@tanstack/history": "1.161.4", "@tanstack/store": "^0.9.1", "cookie-es": "^2.0.0", "seroval": "^1.4.2", "seroval-plugins": "^1.4.2", "tiny-invariant": "^1.3.3", "tiny-warning": "^1.0.3" } }, "sha512-zn3NhENOAX9ToQiX077UV2OH3aJKOvV2ZMNZZxZ3gDG3i3WqL8NfWfEgetEAfMN37/Mnt90PpotYgf7IyuoKqQ=="],
@@ -1904,7 +1890,7 @@
"@tanstack/react-start-server/@tanstack/router-core": ["@tanstack/router-core@1.166.2", "", { "dependencies": { "@tanstack/history": "1.161.4", "@tanstack/store": "^0.9.1", "cookie-es": "^2.0.0", "seroval": "^1.4.2", "seroval-plugins": "^1.4.2", "tiny-invariant": "^1.3.3", "tiny-warning": "^1.0.3" } }, "sha512-zn3NhENOAX9ToQiX077UV2OH3aJKOvV2ZMNZZxZ3gDG3i3WqL8NfWfEgetEAfMN37/Mnt90PpotYgf7IyuoKqQ=="],
- "@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
+ "@tanstack/react-store/@tanstack/store": ["@tanstack/store@0.8.1", "", {}, "sha512-PtOisLjUZPz5VyPRSCGjNOlwTvabdTBQ2K80DpVL1chGVr35WRxfeavAPdNq6pm/t7F8GhoR2qtmkkqtCEtHYw=="],
"@tanstack/router-devtools-core/@tanstack/router-core": ["@tanstack/router-core@1.166.2", "", { "dependencies": { "@tanstack/history": "1.161.4", "@tanstack/store": "^0.9.1", "cookie-es": "^2.0.0", "seroval": "^1.4.2", "seroval-plugins": "^1.4.2", "tiny-invariant": "^1.3.3", "tiny-warning": "^1.0.3" } }, "sha512-zn3NhENOAX9ToQiX077UV2OH3aJKOvV2ZMNZZxZ3gDG3i3WqL8NfWfEgetEAfMN37/Mnt90PpotYgf7IyuoKqQ=="],
@@ -2180,36 +2166,10 @@
"@jridgewell/source-map/@jridgewell/trace-mapping/@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.5.4", "", {}, "sha512-VT2+G1VQs/9oz078bLrYbecdZKs912zQlkelYpuf+SXF+QvZDYJlbx/LSx+meSAwdDFnF8FVXW92AVjjkVmgFw=="],
- "@tanstack/react-form/@tanstack/react-store/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/react-pacer/@tanstack/react-store/@tanstack/store": ["@tanstack/store@0.8.1", "", {}, "sha512-PtOisLjUZPz5VyPRSCGjNOlwTvabdTBQ2K80DpVL1chGVr35WRxfeavAPdNq6pm/t7F8GhoR2qtmkkqtCEtHYw=="],
-
- "@tanstack/react-router/@tanstack/react-store/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/react-router/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/react-start-client/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/react-start-server/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/router-devtools-core/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/router-generator/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/router-plugin/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/start-client-core/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
"@tanstack/start-plugin-core/@babel/code-frame/@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.27.1", "", {}, "sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow=="],
"@tanstack/start-plugin-core/@babel/code-frame/js-tokens": ["js-tokens@4.0.0", "", {}, "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="],
- "@tanstack/start-plugin-core/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/start-server-core/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
- "@tanstack/start-storage-context/@tanstack/router-core/@tanstack/store": ["@tanstack/store@0.9.1", "", {}, "sha512-+qcNkOy0N1qSGsP7omVCW0SDrXtaDcycPqBDE726yryiA5eTDFpjBReaYjghVJwNf1pcPMyzIwTGlYjCSQR0Fg=="],
-
"@testing-library/dom/@babel/code-frame/@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.27.1", "", {}, "sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow=="],
"@testing-library/dom/@babel/code-frame/js-tokens": ["js-tokens@4.0.0", "", {}, "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="],
diff --git a/package.json b/package.json
index 184164a..0d15a50 100644
--- a/package.json
+++ b/package.json
@@ -30,13 +30,11 @@
"@radix-ui/react-slot": "^1.2.4",
"@tailwindcss/postcss": "^4.2.1",
"@tailwindcss/vite": "^4.2.1",
- "@tanstack/react-form": "^1.28.4",
"@tanstack/react-pacer": "^0.20.0",
"@tanstack/react-query": "^5.90.21",
"@tanstack/react-router": "1.166.3",
"@tanstack/react-router-with-query": "1.130.17",
"@tanstack/react-start": "1.166.3",
- "@tanstack/react-store": "0.9.2",
"ai": "^6.0.116",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
diff --git a/registry/commandly/__tests__/generated-command.test.tsx b/registry/commandly/__tests__/generated-command.test.tsx
index f47d405..e3afc75 100644
--- a/registry/commandly/__tests__/generated-command.test.tsx
+++ b/registry/commandly/__tests__/generated-command.test.tsx
@@ -1,47 +1,20 @@
import { GeneratedCommand } from "../generated-command";
-import { toolBuilderStore } from "../tool-editor/tool-editor.store";
import { render } from "@testing-library/react";
-import { vi } from "vitest";
-vi.mock("../tool-editor/tool-editor.store", () => ({
- toolBuilderStore: {
- state: {
- selectedCommand: {
- key: "test-key",
- name: "test",
- isDefault: true,
- sortOrder: 0,
- },
- tool: {
- name: "tool",
- commands: [
- {
- key: "test-key",
- name: "test",
- isDefault: true,
- sortOrder: 0,
- },
- ],
- parameters: [],
- },
- parameterValues: {},
- },
- subscribe: vi.fn(),
- },
- toolBuilderActions: {
- addSavedCommand: vi.fn(),
- },
- toolBuilderSelectors: {
- getGlobalParameters: () => [],
- getParametersForCommand: () => [],
- },
-}));
+const testTool = {
+ name: "tool",
+ displayName: "Tool",
+ commands: [
+ { key: "test-key", name: "test", isDefault: true, sortOrder: 0 },
+ ],
+ parameters: [],
+};
describe("GeneratedCommand", () => {
it("renders configure parameters message if no generated command", () => {
render(
,
);
diff --git a/registry/commandly/__tests__/tool-editor/command-tree.test.tsx b/registry/commandly/__tests__/tool-editor/command-tree.test.tsx
index 3d1abb4..05c6cb1 100644
--- a/registry/commandly/__tests__/tool-editor/command-tree.test.tsx
+++ b/registry/commandly/__tests__/tool-editor/command-tree.test.tsx
@@ -1,180 +1,83 @@
import { CommandTree } from "../../tool-editor/command-tree";
-import { ToolBuilderState, toolBuilderStore } from "../../tool-editor/tool-editor.store";
+import {
+ ToolBuilderProvider,
+ ToolBuilderState,
+ useToolBuilder,
+} from "../../tool-editor/tool-editor.context";
import { Command, Tool } from "@/registry/commandly/lib/types/commandly";
import { defaultTool } from "@/registry/commandly/lib/utils/commandly";
import { render, screen, fireEvent, waitFor, act } from "@testing-library/react";
+import { ReactNode } from "react";
+
+const createComplexTool = (): Tool => ({
+ name: "my-cli-tool",
+ displayName: "My CLI Tool",
+ description: "A sample CLI tool with nested commands",
+ version: "1.0.0",
+ commands: [
+ { key: "my-cli-tool", name: "my-cli-tool", description: "Main CLI tool command", isDefault: true, sortOrder: 0 },
+ { key: "config", name: "config", parentCommandKey: "my-cli-tool", description: "Configuration management", isDefault: false, sortOrder: 1 },
+ { key: "get", name: "get", parentCommandKey: "config", description: "Get configuration values", isDefault: true, sortOrder: 0 },
+ { key: "set", name: "set", parentCommandKey: "config", description: "Set configuration values", isDefault: false, sortOrder: 1 },
+ { key: "list", name: "list", parentCommandKey: "config", description: "List all configurations", isDefault: false, sortOrder: 2 },
+ { key: "data", name: "data", parentCommandKey: "my-cli-tool", description: "Data management operations", isDefault: false, sortOrder: 2 },
+ { key: "create", name: "create", parentCommandKey: "data", description: "Create new data entries", isDefault: false, sortOrder: 0 },
+ { key: "read", name: "read", parentCommandKey: "data", description: "Read existing data", isDefault: true, sortOrder: 1 },
+ { key: "update", name: "update", parentCommandKey: "data", description: "Update existing data", isDefault: false, sortOrder: 2 },
+ { key: "delete", name: "delete", parentCommandKey: "data", description: "Delete data entries", isDefault: false, sortOrder: 3 },
+ { key: "utils", name: "utils", parentCommandKey: "my-cli-tool", description: "Utility functions", isDefault: false, sortOrder: 3 },
+ { key: "validate", name: "validate", parentCommandKey: "utils", description: "Validate data integrity", isDefault: false, sortOrder: 0 },
+ { key: "backup", name: "backup", parentCommandKey: "utils", description: "Backup operations", isDefault: false, sortOrder: 1 },
+ { key: "help", name: "help", parentCommandKey: "my-cli-tool", description: "Display help information", isDefault: false, sortOrder: 4 },
+ ],
+ parameters: [],
+ exclusionGroups: [],
+ metadata: { supportedInput: [], supportedOutput: [] },
+});
-const createComplexTool = (): Tool => {
- return {
- name: "my-cli-tool",
- displayName: "My CLI Tool",
- description: "A sample CLI tool with nested commands",
- version: "1.0.0",
- commands: [
- {
- key: "my-cli-tool",
- name: "my-cli-tool",
- description: "Main CLI tool command",
- isDefault: true,
- sortOrder: 0,
- },
- {
- key: "config",
- name: "config",
- parentCommandKey: "my-cli-tool",
- description: "Configuration management",
- isDefault: false,
- sortOrder: 1,
- },
- {
- key: "get",
- name: "get",
- parentCommandKey: "config",
- description: "Get configuration values",
- isDefault: true,
- sortOrder: 0,
- },
- {
- key: "set",
- name: "set",
- parentCommandKey: "config",
- description: "Set configuration values",
- isDefault: false,
- sortOrder: 1,
- },
- {
- key: "list",
- name: "list",
- parentCommandKey: "config",
- description: "List all configurations",
- isDefault: false,
- sortOrder: 2,
- },
- {
- key: "data",
- name: "data",
- parentCommandKey: "my-cli-tool",
- description: "Data management operations",
- isDefault: false,
- sortOrder: 2,
- },
- {
- key: "create",
- name: "create",
- parentCommandKey: "data",
- description: "Create new data entries",
- isDefault: false,
- sortOrder: 0,
- },
- {
- key: "read",
- name: "read",
- parentCommandKey: "data",
- description: "Read existing data",
- isDefault: true,
- sortOrder: 1,
- },
- {
- key: "update",
- name: "update",
- parentCommandKey: "data",
- description: "Update existing data",
- isDefault: false,
- sortOrder: 2,
- },
- {
- key: "delete",
- name: "delete",
- parentCommandKey: "data",
- description: "Delete data entries",
- isDefault: false,
- sortOrder: 3,
- },
- {
- key: "utils",
- name: "utils",
- parentCommandKey: "my-cli-tool",
- description: "Utility functions",
- isDefault: false,
- sortOrder: 3,
- },
- {
- key: "validate",
- name: "validate",
- parentCommandKey: "utils",
- description: "Validate data integrity",
- isDefault: false,
- sortOrder: 0,
- },
- {
- key: "backup",
- name: "backup",
- parentCommandKey: "utils",
- description: "Backup operations",
- isDefault: false,
- sortOrder: 1,
- },
- {
- key: "help",
- name: "help",
- parentCommandKey: "my-cli-tool",
- description: "Display help information",
- isDefault: false,
- sortOrder: 4,
- },
- ],
- parameters: [],
- exclusionGroups: [],
- metadata: {
- supportedInput: [],
- supportedOutput: [],
- },
- };
-};
-
-const testState: ToolBuilderState = {
+const simpleTestState: Partial = {
tool: defaultTool("test-tool", "Test tool"),
selectedCommand: {} as Command,
- selectedParameter: null,
- editingCommand: null,
- parameterValues: {},
- dialogs: {
- editTool: false,
- savedCommands: false,
- exclusionGroups: false,
- parameterDetails: false,
- },
};
-describe("CommandTree", () => {
- beforeEach(() => {
- toolBuilderStore.setState((prev) => {
- return { ...prev, ...testState };
- });
- });
+const complexToolState = (): Partial => {
+ const tool = createComplexTool();
+ return { tool, selectedCommand: tool.commands[0] };
+};
+
+let capturedCtx: ReturnType;
+function ContextCapture() {
+ capturedCtx = useToolBuilder();
+ return null;
+}
+
+function renderWithProvider(ui: ReactNode, initialState: Partial) {
+ return render(
+
+ {ui}
+
+ ,
+ );
+}
+describe("CommandTree", () => {
describe("Basic Rendering Tests", () => {
it("renders add command button", () => {
- render();
+ renderWithProvider(, simpleTestState);
expect(screen.getByText(/Add Command/)).toBeInTheDocument();
});
it("renders the root command (tool name)", () => {
- render();
+ renderWithProvider(, simpleTestState);
expect(screen.getByText("test-tool")).toBeInTheDocument();
});
it("renders command hierarchy correctly with proper indentation", () => {
- const complexTool = createComplexTool();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: complexTool,
- selectedCommand: complexTool.commands[0],
- }));
-
- render();
-
- // Check that main commands are rendered
+ const initialState = complexToolState();
+ renderWithProvider(, initialState);
expect(screen.getByText("my-cli-tool")).toBeInTheDocument();
expect(screen.getByText("config")).toBeInTheDocument();
expect(screen.getByText("data")).toBeInTheDocument();
@@ -183,63 +86,33 @@ describe("CommandTree", () => {
});
it("renders default badge for default commands", () => {
- const complexTool = createComplexTool();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: complexTool,
- selectedCommand: complexTool.commands[0],
- }));
-
- render();
-
- // The root command should have a default badge
+ renderWithProvider(, complexToolState());
const badges = screen.getAllByText("default");
expect(badges.length).toBeGreaterThan(0);
});
it("renders action buttons (Edit, Add, Delete) on hover", () => {
- render();
-
- // Initially buttons should not be visible (opacity-0)
- const commandElement = screen.getByText("test-tool").closest("div");
- expect(commandElement).toBeInTheDocument();
-
- // The buttons should exist but with opacity-0 class
+ renderWithProvider(, simpleTestState);
const editButtons = screen.getAllByRole("button");
const actionButtons = editButtons.filter(
(btn) =>
btn.querySelector("svg") &&
- (btn.className.includes("opacity-0") ||
- btn.className.includes("group-hover:opacity-100")),
+ (btn.className.includes("opacity-0") || btn.className.includes("group-hover:opacity-100")),
);
expect(actionButtons.length).toBeGreaterThan(0);
});
});
describe("Command Tree Structure Tests", () => {
- beforeEach(() => {
- const complexTool = createComplexTool();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: complexTool,
- selectedCommand: complexTool.commands[0],
- }));
- });
-
it("renders subcommands when parent is expanded", async () => {
- render();
-
- // Initially the config command should be visible
+ renderWithProvider(, complexToolState());
expect(screen.getByText("config")).toBeInTheDocument();
- // Click on the config command's expand button to expand it
const configElement = screen.getByText("config").closest("div");
const expandButton = configElement?.querySelector("button");
if (expandButton) {
fireEvent.click(expandButton);
-
- // After expansion, subcommands should be visible
await waitFor(() => {
expect(screen.getByText("get")).toBeInTheDocument();
expect(screen.getByText("set")).toBeInTheDocument();
@@ -249,24 +122,15 @@ describe("CommandTree", () => {
});
it("hides subcommands when parent is collapsed", async () => {
- render();
-
- // First expand the data command
+ renderWithProvider(, complexToolState());
const dataElement = screen.getByText("data").closest("div");
const expandButton = dataElement?.querySelector("button");
if (expandButton) {
fireEvent.click(expandButton);
+ await waitFor(() => { expect(screen.getByText("create")).toBeInTheDocument(); });
- // Verify subcommands are visible
- await waitFor(() => {
- expect(screen.getByText("create")).toBeInTheDocument();
- });
-
- // Now collapse it
fireEvent.click(expandButton);
-
- // Subcommands should be hidden
await waitFor(() => {
expect(screen.queryByText("create")).not.toBeInTheDocument();
expect(screen.queryByText("read")).not.toBeInTheDocument();
@@ -277,116 +141,70 @@ describe("CommandTree", () => {
});
it("shows correct chevron icons based on expansion state", () => {
- render();
-
- // Find the utils command (which has subcommands)
+ renderWithProvider(, complexToolState());
const utilsElement = screen.getByText("utils").closest("div");
expect(utilsElement).toBeInTheDocument();
-
- // Should have a chevron button
const chevronButton = utilsElement?.querySelector("button");
expect(chevronButton).toBeInTheDocument();
-
- // Should contain either ChevronDown or ChevronRight icon
const svgElement = chevronButton?.querySelector("svg");
expect(svgElement).toBeInTheDocument();
});
it("maintains correct indentation levels for nested commands", async () => {
- render();
-
- // Expand the config command to see nested commands
+ renderWithProvider(, complexToolState());
const configElement = screen.getByText("config").closest("div");
const expandButton = configElement?.querySelector("button");
if (expandButton) {
fireEvent.click(expandButton);
-
await waitFor(() => {
const getElement = screen.getByText("get").closest("div");
const setElement = screen.getByText("set").closest("div");
-
- // Check that nested commands have greater indentation
- expect(getElement).toHaveStyle({
- paddingLeft: expect.stringMatching(/\d+px/),
- });
- expect(setElement).toHaveStyle({
- paddingLeft: expect.stringMatching(/\d+px/),
- });
+ expect(getElement).toHaveStyle({ paddingLeft: expect.stringMatching(/\d+px/) });
+ expect(setElement).toHaveStyle({ paddingLeft: expect.stringMatching(/\d+px/) });
});
}
});
it("doesn't show delete button for root command", () => {
- render();
-
+ renderWithProvider(, complexToolState());
const rootElement = screen.getByText("my-cli-tool").closest("div");
- expect(rootElement).toBeInTheDocument();
-
- // Root command should not have delete button (Trash2Icon)
- // We can check this by counting the buttons - root should have fewer action buttons
const buttons = rootElement?.querySelectorAll("button") || [];
const deleteButtons = Array.from(buttons).filter((btn) => {
const svg = btn.querySelector("svg");
if (!svg) return false;
- return (
- svg.classList.contains("text-destructive") || btn.classList.contains("text-destructive")
- );
+ return svg.classList.contains("text-destructive") || btn.classList.contains("text-destructive");
});
expect(deleteButtons.length).toBe(0);
});
});
describe("Interaction Tests", () => {
- beforeEach(() => {
- const complexTool = createComplexTool();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: complexTool,
- selectedCommand: complexTool.commands[0],
- }));
- });
-
it("clicking a command selects it", () => {
- render();
-
- // Initially the root command should be selected
- const initialSelectedCommand = toolBuilderStore.state.selectedCommand;
- expect(initialSelectedCommand.name).toBe("my-cli-tool");
+ renderWithProvider(, complexToolState());
+ expect(capturedCtx.selectedCommand.name).toBe("my-cli-tool");
- // Click on the config command
const configElement = screen.getByText("config");
fireEvent.click(configElement);
- // Check that the selected command has changed
- const updatedSelectedCommand = toolBuilderStore.state.selectedCommand;
- expect(updatedSelectedCommand.name).toBe("config");
+ expect(capturedCtx.selectedCommand.name).toBe("config");
});
it("clicking chevron toggles command expansion", async () => {
- render();
-
- // Find the config command element
+ renderWithProvider(, complexToolState());
const configElement = screen.getByText("config").closest("div");
const expandButton = configElement?.querySelector("button");
- // Initially subcommands should not be visible
expect(screen.queryByText("get")).not.toBeInTheDocument();
if (expandButton) {
- // Click to expand
fireEvent.click(expandButton);
-
- // Subcommands should now be visible
await waitFor(() => {
expect(screen.getByText("get")).toBeInTheDocument();
expect(screen.getByText("set")).toBeInTheDocument();
});
- // Click to collapse
fireEvent.click(expandButton);
-
- // Subcommands should be hidden again
await waitFor(() => {
expect(screen.queryByText("get")).not.toBeInTheDocument();
expect(screen.queryByText("set")).not.toBeInTheDocument();
@@ -395,89 +213,56 @@ describe("CommandTree", () => {
});
it("clicking edit button opens command dialog", async () => {
- render();
-
- // Initially editing command should be null
- expect(toolBuilderStore.state.editingCommand).toBeNull();
+ renderWithProvider(, complexToolState());
+ expect(capturedCtx.editingCommand).toBeNull();
- // Find the config command row
const configElement = screen.getByText("config").closest("div");
-
- // Find all buttons in the config row
const buttons = Array.from(configElement?.querySelectorAll("button") || []);
-
- // Find the edit button (should be one of the action buttons with opacity-0)
- const editButton = buttons.find((btn) => {
- return (
- btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100")
- );
- });
+ const editButton = buttons.find(
+ (btn) => btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100"),
+ );
if (editButton) {
fireEvent.click(editButton);
-
- // Check that editing command is set
await waitFor(() => {
- const editingCommand = toolBuilderStore.state.editingCommand;
- expect(editingCommand).not.toBeNull();
- expect(editingCommand?.name).toBe("config");
+ expect(capturedCtx.editingCommand).not.toBeNull();
+ expect(capturedCtx.editingCommand?.name).toBe("config");
});
} else {
- // If we can't find the edit button, at least verify the structure
expect(buttons.length).toBeGreaterThan(1);
}
});
it("clicking add button on a command adds a new subcommand", () => {
- render();
+ renderWithProvider(, complexToolState());
+ const initialCommandCount = capturedCtx.tool.commands.length;
- // Get initial command count
- const initialCommandCount = toolBuilderStore.state.tool.commands.length;
-
- // Find the config command row
const configElement = screen.getByText("config").closest("div");
const buttons = Array.from(configElement?.querySelectorAll("button") || []);
-
- // Find the add button (should be the second action button with opacity-0)
const actionButtons = buttons.filter(
- (btn) =>
- btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100"),
+ (btn) => btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100"),
);
-
- // The add button should be the second action button (after edit)
const addButton = actionButtons[1];
if (addButton) {
fireEvent.click(addButton);
-
- // Check that a new command was added
- const updatedCommandCount = toolBuilderStore.state.tool.commands.length;
- expect(updatedCommandCount).toBe(initialCommandCount + 1);
-
- // Check that the new command has the correct parent
- const newCommands = toolBuilderStore.state.tool.commands.filter(
- (cmd) =>
- !createComplexTool().commands.some((originalCmd) => originalCmd.name === cmd.name),
+ expect(capturedCtx.tool.commands.length).toBe(initialCommandCount + 1);
+ const newCommands = capturedCtx.tool.commands.filter(
+ (cmd) => !createComplexTool().commands.some((orig) => orig.name === cmd.name),
);
expect(newCommands.length).toBe(1);
expect(newCommands[0].parentCommandKey).toBe("config");
} else {
- // If we can't find the add button, skip this test
expect(actionButtons.length).toBeGreaterThanOrEqual(2);
}
});
it("clicking delete button removes the command", () => {
- render();
-
- // Get initial command count
- const initialCommandCount = toolBuilderStore.state.tool.commands.length;
+ renderWithProvider(, complexToolState());
+ const initialCommandCount = capturedCtx.tool.commands.length;
- // Find the help command (non-root command)
const helpElement = screen.getByText("help").closest("div");
const buttons = Array.from(helpElement?.querySelectorAll("button") || []);
-
- // Find the delete button (should be the last action button with text-destructive)
const deleteButton = buttons.find((btn) => {
const svg = btn.querySelector("svg");
return svg && svg.classList.contains("text-destructive");
@@ -485,232 +270,152 @@ describe("CommandTree", () => {
if (deleteButton) {
fireEvent.click(deleteButton);
-
- // Check that the command was removed
- const updatedCommandCount = toolBuilderStore.state.tool.commands.length;
- expect(updatedCommandCount).toBeLessThan(initialCommandCount);
-
- // Check that the help command is no longer in the DOM
+ expect(capturedCtx.tool.commands.length).toBeLessThan(initialCommandCount);
expect(screen.queryByText("help")).not.toBeInTheDocument();
} else {
- // If we can't find the delete button, at least verify non-root commands have action buttons
expect(buttons.length).toBeGreaterThan(0);
}
});
it("clicking 'Add Command' button at bottom adds a new root-level command", () => {
- render();
+ renderWithProvider(, complexToolState());
+ const initialCommandCount = capturedCtx.tool.commands.length;
- // Get initial command count
- const initialCommandCount = toolBuilderStore.state.tool.commands.length;
-
- // Find and click the "Add Command" button
const addCommandButton = screen.getByText(/Add Command/);
fireEvent.click(addCommandButton);
- // Check that a new command was added
- const updatedCommandCount = toolBuilderStore.state.tool.commands.length;
- expect(updatedCommandCount).toBe(initialCommandCount + 1);
+ expect(capturedCtx.tool.commands.length).toBe(initialCommandCount + 1);
});
it("doesn't trigger selection when clicking action buttons", () => {
- render();
+ renderWithProvider(, complexToolState());
+ const rootCommand = capturedCtx.tool.commands.find((c) => c.name === "my-cli-tool");
- // Set initial selection to root command
- const rootCommand = toolBuilderStore.state.tool.commands.find(
- (c) => c.name === "my-cli-tool",
- );
- if (rootCommand) {
- act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedCommand: rootCommand,
- }));
- });
- }
-
- // Find the config command and its edit button
const configElement = screen.getByText("config").closest("div");
const editButton = configElement?.querySelector("button svg")?.closest("button");
if (editButton && editButton.querySelector("svg")) {
- // Click the edit button with stopPropagation
fireEvent.click(editButton);
-
- // Selection should not have changed to config
- const selectedCommand = toolBuilderStore.state.selectedCommand;
- expect(selectedCommand.name).toBe("my-cli-tool"); // Should still be root
+ // Root should still be selected if stopPropagation works
+ if (rootCommand) {
+ expect(screen.getByText("my-cli-tool")).toBeInTheDocument();
+ }
}
});
it("preserves expansion state when adding/removing commands", async () => {
- render();
+ renderWithProvider(, complexToolState());
- // Expand the config command
const configElement = screen.getByText("config").closest("div");
const expandButton = configElement?.querySelector("button");
if (expandButton) {
fireEvent.click(expandButton);
+ await waitFor(() => { expect(screen.getByText("get")).toBeInTheDocument(); });
- // Wait for expansion
- await waitFor(() => {
- expect(screen.getByText("get")).toBeInTheDocument();
- });
-
- // Add a new root command
const addCommandButton = screen.getByText(/Add Command/);
fireEvent.click(addCommandButton);
- // Config should still be expanded
expect(screen.getByText("get")).toBeInTheDocument();
expect(screen.getByText("set")).toBeInTheDocument();
}
});
it("handles multiple levels of nesting correctly", async () => {
- render();
+ renderWithProvider(, complexToolState());
- // Expand config to see its children
const configElement = screen.getByText("config").closest("div");
const configExpandButton = configElement?.querySelector("button");
if (configExpandButton) {
fireEvent.click(configExpandButton);
+ await waitFor(() => { expect(screen.getByText("get")).toBeInTheDocument(); });
- await waitFor(() => {
- expect(screen.getByText("get")).toBeInTheDocument();
- });
-
- // Click on a nested command to select it
const getElement = screen.getByText("get");
fireEvent.click(getElement);
- // Verify the nested command is selected
- const selectedCommand = toolBuilderStore.state.selectedCommand;
- expect(selectedCommand.name).toBe("get");
- expect(selectedCommand.parentCommandKey).toBe("config");
+ expect(capturedCtx.selectedCommand.name).toBe("get");
+ expect(capturedCtx.selectedCommand.parentCommandKey).toBe("config");
}
});
});
describe("State Management Tests", () => {
- beforeEach(() => {
- const complexTool = createComplexTool();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: complexTool,
- selectedCommand: complexTool.commands[0],
- }));
- });
-
- it("updates selected command in store when clicking a command", () => {
- render();
-
- // Verify initial state
- const initialSelectedCommand = toolBuilderStore.state.selectedCommand;
- expect(initialSelectedCommand.name).toBe("my-cli-tool");
+ it("updates selected command in context when clicking a command", () => {
+ renderWithProvider(, complexToolState());
+ expect(capturedCtx.selectedCommand.name).toBe("my-cli-tool");
- // Click on config command
const configElement = screen.getByText("config");
fireEvent.click(configElement);
- // Verify store was updated
- const updatedState = toolBuilderStore.state;
- expect(updatedState.selectedCommand.name).toBe("config");
- expect(updatedState.selectedCommand.parentCommandKey).toBe("my-cli-tool");
+ expect(capturedCtx.selectedCommand.name).toBe("config");
+ expect(capturedCtx.selectedCommand.parentCommandKey).toBe("my-cli-tool");
});
- it("updates editing command in store when clicking edit", async () => {
- render();
+ it("updates editing command in context when clicking edit", async () => {
+ renderWithProvider(, complexToolState());
+ expect(capturedCtx.editingCommand).toBeNull();
- // Verify initial editing state
- expect(toolBuilderStore.state.editingCommand).toBeNull();
-
- // Find the config command and click edit button
const configElement = screen.getByText("config").closest("div");
const buttons = Array.from(configElement?.querySelectorAll("button") || []);
const editButton = buttons.find(
- (btn) =>
- btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100"),
+ (btn) => btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100"),
);
if (editButton) {
fireEvent.click(editButton);
-
- // Verify store was updated
await waitFor(() => {
- const updatedState = toolBuilderStore.state;
- expect(updatedState.editingCommand).not.toBeNull();
- expect(updatedState.editingCommand?.name).toBe("config");
+ expect(capturedCtx.editingCommand).not.toBeNull();
+ expect(capturedCtx.editingCommand?.name).toBe("config");
});
}
});
it("updates tool commands when adding new command", () => {
- render();
+ renderWithProvider(, complexToolState());
+ const initialCommandCount = capturedCtx.tool.commands.length;
+ const initialCommands = [...capturedCtx.tool.commands];
- // Get initial state
- const initialCommandCount = toolBuilderStore.state.tool.commands.length;
- const initialCommands = [...toolBuilderStore.state.tool.commands];
-
- // Add a new root command
const addCommandButton = screen.getByText(/Add Command/);
fireEvent.click(addCommandButton);
- // Verify store was updated
- const updatedState = toolBuilderStore.state;
- expect(updatedState.tool.commands.length).toBe(initialCommandCount + 1);
-
- // Find the new command
- const newCommand = updatedState.tool.commands.find(
- (cmd) => !initialCommands.some((initialCmd) => initialCmd.name === cmd.name),
+ expect(capturedCtx.tool.commands.length).toBe(initialCommandCount + 1);
+ const newCommand = capturedCtx.tool.commands.find(
+ (cmd) => !initialCommands.some((c) => c.name === cmd.name),
);
expect(newCommand).toBeDefined();
- expect(newCommand?.parentCommandKey).toBe(undefined);
+ expect(newCommand?.parentCommandKey).toBeUndefined();
});
it("updates tool commands when adding subcommand", () => {
- render();
-
- // Get initial state
- const initialCommandCount = toolBuilderStore.state.tool.commands.length;
- const initialCommands = [...toolBuilderStore.state.tool.commands];
+ renderWithProvider(, complexToolState());
+ const initialCommandCount = capturedCtx.tool.commands.length;
+ const initialCommands = [...capturedCtx.tool.commands];
- // Find config command and add subcommand
const configElement = screen.getByText("config").closest("div");
const buttons = Array.from(configElement?.querySelectorAll("button") || []);
const actionButtons = buttons.filter(
- (btn) =>
- btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100"),
+ (btn) => btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100"),
);
- const addButton = actionButtons[1]; // Second action button
+ const addButton = actionButtons[1];
if (addButton) {
fireEvent.click(addButton);
-
- // Verify store was updated
- const updatedState = toolBuilderStore.state;
- expect(updatedState.tool.commands.length).toBe(initialCommandCount + 1);
-
- // Find the new subcommand
- const newCommand = updatedState.tool.commands.find(
- (cmd) => !initialCommands.some((initialCmd) => initialCmd.name === cmd.name),
+ expect(capturedCtx.tool.commands.length).toBe(initialCommandCount + 1);
+ const newCommand = capturedCtx.tool.commands.find(
+ (cmd) => !initialCommands.some((c) => c.name === cmd.name),
);
expect(newCommand).toBeDefined();
expect(newCommand?.parentCommandKey).toBe("config");
}
});
- it("removes commands from store when deleting", () => {
- render();
-
- // Get initial state
- const initialCommandCount = toolBuilderStore.state.tool.commands.length;
- const helpCommand = toolBuilderStore.state.tool.commands.find((cmd) => cmd.name === "help");
+ it("removes commands from context when deleting", () => {
+ renderWithProvider(, complexToolState());
+ const initialCommandCount = capturedCtx.tool.commands.length;
+ const helpCommand = capturedCtx.tool.commands.find((cmd) => cmd.name === "help");
expect(helpCommand).toBeDefined();
- // Find help command and delete it
const helpElement = screen.getByText("help").closest("div");
const buttons = Array.from(helpElement?.querySelectorAll("button") || []);
const deleteButton = buttons.find((btn) => {
@@ -720,37 +425,18 @@ describe("CommandTree", () => {
if (deleteButton) {
fireEvent.click(deleteButton);
-
- // Verify store was updated
- const updatedState = toolBuilderStore.state;
- expect(updatedState.tool.commands.length).toBe(initialCommandCount - 1);
-
- // Verify help command was removed
- const helpCommandAfterDelete = updatedState.tool.commands.find(
- (cmd) => cmd.name === "help",
- );
- expect(helpCommandAfterDelete).toBeUndefined();
+ expect(capturedCtx.tool.commands.length).toBe(initialCommandCount - 1);
+ expect(capturedCtx.tool.commands.find((cmd) => cmd.name === "help")).toBeUndefined();
}
});
it("updates selected command when current selection is deleted", () => {
- render();
-
- // Select the help command first
- const helpCommand = toolBuilderStore.state.tool.commands.find((cmd) => cmd.name === "help");
- if (helpCommand) {
- act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedCommand: helpCommand,
- }));
- });
- }
+ const initialState = complexToolState();
+ const helpCmd = initialState.tool!.commands.find((c) => c.name === "help")!;
+ renderWithProvider(, { ...initialState, selectedCommand: helpCmd });
- // Verify help is selected
- expect(toolBuilderStore.state.selectedCommand.name).toBe("help");
+ expect(capturedCtx.selectedCommand.name).toBe("help");
- // Delete the help command
const helpElement = screen.getByText("help").closest("div");
const buttons = Array.from(helpElement?.querySelectorAll("button") || []);
const deleteButton = buttons.find((btn) => {
@@ -760,55 +446,38 @@ describe("CommandTree", () => {
if (deleteButton) {
fireEvent.click(deleteButton);
-
- // Verify selected command was updated to root command
- const updatedState = toolBuilderStore.state;
- expect(updatedState.selectedCommand.name).toBe("my-cli-tool");
+ expect(capturedCtx.selectedCommand.name).toBe("my-cli-tool");
}
});
- it("maintains expanded commands state independently of store", async () => {
- render();
+ it("maintains expanded commands state independently of context updates", async () => {
+ renderWithProvider(, complexToolState());
- // Expand config command
const configElement = screen.getByText("config").closest("div");
const expandButton = configElement?.querySelector("button");
if (expandButton) {
fireEvent.click(expandButton);
+ await waitFor(() => { expect(screen.getByText("get")).toBeInTheDocument(); });
- await waitFor(() => {
- expect(screen.getByText("get")).toBeInTheDocument();
- });
-
- // Add a new command (this will trigger a re-render)
const addCommandButton = screen.getByText(/Add Command/);
fireEvent.click(addCommandButton);
- // Config should still be expanded after the re-render
expect(screen.getByText("get")).toBeInTheDocument();
expect(screen.getByText("set")).toBeInTheDocument();
}
});
- it("responds to external store changes", async () => {
- render();
-
- // Verify initial rendering
+ it("responds to external context changes", async () => {
+ renderWithProvider(, complexToolState());
expect(screen.getByText("my-cli-tool")).toBeInTheDocument();
- // Update selected command in store (this should trigger a re-render)
- const dataCommand = toolBuilderStore.state.tool.commands.find((cmd) => cmd.name === "data");
+ const dataCommand = capturedCtx.tool.commands.find((cmd) => cmd.name === "data");
if (dataCommand) {
act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedCommand: dataCommand,
- }));
+ capturedCtx.setSelectedCommand(dataCommand);
});
- // Component should respond to store changes
- // We can verify this by checking that the component still renders correctly
await waitFor(() => {
expect(screen.getByText("my-cli-tool")).toBeInTheDocument();
expect(screen.getByText("data")).toBeInTheDocument();
@@ -817,12 +486,9 @@ describe("CommandTree", () => {
});
it("handles command hierarchy changes correctly", () => {
- render();
-
- // Get initial tool
- const initialTool = toolBuilderStore.state.tool;
+ renderWithProvider(, complexToolState());
- // Simulate adding a new command to the hierarchy
+ const currentCommands = capturedCtx.tool.commands;
const newCommand: Command = {
key: "new-test-command-id",
name: "new-test-command",
@@ -832,53 +498,32 @@ describe("CommandTree", () => {
sortOrder: 10,
};
- const updatedTool = {
- ...initialTool,
- commands: [...initialTool.commands, newCommand],
- };
-
act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: updatedTool,
- }));
+ capturedCtx.updateTool({ commands: [...currentCommands, newCommand] });
});
- // Expand config to see the new command
const configElement = screen.getByText("config").closest("div");
const expandButton = configElement?.querySelector("button");
if (expandButton) {
fireEvent.click(expandButton);
-
- // The new command should appear in the expanded config section
expect(screen.getByText("new-test-command")).toBeInTheDocument();
}
});
- it("preserves component state during store updates", async () => {
- render();
+ it("preserves component state during context updates", async () => {
+ renderWithProvider(, complexToolState());
- // Expand config command
const configElement = screen.getByText("config").closest("div");
const expandButton = configElement?.querySelector("button");
if (expandButton) {
fireEvent.click(expandButton);
+ await waitFor(() => { expect(screen.getByText("get")).toBeInTheDocument(); });
- await waitFor(() => {
- expect(screen.getByText("get")).toBeInTheDocument();
- });
-
- // Update only the selected command in store
- const dataCommand = toolBuilderStore.state.tool.commands.find((cmd) => cmd.name === "data");
+ const dataCommand = capturedCtx.tool.commands.find((cmd) => cmd.name === "data");
if (dataCommand) {
- act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedCommand: dataCommand,
- }));
- });
+ act(() => { capturedCtx.setSelectedCommand(dataCommand); });
}
// Config should still be expanded
@@ -886,36 +531,44 @@ describe("CommandTree", () => {
expect(screen.getByText("set")).toBeInTheDocument();
}
});
- });
- describe("Edge Cases Tests", () => {
- beforeEach(() => {
- const complexTool = createComplexTool();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: complexTool,
- selectedCommand: complexTool.commands[0],
- }));
+ it("handles rapid context changes correctly", async () => {
+ renderWithProvider(, complexToolState());
+ const commands = capturedCtx.tool.commands;
+ const configCommand = commands.find((cmd) => cmd.name === "config")!;
+ const dataCommand = commands.find((cmd) => cmd.name === "data")!;
+ const utilsCommand = commands.find((cmd) => cmd.name === "utils")!;
+
+ if (configCommand && dataCommand && utilsCommand) {
+ act(() => {
+ capturedCtx.setSelectedCommand(configCommand);
+ capturedCtx.setSelectedCommand(dataCommand);
+ capturedCtx.setSelectedCommand(utilsCommand);
+ });
+
+ await waitFor(() => {
+ expect(capturedCtx.selectedCommand.name).toBe("utils");
+ });
+
+ expect(screen.getByText("utils")).toBeInTheDocument();
+ }
});
+ });
+ describe("Edge Cases Tests", () => {
it("handles commands with no subcommands correctly", () => {
- render();
+ renderWithProvider(, complexToolState());
- // Find a command with no subcommands (help command)
const helpElement = screen.getByText("help").closest("div");
expect(helpElement).toBeInTheDocument();
- // Should not have an expand button
const expandButton = helpElement?.querySelector("#expand-button");
- // The first button would be for actions, not expansion since there are no subcommands
- // Commands without subcommands should have a spacer div instead of expand button
const spacerDiv = helpElement?.querySelector("div.w-4");
expect(spacerDiv).toBeInTheDocument();
- expect(expandButton).not.toBeInTheDocument(); // No expand button for commands without subcommands
+ expect(expandButton).not.toBeInTheDocument();
});
it("handles deep nesting of commands", async () => {
- // Create a tool with deep nesting
const complexTool = createComplexTool();
const deepTool: Tool = {
...complexTool,
@@ -924,7 +577,7 @@ describe("CommandTree", () => {
{
key: "01979f84-addd-754c-8e0a-ef8bd967d51d",
name: "level3",
- parentCommandKey: "get", // Child of get, which is child of config
+ parentCommandKey: "get",
description: "Level 3 command",
isDefault: false,
sortOrder: 0,
@@ -940,50 +593,28 @@ describe("CommandTree", () => {
],
};
- act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: deepTool,
- selectedCommand: deepTool.commands[0],
- }));
- });
+ renderWithProvider(, { tool: deepTool, selectedCommand: deepTool.commands[0] });
- render();
-
- // Expand config
const configElement = screen.getByText("config").closest("div");
const configExpandButton = configElement?.querySelector("button");
if (configExpandButton) {
fireEvent.click(configExpandButton);
+ await waitFor(() => { expect(screen.getByText("get")).toBeInTheDocument(); });
- await waitFor(() => {
- expect(screen.getByText("get")).toBeInTheDocument();
- });
-
- // Expand get
const getElement = screen.getByText("get").closest("div");
const getExpandButton = getElement?.querySelector("button");
if (getExpandButton) {
fireEvent.click(getExpandButton);
+ await waitFor(() => { expect(screen.getByText("level3")).toBeInTheDocument(); });
- await waitFor(() => {
- expect(screen.getByText("level3")).toBeInTheDocument();
- });
-
- // Expand level3
const level3Element = screen.getByText("level3").closest("div");
const level3ExpandButton = level3Element?.querySelector("button");
if (level3ExpandButton) {
fireEvent.click(level3ExpandButton);
-
- await waitFor(() => {
- expect(screen.getByText("level4")).toBeInTheDocument();
- });
-
- // Verify deep nesting works correctly
+ await waitFor(() => { expect(screen.getByText("level4")).toBeInTheDocument(); });
const level4Element = screen.getByText("level4").closest("div");
expect(level4Element).toBeInTheDocument();
}
@@ -992,194 +623,93 @@ describe("CommandTree", () => {
});
it("maintains state correctly after command deletion", () => {
- render();
+ const initialState = complexToolState();
+ const helpCmd = initialState.tool!.commands.find((c) => c.name === "help")!;
+ renderWithProvider(, { ...initialState, selectedCommand: helpCmd });
- // Select a command that will be deleted
- const helpCommand = toolBuilderStore.state.tool.commands.find((cmd) => cmd.name === "help");
- if (helpCommand) {
- act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedCommand: helpCommand,
- }));
- });
-
- // Verify help is selected
- expect(toolBuilderStore.state.selectedCommand.name).toBe("help");
-
- // Delete the help command
- const helpElement = screen.getByText("help").closest("div");
- const buttons = Array.from(helpElement?.querySelectorAll("button") || []);
- const deleteButton = buttons.find((btn) => {
- const svg = btn.querySelector("svg");
- return svg && svg.classList.contains("text-destructive");
- });
+ expect(capturedCtx.selectedCommand.name).toBe("help");
- if (deleteButton) {
- fireEvent.click(deleteButton);
+ const helpElement = screen.getByText("help").closest("div");
+ const buttons = Array.from(helpElement?.querySelectorAll("button") || []);
+ const deleteButton = buttons.find((btn) => {
+ const svg = btn.querySelector("svg");
+ return svg && svg.classList.contains("text-destructive");
+ });
- // Store should handle the deletion gracefully
- const updatedState = toolBuilderStore.state;
- expect(updatedState.selectedCommand.name).toBe("my-cli-tool"); // Falls back to root
- expect(screen.queryByText("help")).not.toBeInTheDocument();
- }
+ if (deleteButton) {
+ fireEvent.click(deleteButton);
+ expect(capturedCtx.selectedCommand.name).toBe("my-cli-tool");
+ expect(screen.queryByText("help")).not.toBeInTheDocument();
}
});
it("handles empty command list gracefully", () => {
- // Create a tool with minimal commands (just root)
const complexTool = createComplexTool();
const minimalTool: Tool = {
...complexTool,
- commands: [
- {
- key: "minimal-tool-id",
- name: "minimal-tool",
- description: "Minimal tool with just root command",
- isDefault: true,
- sortOrder: 0,
- },
- ],
+ commands: [{
+ key: "minimal-tool-id",
+ name: "minimal-tool",
+ description: "Minimal tool with just root command",
+ isDefault: true,
+ sortOrder: 0,
+ }],
};
- act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: minimalTool,
- selectedCommand: minimalTool.commands[0],
- }));
- });
-
- render();
+ renderWithProvider(, { tool: minimalTool, selectedCommand: minimalTool.commands[0] });
- // Should render the root command
expect(screen.getByText("minimal-tool")).toBeInTheDocument();
-
- // Should still have the Add Command button
expect(screen.getByText(/Add Command/)).toBeInTheDocument();
- // Root command should not have expand button since no subcommands
const rootElement = screen.getByText("minimal-tool").closest("div");
const spacerDiv = rootElement?.querySelector("div.w-4");
expect(spacerDiv).toBeInTheDocument();
});
it("preserves expansion state when updating commands", async () => {
- render();
+ renderWithProvider(, complexToolState());
- // Expand config command
const configElement = screen.getByText("config").closest("div");
const expandButton = configElement?.querySelector("button");
if (expandButton) {
fireEvent.click(expandButton);
+ await waitFor(() => { expect(screen.getByText("get")).toBeInTheDocument(); });
- await waitFor(() => {
- expect(screen.getByText("get")).toBeInTheDocument();
- });
-
- // Add a new subcommand to config
const buttons = Array.from(configElement?.querySelectorAll("button") || []);
const actionButtons = buttons.filter(
- (btn) =>
- btn.classList.contains("opacity-0") &&
- btn.classList.contains("group-hover:opacity-100"),
+ (btn) => btn.classList.contains("opacity-0") && btn.classList.contains("group-hover:opacity-100"),
);
- const addButton = actionButtons[1]; // Second action button
+ const addButton = actionButtons[1];
if (addButton) {
fireEvent.click(addButton);
-
- // Config should still be expanded and show the new command
expect(screen.getByText("get")).toBeInTheDocument();
expect(screen.getByText("set")).toBeInTheDocument();
- // New command should be visible
- const newCommands = toolBuilderStore.state.tool.commands.filter(
- (cmd) =>
- !createComplexTool().commands.some((originalCmd) => originalCmd.name === cmd.name),
+ const newCommands = capturedCtx.tool.commands.filter(
+ (cmd) => !createComplexTool().commands.some((orig) => orig.name === cmd.name),
);
expect(newCommands.length).toBe(1);
}
}
});
- it("handles rapid state changes correctly", async () => {
- render();
-
- // Rapidly change selected command multiple times
- const commands = toolBuilderStore.state.tool.commands;
- const configCommand = commands.find((cmd) => cmd.name === "config");
- const dataCommand = commands.find((cmd) => cmd.name === "data");
- const utilsCommand = commands.find((cmd) => cmd.name === "utils");
-
- if (configCommand && dataCommand && utilsCommand) {
- // Rapid state changes
- act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedCommand: configCommand,
- }));
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedCommand: dataCommand,
- }));
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedCommand: utilsCommand,
- }));
- });
-
- // Final state should be utils
- await waitFor(() => {
- expect(toolBuilderStore.state.selectedCommand.name).toBe("utils");
- });
-
- // Component should handle this gracefully
- expect(screen.getByText("utils")).toBeInTheDocument();
- }
- });
-
it("handles invalid command hierarchies gracefully", () => {
- // Create a tool with broken hierarchy (parent doesn't exist)
const complexTool = createComplexTool();
const brokenTool: Tool = {
...complexTool,
commands: [
- {
- key: "root-id",
- name: "root",
- description: "Root command",
- isDefault: true,
- sortOrder: 0,
- },
- {
- key: "orphan-id",
- name: "orphan",
- parentCommandKey: "non-existent-parent",
- description: "Orphaned command",
- isDefault: false,
- sortOrder: 1,
- },
+ { key: "root-id", name: "root", description: "Root command", isDefault: true, sortOrder: 0 },
+ { key: "orphan-id", name: "orphan", parentCommandKey: "non-existent-parent", description: "Orphaned command", isDefault: false, sortOrder: 1 },
],
};
- act(() => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: brokenTool,
- selectedCommand: brokenTool.commands[0],
- }));
- });
-
- // Should render without crashing
- expect(() => render()).not.toThrow();
+ expect(() =>
+ renderWithProvider(, { tool: brokenTool, selectedCommand: brokenTool.commands[0] }),
+ ).not.toThrow();
- // Should show the root command
expect(screen.getByText("root")).toBeInTheDocument();
-
- // The orphaned command might not be shown or shown at root level
- // depending on how buildCommandHierarchy handles it
expect(screen.getByText(/Add Command/)).toBeInTheDocument();
});
});
diff --git a/registry/commandly/__tests__/tool-editor/dialogs/command-dialog.test.tsx b/registry/commandly/__tests__/tool-editor/dialogs/command-dialog.test.tsx
index 0680749..a8cde83 100644
--- a/registry/commandly/__tests__/tool-editor/dialogs/command-dialog.test.tsx
+++ b/registry/commandly/__tests__/tool-editor/dialogs/command-dialog.test.tsx
@@ -2,11 +2,12 @@ import { Command } from "@/registry/commandly/lib/types/commandly";
import { defaultTool } from "@/registry/commandly/lib/utils/commandly";
import { CommandDialog } from "@/registry/commandly/tool-editor/dialogs/command-dialog";
import {
+ ToolBuilderProvider,
ToolBuilderState,
- toolBuilderStore,
- toolBuilderActions,
-} from "@/registry/commandly/tool-editor/tool-editor.store";
+ useToolBuilder,
+} from "@/registry/commandly/tool-editor/tool-editor.context";
import { render, screen, fireEvent } from "@testing-library/react";
+import { ReactNode } from "react";
const createTestCommand = (overrides: Partial = {}): Command => ({
key: "test-command-key",
@@ -17,35 +18,46 @@ const createTestCommand = (overrides: Partial = {}): Command => ({
...overrides,
});
-const createTestState = (command: Command, toolName: string = "test-tool"): ToolBuilderState => ({
- tool: { ...defaultTool(toolName, "Test tool"), name: toolName },
+const createTestState = (command: Command, toolName: string = "test-tool"): Partial => ({
+ tool: { ...defaultTool(toolName, "Test tool"), name: toolName, commands: [command] },
selectedCommand: command,
- selectedParameter: null,
editingCommand: command,
- parameterValues: {},
- dialogs: {
- editTool: false,
- savedCommands: false,
- exclusionGroups: false,
- parameterDetails: false,
- },
});
+// Captures the latest context value so tests can verify state changes
+let capturedCtx: ReturnType;
+function ContextCapture() {
+ capturedCtx = useToolBuilder();
+ return null;
+}
+
+function renderWithProvider(
+ ui: ReactNode,
+ initialState: Partial,
+) {
+ return render(
+
+ {ui}
+
+ ,
+ );
+}
+
describe("CommandDialog - Rendering & Structure", () => {
const mockOnOpenChange = vi.fn();
- const testCommand = createTestCommand();
beforeEach(() => {
vi.clearAllMocks();
- toolBuilderStore.setState(() => createTestState(testCommand));
});
it("renders the dialog when isOpen is true", () => {
- render(
- ,
+ const testCommand = createTestCommand();
+ renderWithProvider(
+ ,
+ createTestState(testCommand),
);
expect(screen.getByText("Edit Command Settings")).toBeInTheDocument();
@@ -57,45 +69,44 @@ describe("CommandDialog - Rendering & Structure", () => {
});
it("does not render dialog content when isOpen is false", () => {
- render(
- ,
+ const testCommand = createTestCommand();
+ renderWithProvider(
+ ,
+ createTestState(testCommand),
);
expect(screen.queryByText("Edit Command Settings")).not.toBeInTheDocument();
});
it("displays the terminal icon in the dialog title", () => {
- render(
- ,
+ const testCommand = createTestCommand();
+ renderWithProvider(
+ ,
+ createTestState(testCommand),
);
const title = screen.getByText("Edit Command Settings");
expect(title).toHaveClass("flex", "items-center", "gap-2");
});
+
it("calls onOpenChange with false when dialog is closed", () => {
- const { rerender } = render(
- ,
+ const testCommand = createTestCommand();
+ const testState = createTestState(testCommand);
+ const { rerender } = renderWithProvider(
+ ,
+ testState,
);
- // Simulate closing the dialog by changing isOpen prop
rerender(
- ,
+
+
+
+ ,
);
- // The onOpenChange should be called by the Dialog component itself when closed
- // We'll test this by verifying the dialog behavior works correctly
expect(screen.queryByText("Edit Command Settings")).not.toBeInTheDocument();
});
});
@@ -109,13 +120,9 @@ describe("CommandDialog - Form Fields", () => {
it("displays current command name in the input", () => {
const command = createTestCommand({ name: "my-command" });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const nameInput = screen.getByLabelText("Command Name") as HTMLInputElement;
@@ -124,13 +131,9 @@ describe("CommandDialog - Form Fields", () => {
it("updates command name when input changes", () => {
const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const nameInput = screen.getByLabelText("Command Name");
@@ -141,13 +144,9 @@ describe("CommandDialog - Form Fields", () => {
it("disables command name input when command name matches tool name", () => {
const command = createTestCommand({ name: "test-tool" });
- toolBuilderStore.setState(() => createTestState(command, "test-tool"));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command, "test-tool"),
);
const nameInput = screen.getByLabelText("Command Name");
@@ -156,13 +155,9 @@ describe("CommandDialog - Form Fields", () => {
it("displays current sort order in the input", () => {
const command = createTestCommand({ sortOrder: 5 });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const sortOrderInput = screen.getByLabelText("Sort Order") as HTMLInputElement;
@@ -171,13 +166,9 @@ describe("CommandDialog - Form Fields", () => {
it("updates sort order when input changes", () => {
const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const sortOrderInput = screen.getByLabelText("Sort Order");
@@ -188,13 +179,9 @@ describe("CommandDialog - Form Fields", () => {
it("defaults sort order to 0 for invalid input", () => {
const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const sortOrderInput = screen.getByLabelText("Sort Order");
@@ -205,13 +192,9 @@ describe("CommandDialog - Form Fields", () => {
it("displays current description in the textarea", () => {
const command = createTestCommand({ description: "My test description" });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const descriptionTextarea = screen.getByLabelText("Description") as HTMLTextAreaElement;
@@ -220,19 +203,13 @@ describe("CommandDialog - Form Fields", () => {
it("updates description when textarea changes", () => {
const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const descriptionTextarea = screen.getByLabelText("Description");
- fireEvent.change(descriptionTextarea, {
- target: { value: "New description" },
- });
+ fireEvent.change(descriptionTextarea, { target: { value: "New description" } });
expect((descriptionTextarea as HTMLTextAreaElement).value).toBe("New description");
});
@@ -247,13 +224,9 @@ describe("CommandDialog - Default Command Switch", () => {
it("reflects current isDefault state", () => {
const command = createTestCommand({ isDefault: true });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const defaultSwitch = screen.getByLabelText("Default Command");
@@ -262,13 +235,9 @@ describe("CommandDialog - Default Command Switch", () => {
it("updates isDefault when switch is toggled", () => {
const command = createTestCommand({ isDefault: false });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const defaultSwitch = screen.getByLabelText("Default Command");
@@ -279,13 +248,9 @@ describe("CommandDialog - Default Command Switch", () => {
it("disables switch when command is already default", () => {
const command = createTestCommand({ isDefault: true });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const defaultSwitch = screen.getByLabelText("Default Command");
@@ -298,25 +263,16 @@ describe("CommandDialog - Save Functionality", () => {
beforeEach(() => {
vi.clearAllMocks();
- vi.spyOn(toolBuilderActions, "updateCommand").mockImplementation(() => {});
});
- afterEach(() => {
- vi.restoreAllMocks();
- });
-
- it("calls updateCommand and closes dialog when Save & Close is clicked", () => {
+ it("updates command in context and closes dialog when Save & Close is clicked", () => {
const command = createTestCommand({
key: "original-command-key",
name: "original-command",
});
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const nameInput = screen.getByLabelText("Command Name");
@@ -325,15 +281,13 @@ describe("CommandDialog - Save Functionality", () => {
const saveButton = screen.getByRole("button", { name: "Save & Close" });
fireEvent.click(saveButton);
- expect(toolBuilderActions.updateCommand).toHaveBeenCalledWith(
- "original-command-key",
- expect.objectContaining({
- name: "updated-command",
- description: "Test command description",
- isDefault: false,
- sortOrder: 0,
- }),
+ const updatedCommand = capturedCtx.tool.commands.find(
+ (c) => c.key === "original-command-key",
);
+ expect(updatedCommand?.name).toBe("updated-command");
+ expect(updatedCommand?.description).toBe("Test command description");
+ expect(updatedCommand?.isDefault).toBe(false);
+ expect(updatedCommand?.sortOrder).toBe(0);
expect(mockOnOpenChange).toHaveBeenCalledWith(false);
});
@@ -342,38 +296,26 @@ describe("CommandDialog - Save Functionality", () => {
key: "original-command-key",
name: "original-command",
});
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
- fireEvent.change(screen.getByLabelText("Command Name"), {
- target: { value: "new-name" },
- });
- fireEvent.change(screen.getByLabelText("Sort Order"), {
- target: { value: "15" },
- });
- fireEvent.change(screen.getByLabelText("Description"), {
- target: { value: "New description" },
- });
+ fireEvent.change(screen.getByLabelText("Command Name"), { target: { value: "new-name" } });
+ fireEvent.change(screen.getByLabelText("Sort Order"), { target: { value: "15" } });
+ fireEvent.change(screen.getByLabelText("Description"), { target: { value: "New description" } });
fireEvent.click(screen.getByLabelText("Default Command"));
const saveButton = screen.getByRole("button", { name: "Save & Close" });
fireEvent.click(saveButton);
- expect(toolBuilderActions.updateCommand).toHaveBeenCalledWith(
- "original-command-key",
- expect.objectContaining({
- name: "new-name",
- description: "New description",
- isDefault: true,
- sortOrder: 15,
- }),
+ const updatedCommand = capturedCtx.tool.commands.find(
+ (c) => c.key === "original-command-key",
);
+ expect(updatedCommand?.name).toBe("new-name");
+ expect(updatedCommand?.description).toBe("New description");
+ expect(updatedCommand?.isDefault).toBe(true);
+ expect(updatedCommand?.sortOrder).toBe(15);
});
it("handles save with empty command name", () => {
@@ -381,13 +323,9 @@ describe("CommandDialog - Save Functionality", () => {
key: "original-name-key",
name: "original-name",
});
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const nameInput = screen.getByLabelText("Command Name");
@@ -396,12 +334,10 @@ describe("CommandDialog - Save Functionality", () => {
const saveButton = screen.getByRole("button", { name: "Save & Close" });
fireEvent.click(saveButton);
- expect(toolBuilderActions.updateCommand).toHaveBeenCalledWith(
- "original-name-key",
- expect.objectContaining({
- name: "",
- }),
+ const updatedCommand = capturedCtx.tool.commands.find(
+ (c) => c.key === "original-name-key",
);
+ expect(updatedCommand?.name).toBe("");
});
it("preserves subcommands when saving", () => {
@@ -409,13 +345,9 @@ describe("CommandDialog - Save Functionality", () => {
key: "parent-command-key",
name: "parent-command",
});
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const nameInput = screen.getByLabelText("Command Name");
@@ -424,26 +356,20 @@ describe("CommandDialog - Save Functionality", () => {
const saveButton = screen.getByRole("button", { name: "Save & Close" });
fireEvent.click(saveButton);
- expect(toolBuilderActions.updateCommand).toHaveBeenCalledWith(
- "parent-command-key",
- expect.objectContaining({
- name: "updated-parent",
- }),
+ const updatedCommand = capturedCtx.tool.commands.find(
+ (c) => c.key === "parent-command-key",
);
+ expect(updatedCommand?.name).toBe("updated-parent");
});
- it("correctly updates command name using original name as identifier", () => {
+ it("correctly updates command name using original key as identifier", () => {
const originalCommand = createTestCommand({
key: "original-name-key",
name: "original-name",
});
- toolBuilderStore.setState(() => createTestState(originalCommand));
-
- render(
- ,
+ renderWithProvider(
+ ,
+ createTestState(originalCommand),
);
const nameInput = screen.getByLabelText("Command Name");
@@ -452,12 +378,10 @@ describe("CommandDialog - Save Functionality", () => {
const saveButton = screen.getByRole("button", { name: "Save & Close" });
fireEvent.click(saveButton);
- expect(toolBuilderActions.updateCommand).toHaveBeenCalledWith(
- "original-name-key",
- expect.objectContaining({
- name: "completely-new-name",
- }),
+ const updatedCommand = capturedCtx.tool.commands.find(
+ (c) => c.key === "original-name-key",
);
+ expect(updatedCommand?.name).toBe("completely-new-name");
});
});
@@ -466,16 +390,13 @@ describe("CommandDialog - UI Elements and Layout", () => {
beforeEach(() => {
vi.clearAllMocks();
- const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
});
it("renders all labels and inputs correctly", () => {
- render(
- ,
+ const command = createTestCommand();
+ renderWithProvider(
+ ,
+ createTestState(command),
);
expect(screen.getByLabelText("Command Name")).toBeInTheDocument();
@@ -485,11 +406,10 @@ describe("CommandDialog - UI Elements and Layout", () => {
});
it("applies correct classes and layout structure", () => {
- render(
- ,
+ const command = createTestCommand();
+ renderWithProvider(
+ ,
+ createTestState(command),
);
const dialog = screen.getByRole("dialog");
@@ -498,335 +418,4 @@ describe("CommandDialog - UI Elements and Layout", () => {
const title = screen.getByText("Edit Command Settings");
expect(title).toHaveClass("flex", "items-center", "gap-2");
});
-
- it("renders TerminalIcon in the dialog title", () => {
- render(
- ,
- );
-
- const title = screen.getByText("Edit Command Settings");
- const icon = title.querySelector("svg");
- expect(icon).toBeInTheDocument();
- expect(icon).toHaveClass("h-5", "w-5");
- });
-});
-
-describe("CommandDialog - State Management", () => {
- const mockOnOpenChange = vi.fn();
-
- beforeEach(() => {
- vi.clearAllMocks();
- });
-
- it("initializes editCommand state from the store's editingCommand", () => {
- const command = createTestCommand({
- name: "initial-command",
- description: "Initial description",
- sortOrder: 5,
- isDefault: true,
- });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
- );
-
- expect(screen.getByDisplayValue("initial-command")).toBeInTheDocument();
- expect(screen.getByDisplayValue("Initial description")).toBeInTheDocument();
- expect(screen.getByDisplayValue("5")).toBeInTheDocument();
- expect(screen.getByLabelText("Default Command")).toBeChecked();
- });
-
- it("does not mutate the original command in the store until save", () => {
- const originalCommand = createTestCommand({ name: "original-name" });
- toolBuilderStore.setState(() => createTestState(originalCommand));
-
- render(
- ,
- );
-
- // Modify the form without saving
- fireEvent.change(screen.getByLabelText("Command Name"), {
- target: { value: "modified-name" },
- });
-
- // Original command should remain unchanged
- const storeState = toolBuilderStore.state;
- expect(storeState.editingCommand?.name).toBe("original-name");
- });
-
- it("maintains local state independently of store updates", () => {
- const command = createTestCommand({ name: "test-command" });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
- );
-
- // Change local state
- fireEvent.change(screen.getByLabelText("Command Name"), {
- target: { value: "local-change" },
- });
-
- // Update store with different command
- const newCommand = createTestCommand({ name: "store-change" });
- toolBuilderStore.setState(() => createTestState(newCommand));
-
- // Local state should be preserved
- expect(screen.getByDisplayValue("local-change")).toBeInTheDocument();
- });
-});
-
-describe("CommandDialog - Edge Cases", () => {
- const mockOnOpenChange = vi.fn();
-
- beforeEach(() => {
- vi.clearAllMocks();
- });
-
- it("handles command being null gracefully", () => {
- // The component expects editingCommand to be non-null, so we test with minimal command
- const minimalCommand = createTestCommand({ name: "", description: "" });
- toolBuilderStore.setState(() => ({
- ...createTestState(minimalCommand),
- editingCommand: minimalCommand,
- }));
-
- expect(() => {
- render(
- ,
- );
- }).not.toThrow();
-
- // Should render with empty values
- const nameInput = screen.getByLabelText("Command Name") as HTMLInputElement;
- const descriptionTextarea = screen.getByLabelText("Description") as HTMLTextAreaElement;
- expect(nameInput.value).toBe("");
- expect(descriptionTextarea.value).toBe("");
- });
-
- it("handles rapid open/close actions without errors", () => {
- const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
-
- const { rerender } = render(
- ,
- );
-
- // Rapid open/close
- rerender(
- ,
- );
- rerender(
- ,
- );
- rerender(
- ,
- );
-
- expect(screen.getByText("Edit Command Settings")).toBeInTheDocument();
- });
-
- it("handles empty command name input", () => {
- const command = createTestCommand({ name: "test-command" });
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
- );
-
- const nameInput = screen.getByLabelText("Command Name");
- fireEvent.change(nameInput, { target: { value: "" } });
-
- expect((nameInput as HTMLInputElement).value).toBe("");
- });
-
- it("handles very long input values", () => {
- const longText = "a".repeat(1000);
- const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
- );
-
- const nameInput = screen.getByLabelText("Command Name");
- const descriptionTextarea = screen.getByLabelText("Description");
-
- fireEvent.change(nameInput, { target: { value: longText } });
- fireEvent.change(descriptionTextarea, { target: { value: longText } });
-
- expect((nameInput as HTMLInputElement).value).toBe(longText);
- expect((descriptionTextarea as HTMLTextAreaElement).value).toBe(longText);
- });
-
- it("handles negative sort order input", () => {
- const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
- );
-
- const sortOrderInput = screen.getByLabelText("Sort Order");
- fireEvent.change(sortOrderInput, { target: { value: "-5" } });
-
- expect((sortOrderInput as HTMLInputElement).value).toBe("-5");
- });
-
- it("handles very large sort order numbers", () => {
- const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
-
- render(
- ,
- );
-
- const sortOrderInput = screen.getByLabelText("Sort Order");
- fireEvent.change(sortOrderInput, { target: { value: "999999" } });
-
- expect((sortOrderInput as HTMLInputElement).value).toBe("999999");
- });
-});
-
-describe("CommandDialog - Accessibility", () => {
- const mockOnOpenChange = vi.fn();
-
- beforeEach(() => {
- vi.clearAllMocks();
- const command = createTestCommand();
- toolBuilderStore.setState(() => createTestState(command));
- });
-
- it("has correct htmlFor and id attributes for form elements", () => {
- render(
- ,
- );
-
- const nameLabel = screen.getByText("Command Name");
- const nameInput = screen.getByLabelText("Command Name");
- expect(nameLabel).toHaveAttribute("for", "cmd-name");
- expect(nameInput).toHaveAttribute("id", "cmd-name");
-
- const sortOrderLabel = screen.getByText("Sort Order");
- const sortOrderInput = screen.getByLabelText("Sort Order");
- expect(sortOrderLabel).toHaveAttribute("for", "sort-order");
- expect(sortOrderInput).toHaveAttribute("id", "sort-order");
-
- const defaultLabel = screen.getByText("Default Command");
- const defaultSwitch = screen.getByLabelText("Default Command");
- expect(defaultLabel).toHaveAttribute("for", "default-cmd");
- expect(defaultSwitch).toHaveAttribute("id", "default-cmd");
-
- const descriptionLabel = screen.getByText("Description");
- const descriptionTextarea = screen.getByLabelText("Description");
- expect(descriptionLabel).toHaveAttribute("for", "cmd-desc");
- expect(descriptionTextarea).toHaveAttribute("id", "cmd-desc");
- });
-
- it("is keyboard navigable", () => {
- render(
- ,
- );
-
- const nameInput = screen.getByLabelText("Command Name");
- const sortOrderInput = screen.getByLabelText("Sort Order");
- const defaultSwitch = screen.getByLabelText("Default Command");
- const descriptionTextarea = screen.getByLabelText("Description");
- const saveButton = screen.getByRole("button", { name: "Save & Close" });
-
- // Test that elements can be focused
- nameInput.focus();
- expect(document.activeElement).toBe(nameInput);
-
- sortOrderInput.focus();
- expect(document.activeElement).toBe(sortOrderInput);
-
- defaultSwitch.focus();
- expect(document.activeElement).toBe(defaultSwitch);
-
- descriptionTextarea.focus();
- expect(document.activeElement).toBe(descriptionTextarea);
-
- saveButton.focus();
- expect(document.activeElement).toBe(saveButton);
- });
-
- it("has proper dialog role and aria attributes", () => {
- render(
- ,
- );
-
- const dialog = screen.getByRole("dialog");
- expect(dialog).toBeInTheDocument();
- expect(dialog).toHaveAttribute("aria-labelledby");
- expect(dialog).toHaveAttribute("aria-describedby");
- });
-
- it("supports clicking save button to save", () => {
- vi.spyOn(toolBuilderActions, "updateCommand").mockImplementation(() => {});
-
- render(
- ,
- );
-
- const saveButton = screen.getByRole("button", { name: "Save & Close" });
- fireEvent.click(saveButton);
-
- expect(toolBuilderActions.updateCommand).toHaveBeenCalled();
- expect(mockOnOpenChange).toHaveBeenCalledWith(false);
-
- vi.restoreAllMocks();
- });
});
diff --git a/registry/commandly/__tests__/tool-editor/dialogs/parameter-details-dialog.test.tsx b/registry/commandly/__tests__/tool-editor/dialogs/parameter-details-dialog.test.tsx
index 4247d9b..9f9dd6d 100644
--- a/registry/commandly/__tests__/tool-editor/dialogs/parameter-details-dialog.test.tsx
+++ b/registry/commandly/__tests__/tool-editor/dialogs/parameter-details-dialog.test.tsx
@@ -2,11 +2,12 @@ import { Parameter, Command } from "@/registry/commandly/lib/types/commandly";
import { defaultTool } from "@/registry/commandly/lib/utils/commandly";
import { ParameterDetailsDialog } from "@/registry/commandly/tool-editor/dialogs/parameter-details-dialog";
import {
+ ToolBuilderProvider,
ToolBuilderState,
- toolBuilderStore,
- toolBuilderActions,
-} from "@/registry/commandly/tool-editor/tool-editor.store";
+ useToolBuilder,
+} from "@/registry/commandly/tool-editor/tool-editor.context";
import { render, screen, fireEvent, act } from "@testing-library/react";
+import { ReactNode } from "react";
const createTestParameter = (overrides: Partial = {}): Parameter => ({
key: "test-param-key",
@@ -36,20 +37,34 @@ const createTestState = (
parameter: Parameter | null,
toolName: string = "test-tool",
command?: Command,
-): ToolBuilderState => ({
+): Partial => ({
tool: { ...defaultTool(toolName, "Test tool"), name: toolName },
selectedCommand: command || createTestCommand(),
selectedParameter: parameter,
- editingCommand: null,
- parameterValues: {},
- dialogs: {
- editTool: false,
- savedCommands: false,
- exclusionGroups: false,
- parameterDetails: false,
- },
});
+// Captures the latest context value after each render
+let capturedCtx: ReturnType;
+function ContextCapture() {
+ capturedCtx = useToolBuilder();
+ return null;
+}
+
+function renderWithProvider(
+ ui: ReactNode,
+ initialState: Partial,
+) {
+ return render(
+
+ {ui}
+
+ ,
+ );
+}
+
describe("ParameterDetailsDialog - Dialog Lifecycle", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -58,24 +73,19 @@ describe("ParameterDetailsDialog - Dialog Lifecycle", () => {
it("manages dialog open/close states and store synchronization", () => {
const testParameter = createTestParameter();
- // Opens when parameter is selected
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(testParameter));
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(screen.getByText("test-param")).toBeInTheDocument();
- expect(toolBuilderStore.state.selectedParameter).toEqual(testParameter);
+ expect(capturedCtx.selectedParameter).toEqual(testParameter);
- // Closes when parameter is deselected
+ // Closes when parameter is deselected via context action
act(() => {
- toolBuilderStore.setState(() => createTestState(null));
+ capturedCtx.setSelectedParameter(null);
});
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
- expect(toolBuilderStore.state.selectedParameter).toBeNull();
+ expect(capturedCtx.selectedParameter).toBeNull();
});
});
@@ -92,11 +102,7 @@ describe("ParameterDetailsDialog - Form Fields", () => {
dataType: "String",
});
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(testParameter));
// Check initial values
expect(screen.getByDisplayValue("my-parameter")).toBeInTheDocument();
@@ -110,9 +116,7 @@ describe("ParameterDetailsDialog - Form Fields", () => {
act(() => {
fireEvent.change(nameInput, { target: { value: "updated-param" } });
- fireEvent.change(descriptionTextarea, {
- target: { value: "Updated description" },
- });
+ fireEvent.change(descriptionTextarea, { target: { value: "Updated description" } });
});
expect(screen.getByDisplayValue("updated-param")).toBeInTheDocument();
@@ -125,32 +129,20 @@ describe("ParameterDetailsDialog - Form Fields", () => {
dataType: "String",
});
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(testParameter));
const selectElements = screen.getAllByRole("combobox");
const parameterTypeSelect = selectElements[0];
const dataTypeSelect = selectElements[1];
// Change parameter type
- act(() => {
- fireEvent.click(parameterTypeSelect);
- });
- act(() => {
- fireEvent.click(screen.getByRole("option", { name: "Flag" }));
- });
+ act(() => { fireEvent.click(parameterTypeSelect); });
+ act(() => { fireEvent.click(screen.getByRole("option", { name: "Flag" })); });
expect(screen.getByText("Flag")).toBeInTheDocument();
// Change data type
- act(() => {
- fireEvent.click(dataTypeSelect);
- });
- act(() => {
- fireEvent.click(screen.getByRole("option", { name: "Boolean" }));
- });
+ act(() => { fireEvent.click(dataTypeSelect); });
+ act(() => { fireEvent.click(screen.getByRole("option", { name: "Boolean" })); });
expect(screen.getByText("Boolean")).toBeInTheDocument();
});
@@ -161,11 +153,7 @@ describe("ParameterDetailsDialog - Form Fields", () => {
isRepeatable: false,
});
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(testParameter));
const switches = screen.getAllByRole("switch");
const requiredSwitch = switches.find((s) =>
@@ -195,12 +183,7 @@ describe("ParameterDetailsDialog - Form Fields", () => {
it("validates empty parameter name", () => {
const testParameter = createTestParameter();
-
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(testParameter));
const nameInput = screen.getByDisplayValue("test-param");
const saveButton = screen.getByRole("button", { name: "Save Changes" });
@@ -220,12 +203,7 @@ describe("ParameterDetailsDialog - Parameter Type Specific Fields", () => {
it("conditionally renders fields based on parameter type", () => {
const flagParameter = createTestParameter({ parameterType: "Flag" });
-
- act(() => {
- toolBuilderStore.setState(() => createTestState(flagParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(flagParameter));
// Flag type shows flag fields but not key-value separator
expect(screen.getByText("Short Flag (include prefix)")).toBeInTheDocument();
@@ -236,12 +214,8 @@ describe("ParameterDetailsDialog - Parameter Type Specific Fields", () => {
const selectElements = screen.getAllByRole("combobox");
const parameterTypeSelect = selectElements[0];
- act(() => {
- fireEvent.click(parameterTypeSelect);
- });
- act(() => {
- fireEvent.click(screen.getByRole("option", { name: "Option" }));
- });
+ act(() => { fireEvent.click(parameterTypeSelect); });
+ act(() => { fireEvent.click(screen.getByRole("option", { name: "Option" })); });
// Option type shows all fields including key-value separator
expect(screen.getByText("Short Flag (include prefix)")).toBeInTheDocument();
@@ -249,12 +223,8 @@ describe("ParameterDetailsDialog - Parameter Type Specific Fields", () => {
expect(screen.getByText("Key-Value Separator")).toBeInTheDocument();
// Switch to Argument type
- act(() => {
- fireEvent.click(parameterTypeSelect);
- });
- act(() => {
- fireEvent.click(screen.getByRole("option", { name: "Argument" }));
- });
+ act(() => { fireEvent.click(parameterTypeSelect); });
+ act(() => { fireEvent.click(screen.getByRole("option", { name: "Argument" })); });
// Argument type hides flag fields
expect(screen.queryByText("Short Flag (include prefix)")).not.toBeInTheDocument();
@@ -268,11 +238,7 @@ describe("ParameterDetailsDialog - Parameter Type Specific Fields", () => {
keyValueSeparator: "=",
});
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(testParameter));
const separatorInput = screen.getByDisplayValue("=");
@@ -291,25 +257,20 @@ describe("ParameterDetailsDialog - Dependencies Section", () => {
it("disables Add button when no available parameters", () => {
const testParameter = createTestParameter();
- const testState = createTestState(testParameter);
- // No other parameters available
- testState.tool.parameters = [testParameter];
-
- act(() => {
- toolBuilderStore.setState(() => testState);
- });
+ const initState: Partial = {
+ ...createTestState(testParameter),
+ };
+ // Only this parameter — no others available
+ initState.tool = { ...defaultTool("test-tool", "Test tool"), parameters: [testParameter] };
- render();
+ renderWithProvider(, initState);
const addButtons = screen.getAllByRole("button", { name: "Add" });
- const dependenciesAddButton = addButtons[0]; // First Add button is for dependencies
+ const dependenciesAddButton = addButtons[0];
expect(dependenciesAddButton).toBeDisabled();
-
- // Assert store state - should only have the single parameter
- const state = toolBuilderStore.state;
- expect(state.tool.parameters).toHaveLength(1);
- expect(state.tool.parameters[0]).toEqual(testParameter);
+ expect(capturedCtx.tool.parameters).toHaveLength(1);
+ expect(capturedCtx.tool.parameters[0]).toEqual(testParameter);
});
});
@@ -320,12 +281,7 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
it("enables save button when changes are made but keeps store unchanged until saved", () => {
const testParameter = createTestParameter();
-
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(testParameter));
const saveButton = screen.getByRole("button", { name: "Save Changes" });
expect(saveButton).toBeDisabled();
@@ -337,45 +293,38 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
});
expect(saveButton).not.toBeDisabled();
-
- const state = toolBuilderStore.state;
- expect(state.selectedParameter?.name).toBe("test-param");
+ // Context selectedParameter should still have the original name (not yet saved)
+ expect(capturedCtx.selectedParameter?.name).toBe("test-param");
});
- it("resets dialog state and updates store when new parameter is selected", () => {
+ it("resets dialog state when new parameter is selected via context", () => {
const firstParameter = createTestParameter({ name: "first-param" });
const secondParameter = createTestParameter({
key: "different-key",
name: "second-param",
+ commandKey: "test-command-key",
});
- act(() => {
- toolBuilderStore.setState(() => createTestState(firstParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(firstParameter));
const nameInput = screen.getByDisplayValue("first-param");
act(() => {
- fireEvent.change(nameInput, {
- target: { value: "modified-first-param" },
- });
+ fireEvent.change(nameInput, { target: { value: "modified-first-param" } });
});
const saveButton = screen.getByRole("button", { name: "Save Changes" });
expect(saveButton).not.toBeDisabled();
act(() => {
- toolBuilderStore.setState(() => createTestState(secondParameter));
+ capturedCtx.setSelectedParameter(secondParameter);
});
expect(screen.getByDisplayValue("second-param")).toBeInTheDocument();
expect(saveButton).toBeDisabled();
- const state = toolBuilderStore.state;
- expect(state.selectedParameter?.name).toBe("second-param");
- expect(state.selectedParameter?.key).toBe("different-key");
+ expect(capturedCtx.selectedParameter?.name).toBe("second-param");
+ expect(capturedCtx.selectedParameter?.key).toBe("different-key");
});
it("cancels changes, closes dialog, and preserves original store state", () => {
@@ -384,24 +333,19 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
description: "Original description",
isRequired: false,
});
+ const initState: Partial = {
+ ...createTestState(testParameter),
+ };
+ initState.tool = { ...defaultTool("test-tool", "Test tool"), parameters: [testParameter] };
- const testState = createTestState(testParameter);
- testState.tool.parameters = [testParameter];
-
- act(() => {
- toolBuilderStore.setState(() => testState);
- });
-
- render();
+ renderWithProvider(, initState);
const nameInput = screen.getByDisplayValue("original-param");
const descriptionTextarea = screen.getByDisplayValue("Original description");
act(() => {
fireEvent.change(nameInput, { target: { value: "modified-param" } });
- fireEvent.change(descriptionTextarea, {
- target: { value: "Modified description" },
- });
+ fireEvent.change(descriptionTextarea, { target: { value: "Modified description" } });
});
expect(screen.getByDisplayValue("modified-param")).toBeInTheDocument();
@@ -414,18 +358,17 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
});
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+ expect(capturedCtx.selectedParameter).toBeNull();
- const state = toolBuilderStore.state;
- expect(state.selectedParameter).toBeNull();
-
- const originalParameter = state.tool.parameters.find((p) => p.key === testParameter.key);
- expect(originalParameter).toBeDefined();
+ const originalParameter = capturedCtx.tool.parameters.find(
+ (p) => p.key === testParameter.key,
+ );
expect(originalParameter?.name).toBe("original-param");
expect(originalParameter?.description).toBe("Original description");
expect(originalParameter?.isRequired).toBe(false);
});
- it("saves changes, closes dialog, and updates store with new values", () => {
+ it("saves changes, closes dialog, and updates context with new values", () => {
const testParameter = createTestParameter({
name: "original-param",
description: "Original description",
@@ -434,15 +377,12 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
parameterType: "Option",
dataType: "String",
});
+ const initState: Partial = {
+ ...createTestState(testParameter),
+ };
+ initState.tool = { ...defaultTool("test-tool", "Test tool"), parameters: [testParameter] };
- const testState = createTestState(testParameter);
- testState.tool.parameters = [testParameter];
-
- act(() => {
- toolBuilderStore.setState(() => testState);
- });
-
- render();
+ renderWithProvider(, initState);
const nameInput = screen.getByDisplayValue("original-param");
const descriptionTextarea = screen.getByDisplayValue("Original description");
@@ -451,9 +391,7 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
act(() => {
fireEvent.change(nameInput, { target: { value: "updated-param" } });
- fireEvent.change(descriptionTextarea, {
- target: { value: "Updated description" },
- });
+ fireEvent.change(descriptionTextarea, { target: { value: "Updated description" } });
fireEvent.click(requiredSwitch);
fireEvent.click(globalSwitch);
});
@@ -463,11 +401,9 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
expect(requiredSwitch).toBeChecked();
expect(globalSwitch).toBeChecked();
- let state = toolBuilderStore.state;
- expect(state.selectedParameter?.name).toBe("original-param");
- expect(state.selectedParameter?.description).toBe("Original description");
- expect(state.selectedParameter?.isRequired).toBe(false);
- expect(state.selectedParameter?.isGlobal).toBe(false);
+ // Context should still have original values (not saved yet)
+ expect(capturedCtx.selectedParameter?.name).toBe("original-param");
+ expect(capturedCtx.selectedParameter?.isRequired).toBe(false);
const saveButton = screen.getByRole("button", { name: "Save Changes" });
expect(saveButton).not.toBeDisabled();
@@ -477,11 +413,9 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
});
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+ expect(capturedCtx.selectedParameter).toBeNull();
- state = toolBuilderStore.state;
- expect(state.selectedParameter).toBeNull();
-
- const updatedParameter = state.tool.parameters.find((p) => p.name === "updated-param");
+ const updatedParameter = capturedCtx.tool.parameters.find((p) => p.name === "updated-param");
expect(updatedParameter).toBeDefined();
expect(updatedParameter?.name).toBe("updated-param");
expect(updatedParameter?.description).toBe("Updated description");
@@ -489,19 +423,14 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
expect(updatedParameter?.isGlobal).toBe(true);
});
- it("verifies store actions are called correctly during save and cancel operations", () => {
- const setSelectedParameterSpy = vi.spyOn(toolBuilderActions, "setSelectedParameter");
- const upsertParameterSpy = vi.spyOn(toolBuilderActions, "upsertParameter");
-
+ it("verifies context state is updated correctly after save", () => {
const testParameter = createTestParameter();
- const testState = createTestState(testParameter);
- testState.tool.parameters = [testParameter];
-
- act(() => {
- toolBuilderStore.setState(() => testState);
- });
+ const initState: Partial = {
+ ...createTestState(testParameter),
+ };
+ initState.tool = { ...defaultTool("test-tool", "Test tool"), parameters: [testParameter] };
- render();
+ renderWithProvider(, initState);
const nameInput = screen.getByDisplayValue("test-param");
act(() => {
@@ -513,31 +442,24 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
fireEvent.click(saveButton);
});
- expect(upsertParameterSpy).toHaveBeenCalledWith(
- expect.objectContaining({
- description: "Test parameter description",
- name: "modified-param",
- }),
- );
- expect(setSelectedParameterSpy).toHaveBeenCalledWith(null);
+ // After save: dialog closed, parameter updated in context
+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+ expect(capturedCtx.selectedParameter).toBeNull();
- const finalState = toolBuilderStore.state;
- expect(finalState.selectedParameter).toBeNull();
- const updatedParameter = finalState.tool.parameters.find((p) => p.name === "modified-param");
+ const updatedParameter = capturedCtx.tool.parameters.find(
+ (p) => p.name === "modified-param",
+ );
expect(updatedParameter?.name).toBe("modified-param");
-
- setSelectedParameterSpy.mockRestore();
- upsertParameterSpy.mockRestore();
+ expect(updatedParameter?.description).toBe("Test parameter description");
});
it("resets dialog state and preserves store when dialog is closed and reopened", () => {
const testParameter = createTestParameter();
+ const initState: Partial = {
+ ...createTestState(testParameter),
+ };
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- const { unmount } = render();
+ const { unmount } = renderWithProvider(, initState);
const nameInput = screen.getByDisplayValue("test-param");
@@ -549,18 +471,14 @@ describe("ParameterDetailsDialog - State Management & Dialog Actions", () => {
expect(saveButton).not.toBeDisabled();
const cancelButton = screen.getByRole("button", { name: "Cancel" });
-
act(() => {
fireEvent.click(cancelButton);
});
unmount();
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ // Re-render fresh with the same parameter
+ renderWithProvider(, createTestState(testParameter));
expect(screen.getByDisplayValue("test-param")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Save Changes" })).toBeDisabled();
@@ -588,11 +506,7 @@ describe("ParameterDetailsDialog - UI/UX", () => {
metadata: { tags: ["tag1", "tag2"] },
});
- act(() => {
- toolBuilderStore.setState(() => createTestState(testParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(testParameter));
// Check all fields are pre-filled
expect(screen.getByDisplayValue("test-parameter")).toBeInTheDocument();
@@ -618,19 +532,10 @@ describe("ParameterDetailsDialog - UI/UX", () => {
expect(repeatableSwitch).toBeChecked();
expect(globalSwitch).toBeChecked();
- // Assert store state matches pre-filled values
- const state = toolBuilderStore.state;
- expect(state.selectedParameter?.name).toBe("test-parameter");
- expect(state.selectedParameter?.parameterType).toBe("Option");
- expect(state.selectedParameter?.dataType).toBe("String");
- expect(state.selectedParameter?.longFlag).toBe("--test-flag");
- expect(state.selectedParameter?.shortFlag).toBe("-t");
- expect(state.selectedParameter?.description).toBe("Test description");
- expect(state.selectedParameter?.defaultValue).toBe("default-value");
- expect(state.selectedParameter?.isRequired).toBe(true);
- expect(state.selectedParameter?.isRepeatable).toBe(true);
- expect(state.selectedParameter?.isGlobal).toBe(true);
- expect(state.selectedParameter?.keyValueSeparator).toBe("=");
+ // Confirm context matches
+ expect(capturedCtx.selectedParameter?.name).toBe("test-parameter");
+ expect(capturedCtx.selectedParameter?.isRequired).toBe(true);
+ expect(capturedCtx.selectedParameter?.isGlobal).toBe(true);
});
it("displays correct parameter icon and global badge based on type and properties", () => {
@@ -639,69 +544,53 @@ describe("ParameterDetailsDialog - UI/UX", () => {
isGlobal: true,
});
- act(() => {
- toolBuilderStore.setState(() => createTestState(globalParameter));
- });
-
- render();
+ renderWithProvider(, createTestState(globalParameter));
const dialogTitle = screen.getByText("test-param").closest("h2");
expect(dialogTitle?.querySelector("svg")).toBeInTheDocument();
-
expect(screen.getByText("global")).toBeInTheDocument();
+ // Switch to non-global parameter via context action
const nonGlobalParameter = createTestParameter({ isGlobal: false });
-
act(() => {
- toolBuilderStore.setState(() => createTestState(nonGlobalParameter));
+ capturedCtx.setSelectedParameter(nonGlobalParameter);
});
expect(screen.queryByText("global")).not.toBeInTheDocument();
-
- const state = toolBuilderStore.state;
- expect(state.selectedParameter?.isGlobal).toBe(false);
+ expect(capturedCtx.selectedParameter?.isGlobal).toBe(false);
});
- it("updates store with parameter type changes and related field updates", () => {
+ it("updates context with parameter type changes after save", () => {
const testParameter = createTestParameter({
parameterType: "Option",
keyValueSeparator: "=",
longFlag: "--test",
shortFlag: "-t",
});
+ const initState: Partial = {
+ ...createTestState(testParameter),
+ };
+ initState.tool = { ...defaultTool("test-tool", "Test tool"), parameters: [testParameter] };
- const testState = createTestState(testParameter);
- testState.tool.parameters = [testParameter];
-
- act(() => {
- toolBuilderStore.setState(() => testState);
- });
-
- render();
+ renderWithProvider(, initState);
const selectElements = screen.getAllByRole("combobox");
const parameterTypeSelect = selectElements[0];
- act(() => {
- fireEvent.click(parameterTypeSelect);
- });
-
+ act(() => { fireEvent.click(parameterTypeSelect); });
const flagOption = screen.getByRole("option", { name: "Flag" });
-
- act(() => {
- fireEvent.click(flagOption);
- });
+ act(() => { fireEvent.click(flagOption); });
expect(screen.queryByText("Key-Value Separator")).not.toBeInTheDocument();
const saveButton = screen.getByRole("button", { name: "Save Changes" });
-
act(() => {
fireEvent.click(saveButton);
});
- const state = toolBuilderStore.state;
- const updatedParameter = state.tool.parameters.find((p) => p.key === testParameter.key);
+ const updatedParameter = capturedCtx.tool.parameters.find(
+ (p) => p.key === testParameter.key,
+ );
expect(updatedParameter).toBeDefined();
expect(updatedParameter?.parameterType).toBe("Flag");
expect(updatedParameter?.longFlag).toBe("--test");
diff --git a/registry/commandly/__tests__/tool-editor/help-menu.test.tsx b/registry/commandly/__tests__/tool-editor/help-menu.test.tsx
index 1303179..cf877e6 100644
--- a/registry/commandly/__tests__/tool-editor/help-menu.test.tsx
+++ b/registry/commandly/__tests__/tool-editor/help-menu.test.tsx
@@ -1,19 +1,15 @@
import { HelpMenu } from "../../tool-editor/help-menu";
+import { ToolBuilderProvider } from "../../tool-editor/tool-editor.context";
+import { defaultTool } from "@/registry/commandly/lib/utils/commandly";
import { render, screen } from "@testing-library/react";
-import { vi } from "vitest";
-
-vi.mock("../tool-editor.store", () => ({
- toolBuilderStore: {
- getState: () => ({
- tool: { name: "tool", displayName: "Tool", commands: [], parameters: [] },
- }),
- subscribe: vi.fn(),
- },
-}));
describe("HelpMenu", () => {
it("renders tool name and description", () => {
- render();
+ render(
+
+
+ ,
+ );
expect(screen.getByText(/Tool/)).toBeInTheDocument();
});
});
diff --git a/registry/commandly/__tests__/tool-editor/parameter-list.test.tsx b/registry/commandly/__tests__/tool-editor/parameter-list.test.tsx
index e3a6825..fb44a46 100644
--- a/registry/commandly/__tests__/tool-editor/parameter-list.test.tsx
+++ b/registry/commandly/__tests__/tool-editor/parameter-list.test.tsx
@@ -1,8 +1,13 @@
import { ParameterList } from "../../tool-editor/parameter-list";
-import { ToolBuilderState, toolBuilderStore } from "../../tool-editor/tool-editor.store";
+import {
+ ToolBuilderProvider,
+ ToolBuilderState,
+ useToolBuilder,
+} from "../../tool-editor/tool-editor.context";
import { Parameter, ExclusionGroup } from "@/registry/commandly/lib/types/commandly";
import { defaultTool } from "@/registry/commandly/lib/utils/commandly";
import { render, screen, fireEvent } from "@testing-library/react";
+import { ReactNode } from "react";
const createTestParameter = (overrides: Partial = {}): Parameter => ({
key: "test-param-key",
@@ -28,18 +33,16 @@ const createTestExclusionGroup = (parameterKeys: string[] = []): ExclusionGroup
commandKey: "test-command-key",
});
-const testState: ToolBuilderState = {
+const baseTestState = (): Partial => ({
tool: {
...defaultTool("test-tool", "Test tool"),
- commands: [
- {
- key: "test-command-key",
- name: "test-command",
- description: "Test command",
- isDefault: false,
- sortOrder: 0,
- },
- ],
+ commands: [{
+ key: "test-command-key",
+ name: "test-command",
+ description: "Test command",
+ isDefault: false,
+ sortOrder: 0,
+ }],
},
selectedCommand: {
key: "test-command-key",
@@ -49,91 +52,65 @@ const testState: ToolBuilderState = {
sortOrder: 0,
},
selectedParameter: null,
- editingCommand: null,
- parameterValues: {},
- dialogs: {
- editTool: false,
- savedCommands: false,
- exclusionGroups: false,
- parameterDetails: false,
- },
-};
+});
-describe("ParameterList - Rendering & Structure", () => {
- beforeEach(() => {
- toolBuilderStore.setState((prev) => {
- return { ...prev, ...testState };
- });
- });
+let capturedCtx: ReturnType;
+function ContextCapture() {
+ capturedCtx = useToolBuilder();
+ return null;
+}
+
+function renderWithProvider(ui: ReactNode, initialState: Partial) {
+ return render(
+
+ {ui}
+
+ ,
+ );
+}
+describe("ParameterList - Rendering & Structure", () => {
it("renders the title and parameter count correctly", () => {
const parameters = [
createTestParameter(),
- createTestParameter({
- key: "param2-key",
- name: "param2",
- }),
+ createTestParameter({ key: "param2-key", name: "param2" }),
];
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters };
+ renderWithProvider(, state);
expect(screen.getByText("Test Parameters (2)")).toBeInTheDocument();
});
it("renders the globe icon when isGlobal is true", () => {
const globalParam = createTestParameter({ isGlobal: true });
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [globalParam] },
- }));
-
- render(
- ,
- );
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [globalParam] };
+ renderWithProvider(, state);
expect(screen.getByText("Global Parameters (1)")).toBeInTheDocument();
-
const heading = screen.getByRole("heading", { level: 3 });
expect(heading.querySelector("svg")).toBeInTheDocument();
});
it("renders the add button and triggers the correct action on click", () => {
- render();
-
+ renderWithProvider(, baseTestState());
const addButton = screen.getByRole("button");
expect(addButton).toBeInTheDocument();
expect(addButton.querySelector("svg")).toBeInTheDocument();
-
fireEvent.click(addButton);
});
it("renders the correct number of parameter cards based on the parameters array", () => {
const parameters = [
- createTestParameter({
- key: "param1-key",
- name: "param1",
- }),
- createTestParameter({
- key: "param2-key",
- name: "param2",
- }),
- createTestParameter({
- key: "param3-key",
- name: "param3",
- }),
+ createTestParameter({ key: "param1-key", name: "param1" }),
+ createTestParameter({ key: "param2-key", name: "param2" }),
+ createTestParameter({ key: "param3-key", name: "param3" }),
];
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters },
- }));
-
- render();
-
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters };
+ renderWithProvider(, state);
expect(screen.getByText("param1")).toBeInTheDocument();
expect(screen.getByText("param2")).toBeInTheDocument();
expect(screen.getByText("param3")).toBeInTheDocument();
@@ -142,73 +119,35 @@ describe("ParameterList - Rendering & Structure", () => {
describe("Parameter Card Display", () => {
it("displays the correct icon for each parameterType", () => {
const parameters = [
- createTestParameter({
- key: "flag-param-key",
- name: "flag-param",
- parameterType: "Flag",
- }),
- createTestParameter({
- key: "option-param-key",
- name: "option-param",
- parameterType: "Option",
- }),
- createTestParameter({
- key: "argument-param-key",
- name: "argument-param",
- parameterType: "Argument",
- }),
+ createTestParameter({ key: "flag-param-key", name: "flag-param", parameterType: "Flag" }),
+ createTestParameter({ key: "option-param-key", name: "option-param", parameterType: "Option" }),
+ createTestParameter({ key: "argument-param-key", name: "argument-param", parameterType: "Argument" }),
];
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters };
+ renderWithProvider(, state);
const flagCard = screen.getByText("flag-param").closest("div");
const optionCard = screen.getByText("option-param").closest("div");
const argumentCard = screen.getByText("argument-param").closest("div");
-
expect(flagCard?.querySelector("svg")).toBeInTheDocument();
expect(optionCard?.querySelector("svg")).toBeInTheDocument();
expect(argumentCard?.querySelector("svg")).toBeInTheDocument();
});
it("shows parameter name and flags if present", () => {
- const paramWithBothFlags = createTestParameter({
- name: "test-param",
- longFlag: "--verbose",
- shortFlag: "-v",
- });
- const paramWithLongFlagOnly = createTestParameter({
- key: "long-only-key",
- name: "long-only",
- longFlag: "--long-only",
- shortFlag: "",
- });
- const paramWithNoFlags = createTestParameter({
- key: "no-flags-key",
- name: "no-flags",
- longFlag: "",
- shortFlag: "",
- });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: {
- ...prev.tool,
- parameters: [paramWithBothFlags, paramWithLongFlagOnly, paramWithNoFlags],
- },
- }));
+ const paramWithBothFlags = createTestParameter({ longFlag: "--verbose", shortFlag: "-v" });
+ const paramWithLongFlagOnly = createTestParameter({ key: "long-only-key", name: "long-only", longFlag: "--long-only", shortFlag: "" });
+ const paramWithNoFlags = createTestParameter({ key: "no-flags-key", name: "no-flags", longFlag: "", shortFlag: "" });
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [paramWithBothFlags, paramWithLongFlagOnly, paramWithNoFlags] };
+ renderWithProvider(, state);
expect(screen.getByText("test-param")).toBeInTheDocument();
expect(screen.getByText("(--verbose, -v)")).toBeInTheDocument();
-
expect(screen.getByText("long-only")).toBeInTheDocument();
expect(screen.getByText("(--long-only)")).toBeInTheDocument();
-
expect(screen.getByText("no-flags")).toBeInTheDocument();
const noFlagsCard = screen.getByText("no-flags").closest("div");
expect(noFlagsCard?.textContent).not.toContain("(--");
@@ -216,20 +155,15 @@ describe("ParameterList - Rendering & Structure", () => {
it("shows the remove button and triggers the correct action on click", () => {
const parameter = createTestParameter();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [parameter] },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [parameter] };
+ renderWithProvider(, state);
const removeButtons = screen.getAllByRole("button");
const removeButton = removeButtons.find(
(btn) => btn.querySelector("svg") && btn.className.includes("h-6 w-6"),
);
-
expect(removeButton).toBeInTheDocument();
-
fireEvent.click(removeButton!);
});
});
@@ -237,51 +171,26 @@ describe("ParameterList - Rendering & Structure", () => {
describe("Badges & Validation", () => {
it("shows the required badge if isRequired is true", () => {
const requiredParam = createTestParameter({ isRequired: true });
- const optionalParam = createTestParameter({
- key: "optional-param-key",
- name: "optional-param",
- isRequired: false,
- });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [requiredParam, optionalParam] },
- }));
-
- render();
+ const optionalParam = createTestParameter({ key: "optional-param-key", name: "optional-param", isRequired: false });
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [requiredParam, optionalParam] };
+ renderWithProvider(, state);
const requiredCard = screen.getByText("test-param").closest("div.p-3");
const optionalCard = screen.getByText("optional-param").closest("div.p-3");
-
expect(requiredCard).toHaveTextContent("required");
expect(optionalCard).not.toHaveTextContent("required");
});
it("shows the correct badge for parameterType", () => {
const parameters = [
- createTestParameter({
- key: "flag-param-key",
- name: "flag-param",
- parameterType: "Flag",
- }),
- createTestParameter({
- key: "option-param-key",
- name: "option-param",
- parameterType: "Option",
- }),
- createTestParameter({
- key: "argument-param-key",
- name: "argument-param",
- parameterType: "Argument",
- }),
+ createTestParameter({ key: "flag-param-key", name: "flag-param", parameterType: "Flag" }),
+ createTestParameter({ key: "option-param-key", name: "option-param", parameterType: "Option" }),
+ createTestParameter({ key: "argument-param-key", name: "argument-param", parameterType: "Argument" }),
];
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters };
+ renderWithProvider(, state);
expect(screen.getByText("Flag")).toBeInTheDocument();
expect(screen.getByText("Option")).toBeInTheDocument();
@@ -290,34 +199,14 @@ describe("ParameterList - Rendering & Structure", () => {
it("shows the correct badge for dataType", () => {
const parameters = [
- createTestParameter({
- key: "string-param-key",
- name: "string-param",
- dataType: "String",
- }),
- createTestParameter({
- key: "number-param-key",
- name: "number-param",
- dataType: "Number",
- }),
- createTestParameter({
- key: "boolean-param-key",
- name: "boolean-param",
- dataType: "Boolean",
- }),
- createTestParameter({
- key: "enum-param-key",
- name: "enum-param",
- dataType: "Enum",
- }),
+ createTestParameter({ key: "string-param-key", name: "string-param", dataType: "String" }),
+ createTestParameter({ key: "number-param-key", name: "number-param", dataType: "Number" }),
+ createTestParameter({ key: "boolean-param-key", name: "boolean-param", dataType: "Boolean" }),
+ createTestParameter({ key: "enum-param-key", name: "enum-param", dataType: "Enum" }),
];
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters };
+ renderWithProvider(, state);
expect(screen.getByText("String")).toBeInTheDocument();
expect(screen.getByText("Number")).toBeInTheDocument();
@@ -327,18 +216,9 @@ describe("ParameterList - Rendering & Structure", () => {
it("shows the global badge if isGlobal is true", () => {
const globalParam = createTestParameter({ isGlobal: true });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [globalParam] },
- }));
-
- render(
- ,
- );
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [globalParam] };
+ renderWithProvider(, state);
const globalCard = screen.getByText("test-param").closest("div.p-3");
expect(globalCard).toHaveTextContent("global");
@@ -349,16 +229,9 @@ describe("ParameterList - Rendering & Structure", () => {
const exclusionGroup = createTestExclusionGroup([parameter.key]);
exclusionGroup.commandKey = "test-command-key";
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: {
- ...prev.tool,
- parameters: [parameter],
- exclusionGroups: [exclusionGroup],
- },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [parameter], exclusionGroups: [exclusionGroup] };
+ renderWithProvider(, state);
expect(screen.getByText("Test Group")).toBeInTheDocument();
const groupBadge = screen.getByText("Test Group").closest("span");
@@ -369,23 +242,17 @@ describe("ParameterList - Rendering & Structure", () => {
const invalidParam = createTestParameter({
dataType: "Number",
defaultValue: "invalid-number",
- validations: [
- {
- key: "validation-key",
- parameterKey: "test-param-key",
- validationType: "min_value",
- validationValue: "0",
- errorMessage: "Must be positive",
- },
- ],
+ validations: [{
+ key: "validation-key",
+ parameterKey: "test-param-key",
+ validationType: "min_value",
+ validationValue: "0",
+ errorMessage: "Must be positive",
+ }],
});
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [invalidParam] },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [invalidParam] };
+ renderWithProvider(, state);
const paramCard = screen.getByText("test-param").closest("div.p-3");
const errorIcon = paramCard?.querySelector("svg[class*='text-destructive']");
@@ -393,17 +260,10 @@ describe("ParameterList - Rendering & Structure", () => {
});
it("shows the success icon if the default value is valid and present", () => {
- const validParam = createTestParameter({
- dataType: "String",
- defaultValue: "valid-value",
- });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [validParam] },
- }));
-
- render();
+ const validParam = createTestParameter({ dataType: "String", defaultValue: "valid-value" });
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [validParam] };
+ renderWithProvider(, state);
const paramCard = screen.getByText("test-param").closest("div.p-3");
const successIcon = paramCard?.querySelector("svg[class*='text-green-500']");
@@ -414,91 +274,64 @@ describe("ParameterList - Rendering & Structure", () => {
describe("Interactions", () => {
it("clicking a parameter card selects it", () => {
const parameter = createTestParameter();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [parameter] },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [parameter] };
+ renderWithProvider(, state);
const paramCard = screen.getByText("test-param").closest("div.p-3");
expect(paramCard).toBeInTheDocument();
-
fireEvent.click(paramCard!);
- const updatedState = toolBuilderStore.state;
- expect(updatedState.selectedParameter?.key).toBe(parameter.key);
+ expect(capturedCtx.selectedParameter?.key).toBe(parameter.key);
});
it("clicking the remove button does not select the parameter", () => {
const parameter = createTestParameter();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [parameter] },
- selectedParameter: null,
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [parameter] };
+ renderWithProvider(, state);
const removeButtons = screen.getAllByRole("button");
const removeButton = removeButtons.find(
(btn) => btn.querySelector("svg") && btn.className.includes("h-6 w-6"),
);
-
fireEvent.click(removeButton!);
- const updatedState = toolBuilderStore.state;
- expect(updatedState.selectedParameter).toBeNull();
+ expect(capturedCtx.selectedParameter).toBeNull();
});
it("add button creates a new parameter with correct context for command parameters", () => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedParameter: null,
- }));
-
- render();
+ const state = baseTestState();
+ state.selectedParameter = null;
+ renderWithProvider(, state);
const addButton = screen.getByRole("button");
fireEvent.click(addButton);
- const updatedState = toolBuilderStore.state;
- expect(updatedState.selectedParameter).toBeTruthy();
- expect(updatedState.selectedParameter?.isGlobal).toBe(false);
- expect(updatedState.selectedParameter?.commandKey).toBe("test-command-key");
+ expect(capturedCtx.selectedParameter).toBeTruthy();
+ expect(capturedCtx.selectedParameter?.isGlobal).toBe(false);
+ expect(capturedCtx.selectedParameter?.commandKey).toBe("test-command-key");
});
it("add button creates a new parameter with correct context for global parameters", () => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedParameter: null,
- tool: { ...prev.tool, parameters: [] },
- }));
-
- render(
- ,
- );
+ const state = baseTestState();
+ state.selectedParameter = null;
+ state.tool = { ...state.tool!, parameters: [] };
+ renderWithProvider(, state);
const addButton = screen.getByRole("button");
fireEvent.click(addButton);
- const updatedState = toolBuilderStore.state;
- expect(updatedState.selectedParameter).toBeTruthy();
- expect(updatedState.selectedParameter?.isGlobal).toBe(true);
+ expect(capturedCtx.selectedParameter).toBeTruthy();
+ expect(capturedCtx.selectedParameter?.isGlobal).toBe(true);
});
});
describe("Edge Cases", () => {
it("renders correctly when there are no parameters", () => {
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [] },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [] };
+ renderWithProvider(, state);
expect(screen.getByText("Empty Parameters (0)")).toBeInTheDocument();
expect(screen.getByRole("button")).toBeInTheDocument();
@@ -506,19 +339,10 @@ describe("ParameterList - Rendering & Structure", () => {
});
it("handles parameters with missing or undefined fields gracefully", () => {
- const paramWithMissingFields = createTestParameter({
- longFlag: "",
- shortFlag: "",
- defaultValue: undefined,
- validations: undefined,
- });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [paramWithMissingFields] },
- }));
-
- render();
+ const paramWithMissingFields = createTestParameter({ longFlag: "", shortFlag: "", defaultValue: undefined, validations: undefined });
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [paramWithMissingFields] };
+ renderWithProvider(, state);
expect(screen.getByText("test-param")).toBeInTheDocument();
expect(screen.getByText("Option")).toBeInTheDocument();
@@ -530,102 +354,22 @@ describe("ParameterList - Rendering & Structure", () => {
const exclusionGroupWithNoParams = createTestExclusionGroup([]);
exclusionGroupWithNoParams.commandKey = "test-command";
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: {
- ...prev.tool,
- parameters: [parameter],
- exclusionGroups: [exclusionGroupWithNoParams],
- },
- }));
-
- render();
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [parameter], exclusionGroups: [exclusionGroupWithNoParams] };
+ renderWithProvider(, state);
expect(screen.getByText("test-param")).toBeInTheDocument();
expect(screen.queryByText("Test Group")).not.toBeInTheDocument();
});
it("handles parameters with both longFlag and shortFlag", () => {
- const paramWithBothFlags = createTestParameter({
- longFlag: "--verbose",
- shortFlag: "-v",
- });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [paramWithBothFlags] },
- }));
-
- render();
+ const paramWithBothFlags = createTestParameter({ longFlag: "--verbose", shortFlag: "-v" });
+ const state = baseTestState();
+ state.tool = { ...state.tool!, parameters: [paramWithBothFlags] };
+ renderWithProvider(, state);
expect(screen.getByText("test-param")).toBeInTheDocument();
expect(screen.getByText("(--verbose, -v)")).toBeInTheDocument();
});
-
- it("handles parameters with only longFlag", () => {
- const paramWithLongFlag = createTestParameter({
- longFlag: "--verbose",
- shortFlag: "",
- });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [paramWithLongFlag] },
- }));
-
- render();
-
- expect(screen.getByText("test-param")).toBeInTheDocument();
- expect(screen.getByText("(--verbose)")).toBeInTheDocument();
- });
-
- it("handles parameters with only shortFlag", () => {
- const paramWithShortFlag = createTestParameter({
- longFlag: "",
- shortFlag: "-v",
- });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [paramWithShortFlag] },
- }));
-
- render();
-
- expect(screen.getByText("test-param")).toBeInTheDocument();
- expect(screen.getByText("(-v)")).toBeInTheDocument();
- });
-
- it("handles parameters with no flags", () => {
- const paramWithNoFlags = createTestParameter({
- longFlag: "",
- shortFlag: "",
- });
-
- toolBuilderStore.setState((prev) => ({
- ...prev,
- tool: { ...prev.tool, parameters: [paramWithNoFlags] },
- }));
-
- render();
-
- expect(screen.getByText("test-param")).toBeInTheDocument();
- const paramCard = screen.getByText("test-param").closest("div");
- expect(paramCard?.textContent).not.toContain("(");
- });
-
- it("handles when selectedParameter is null", () => {
- const parameter = createTestParameter();
- toolBuilderStore.setState((prev) => ({
- ...prev,
- selectedParameter: null,
- tool: { ...prev.tool, parameters: [parameter] },
- }));
-
- render();
-
- const paramCard = screen.getByText("test-param").closest("div.p-3");
- expect(paramCard).not.toHaveClass("bg-muted", "border-primary");
- });
});
});
diff --git a/registry/commandly/__tests__/tool-editor/preview-tabs.test.tsx b/registry/commandly/__tests__/tool-editor/preview-tabs.test.tsx
index 75d7d9a..6ef2865 100644
--- a/registry/commandly/__tests__/tool-editor/preview-tabs.test.tsx
+++ b/registry/commandly/__tests__/tool-editor/preview-tabs.test.tsx
@@ -1,32 +1,15 @@
import { PreviewTabs } from "../../tool-editor/preview-tabs";
+import { ToolBuilderProvider } from "../../tool-editor/tool-editor.context";
+import { defaultTool } from "@/registry/commandly/lib/utils/commandly";
import { render, screen } from "@testing-library/react";
-import { OnUrlUpdateFunction, withNuqsTestingAdapter } from "nuqs/adapters/testing";
-import { vi } from "vitest";
-
-vi.mock("../tool-editor.store", () => ({
- toolBuilderStore: {
- getState: () => ({
- tool: { name: "tool", displayName: "Tool", commands: [], parameters: [] },
- selectedCommand: null,
- }),
- subscribe: vi.fn(),
- },
- toolBuilderSelectors: {
- getGlobalParameters: () => [],
- getParametersForCommand: () => [],
- },
-}));
describe("PreviewTabs", () => {
it("renders tabs", () => {
- const onUrlUpdate = vi.fn();
-
- render(, {
- wrapper: withNuqsTestingAdapter({
- searchParams: "?newTool=newTool",
- onUrlUpdate,
- }),
- });
+ render(
+
+
+ ,
+ );
expect(screen.getByText(/Json/)).toBeInTheDocument();
expect(screen.getByText(/Runtime Preview/)).toBeInTheDocument();
expect(screen.getByText(/Help/, { selector: "button" })).toBeInTheDocument();
diff --git a/registry/commandly/__tests__/tool-editor/tool-editor.test.tsx b/registry/commandly/__tests__/tool-editor/tool-editor.test.tsx
index a8aa4e5..100a481 100644
--- a/registry/commandly/__tests__/tool-editor/tool-editor.test.tsx
+++ b/registry/commandly/__tests__/tool-editor/tool-editor.test.tsx
@@ -4,35 +4,6 @@ import { render, screen } from "@testing-library/react";
import { withNuqsTestingAdapter, type OnUrlUpdateFunction } from "nuqs/adapters/testing";
import { vi } from "vitest";
-vi.mock("../tool-editor.store", () => ({
- toolBuilderStore: {
- getState: () => ({
- tool: { name: "tool", displayName: "Tool", commands: [], parameters: [] },
- selectedCommand: null,
- selectedParameter: null,
- }),
- subscribe: vi.fn(),
- },
- toolBuilderActions: {
- initializeTool: vi.fn(),
- setEditToolDialogOpen: vi.fn(),
- setExclusionGroupsDialogOpen: vi.fn(),
- },
- toolBuilderSelectors: {
- getGlobalParameters: () => [],
- getParametersForCommand: () => [],
- },
-}));
-
-vi.mock("@/lib/utils/tool-editor", async () => {
- const original = await vi.importActual("@/lib/utils/tool-editor");
- return {
- ...original,
- getSavedCommandsFromStorage: vi.fn(() => []),
- removeSavedCommandFromStorage: vi.fn(),
- };
-});
-
describe("ToolEditor", () => {
it("renders tool name and displayName", () => {
const onUrlUpdate = vi.fn();
diff --git a/registry/commandly/tool-editor/command-tree.tsx b/registry/commandly/tool-editor/command-tree.tsx
index fc90b18..91fbb5b 100644
--- a/registry/commandly/tool-editor/command-tree.tsx
+++ b/registry/commandly/tool-editor/command-tree.tsx
@@ -1,10 +1,9 @@
import { CommandDialog } from "../tool-editor/dialogs/command-dialog";
-import { toolBuilderStore, toolBuilderActions } from "./tool-editor.store";
+import { useToolBuilder } from "./tool-editor.context";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Command } from "@/registry/commandly/lib/types/commandly";
-import { useStore } from "@tanstack/react-store";
import { ChevronDownIcon, ChevronRightIcon, Edit2Icon, PlusIcon, Trash2Icon } from "lucide-react";
import { useState, useEffect } from "react";
@@ -16,6 +15,7 @@ interface CommandNodeProps {
selectedCommandKey?: string;
expandedCommands: Set;
onToggle: (commandKey: string) => void;
+ onSelect: (command: Command) => void;
onEdit: (command: Command) => void;
onAddSubcommand: (parentKey?: string) => void;
onDelete: (commandKey: string) => void;
@@ -29,6 +29,7 @@ function CommandNode({
selectedCommandKey,
expandedCommands,
onToggle,
+ onSelect,
onEdit,
onAddSubcommand,
onDelete,
@@ -46,7 +47,7 @@ function CommandNode({
isSelected ? "bg-muted" : ""
}`}
style={{ paddingLeft: `${level * 16 + 8}px` }}
- onClick={() => toolBuilderActions.setSelectedCommand(command)}
+ onClick={() => onSelect(command)}
>
{hasSubcommands ? (
@@ -232,7 +228,7 @@ export function CommandTree() {
isOpen={isDialogOpen}
onOpenChange={(open) => {
setIsDialogOpen(open);
- toolBuilderActions.setEditingCommand(null);
+ setEditingCommand(null);
}}
/>
)}
diff --git a/registry/commandly/tool-editor/dialogs/command-dialog.tsx b/registry/commandly/tool-editor/dialogs/command-dialog.tsx
index a1331b5..1328ab1 100644
--- a/registry/commandly/tool-editor/dialogs/command-dialog.tsx
+++ b/registry/commandly/tool-editor/dialogs/command-dialog.tsx
@@ -1,4 +1,4 @@
-import { toolBuilderActions, toolBuilderStore } from "../tool-editor.store";
+import { useToolBuilder } from "../tool-editor.context";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -13,7 +13,6 @@ import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { Command } from "@/registry/commandly/lib/types/commandly";
-import { useStore } from "@tanstack/react-store";
import { TerminalIcon } from "lucide-react";
import { useState } from "react";
@@ -23,8 +22,9 @@ interface CommandDialogProps {
}
export function CommandDialog({ isOpen, onOpenChange }: CommandDialogProps) {
- const command = useStore(toolBuilderStore, (state) => state.editingCommand);
- const toolName = useStore(toolBuilderStore, (state) => state.tool.name);
+ const { editingCommand, tool, updateCommand } = useToolBuilder();
+ const command = editingCommand;
+ const toolName = tool.name;
const [editCommand, setCommand] = useState