summaryrefslogtreecommitdiff
path: root/packages/cli/src/test-utils/mockCommandContext.test.ts
diff options
context:
space:
mode:
authorAbhi <[email protected]>2025-07-07 16:45:44 -0400
committerGitHub <[email protected]>2025-07-07 20:45:44 +0000
commitaa10ccba713d49bef6bf474bfd72c0852e3da611 (patch)
tree92f1de8bec31cdb10a02fe8ddac1fbde41b75e7f /packages/cli/src/test-utils/mockCommandContext.test.ts
parent6eccb474c77e41aa88d1d1d4ea7eada3e85e746c (diff)
feature(commands) - Refactor Slash Command + Vision For the Future (#3175)
Diffstat (limited to 'packages/cli/src/test-utils/mockCommandContext.test.ts')
-rw-r--r--packages/cli/src/test-utils/mockCommandContext.test.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/packages/cli/src/test-utils/mockCommandContext.test.ts b/packages/cli/src/test-utils/mockCommandContext.test.ts
new file mode 100644
index 00000000..310bf748
--- /dev/null
+++ b/packages/cli/src/test-utils/mockCommandContext.test.ts
@@ -0,0 +1,62 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { vi, describe, it, expect } from 'vitest';
+import { createMockCommandContext } from './mockCommandContext.js';
+
+describe('createMockCommandContext', () => {
+ it('should return a valid CommandContext object with default mocks', () => {
+ const context = createMockCommandContext();
+
+ // Just a few spot checks to ensure the structure is correct
+ // and functions are mocks.
+ expect(context).toBeDefined();
+ expect(context.ui.addItem).toBeInstanceOf(Function);
+ expect(vi.isMockFunction(context.ui.addItem)).toBe(true);
+ });
+
+ it('should apply top-level overrides correctly', () => {
+ const mockClear = vi.fn();
+ const overrides = {
+ ui: {
+ clear: mockClear,
+ },
+ };
+
+ const context = createMockCommandContext(overrides);
+
+ // Call the function to see if the override was used
+ context.ui.clear();
+
+ // Assert that our specific mock was called, not the default
+ expect(mockClear).toHaveBeenCalled();
+ // And that other defaults are still in place
+ expect(vi.isMockFunction(context.ui.addItem)).toBe(true);
+ });
+
+ it('should apply deeply nested overrides correctly', () => {
+ // This is the most important test for factory's logic.
+ const mockConfig = {
+ getProjectRoot: () => '/test/project',
+ getModel: () => 'gemini-pro',
+ };
+
+ const overrides = {
+ services: {
+ config: mockConfig,
+ },
+ };
+
+ const context = createMockCommandContext(overrides);
+
+ expect(context.services.config).toBeDefined();
+ expect(context.services.config?.getModel()).toBe('gemini-pro');
+ expect(context.services.config?.getProjectRoot()).toBe('/test/project');
+
+ // Verify a default property on the same nested object is still there
+ expect(context.services.logger).toBeDefined();
+ });
+});