From 764721c07c0a275eea65e2d98d795702797add1c Mon Sep 17 00:00:00 2001 From: Hitesh Sagtani Date: Sun, 12 Jan 2025 14:49:07 +0530 Subject: [PATCH] feat(auto-edits): add test case for setting context (#6592) Adds the test case for the two issues we faced: 1. Tab not working when conflicted with edit command decorations. [Resolves comment](https://github.com/sourcegraph/cody/pull/6581#discussion_r1909965922) - [test cases for PR](https://github.com/sourcegraph/cody/pull/6581) 2. Suffix getting duplicated because in addition to inline acceptance, we were modifying the document again on accept - [[test case for PR](https://github.com/sourcegraph/cody/pull/6583)] ## Test plan Added test case --- .../src/autoedits/autoedits-provider.test.ts | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/vscode/src/autoedits/autoedits-provider.test.ts b/vscode/src/autoedits/autoedits-provider.test.ts index 2f1ca6f90c9b..59003cdf0477 100644 --- a/vscode/src/autoedits/autoedits-provider.test.ts +++ b/vscode/src/autoedits/autoedits-provider.test.ts @@ -339,4 +339,78 @@ describe('AutoeditsProvider', () => { ] `) }) + + it('do not set the the cody.supersuggest.active context for inline completion items', async () => { + const prediction = 'const x = 1\n' + await autoeditResultFor('const x = █\n', { prediction }) + expect(executedCommands).toMatchInlineSnapshot(` + [] + `) + }) + + it('set the cody.supersuggest.active context for inline decoration items', async () => { + const prediction = 'const a = 1\n' + await autoeditResultFor('const x = █\n', { prediction }) + expect(executedCommands).toMatchInlineSnapshot(` + [ + [ + "setContext", + "cody.supersuggest.active", + true, + ], + ] + `) + await acceptSuggestionCommand() + + // Deactives the context after accepting the suggestion + expect(executedCommands.length).toBe(3) + expect(executedCommands[1]).toMatchInlineSnapshot(` + [ + "setContext", + "cody.supersuggest.active", + false, + ] + `) + }) + + it('unset the cody.supersuggest.active context for inline decoration rejection', async () => { + const prediction = 'const a = 1\n' + await autoeditResultFor('const x = █\n', { prediction }) + expect(executedCommands).toMatchInlineSnapshot(` + [ + [ + "setContext", + "cody.supersuggest.active", + true, + ], + ] + `) + await rejectSuggestionCommand() + + // Deactives the context after accepting the suggestion + expect(executedCommands.length).toBe(3) + expect(executedCommands[1]).toMatchInlineSnapshot(` + [ + "setContext", + "cody.supersuggest.active", + false, + ] + `) + }) + + it('do not trigger the editBuilder for inline completion items', async () => { + const prediction = 'const x = 1\n' + const { editBuilder } = await autoeditResultFor('const x = █\n', { prediction }) + + await acceptSuggestionCommand() + expect(editBuilder.size).toBe(0) + }) + + it('trigger the editBuilder for inline decorations items', async () => { + const prediction = 'const a = 1\n' + const { editBuilder } = await autoeditResultFor('const x = █\n', { prediction }) + + await acceptSuggestionCommand() + expect(editBuilder.size).toBe(1) + }) })