Skip to content

Commit

Permalink
feat(auto-edits): add test case for setting context (#6592)
Browse files Browse the repository at this point in the history
Adds the test case for the two issues we faced:
1. Tab not working when conflicted with edit command decorations.
[Resolves
comment](#6581 (comment))
- [test cases for PR](#6581)
2. Suffix getting duplicated because in addition to inline acceptance,
we were modifying the document again on accept - [[test case for
PR](#6583)]

## Test plan
Added test case
  • Loading branch information
hitesh-1997 authored Jan 12, 2025
1 parent e5425fd commit 764721c
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions vscode/src/autoedits/autoedits-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit 764721c

Please sign in to comment.