Skip to content

Commit 7db2529

Browse files
committed
fix: lint and duplication in tests
1 parent ea0bc1e commit 7db2529

File tree

1 file changed

+18
-33
lines changed

1 file changed

+18
-33
lines changed

packages/amazonq/test/unit/app/inline/EditRendering/imageRenderer.test.ts

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ describe('showEdits', function () {
2424
let sessionStub: any
2525
let itemStub: InlineCompletionItemWithReferences
2626

27+
// Helper function to create mock SVG result
28+
function createMockSvgResult(overrides: Partial<any> = {}) {
29+
return {
30+
svgImage: vscode.Uri.file('/path/to/generated.svg'),
31+
startLine: 5,
32+
newCode: 'console.log("Hello World");',
33+
origionalCodeHighlightRange: [{ line: 5, start: 0, end: 10 }],
34+
addedCharacterCount: 25,
35+
deletedCharacterCount: 0,
36+
...overrides,
37+
}
38+
}
39+
2740
beforeEach(function () {
2841
sandbox = sinon.createSandbox()
2942

@@ -54,7 +67,7 @@ describe('showEdits', function () {
5467
id: sharedModuleId,
5568
filename: sharedModuleId,
5669
loaded: true,
57-
parent: null,
70+
parent: undefined,
5871
children: [],
5972
exports: mockSharedModule,
6073
paths: [],
@@ -133,14 +146,7 @@ describe('showEdits', function () {
133146

134147
it('should successfully generate and display SVG when all parameters are valid', async function () {
135148
// Setup successful SVG generation
136-
const mockSvgResult = {
137-
svgImage: vscode.Uri.file('/path/to/generated.svg'),
138-
startLine: 5,
139-
newCode: 'console.log("Hello World");',
140-
origionalCodeHighlightRange: [{ line: 5, start: 0, end: 10 }],
141-
addedCharacterCount: 25,
142-
deletedCharacterCount: 0,
143-
}
149+
const mockSvgResult = createMockSvgResult()
144150
svgGenerationServiceStub.generateDiffSvg.resolves(mockSvgResult)
145151

146152
await showEdits(itemStub, editorStub as unknown as vscode.TextEditor, sessionStub, languageClientStub)
@@ -175,14 +181,7 @@ describe('showEdits', function () {
175181

176182
it('should log error when SVG generation returns empty result', async function () {
177183
// Setup SVG generation to return undefined svgImage
178-
const mockSvgResult = {
179-
svgImage: undefined as any,
180-
startLine: 5,
181-
newCode: 'console.log("Hello World");',
182-
origionalCodeHighlightRange: [{ line: 5, start: 0, end: 10 }],
183-
addedCharacterCount: 25,
184-
deletedCharacterCount: 0,
185-
}
184+
const mockSvgResult = createMockSvgResult({ svgImage: undefined as any })
186185
svgGenerationServiceStub.generateDiffSvg.resolves(mockSvgResult)
187186

188187
await showEdits(itemStub, editorStub as unknown as vscode.TextEditor, sessionStub, languageClientStub)
@@ -219,14 +218,7 @@ describe('showEdits', function () {
219218

220219
it('should catch and log error when displaySvgDecoration throws exception', async function () {
221220
// Setup successful SVG generation
222-
const mockSvgResult = {
223-
svgImage: vscode.Uri.file('/path/to/generated.svg'),
224-
startLine: 5,
225-
newCode: 'console.log("Hello World");',
226-
origionalCodeHighlightRange: [{ line: 5, start: 0, end: 10 }],
227-
addedCharacterCount: 25,
228-
deletedCharacterCount: 0,
229-
}
221+
const mockSvgResult = createMockSvgResult()
230222
svgGenerationServiceStub.generateDiffSvg.resolves(mockSvgResult)
231223

232224
// Setup displaySvgDecoration to throw an error
@@ -262,14 +254,7 @@ describe('showEdits', function () {
262254
} as any
263255

264256
// Setup successful SVG generation
265-
const mockSvgResult = {
266-
svgImage: vscode.Uri.file('/path/to/generated.svg'),
267-
startLine: 5,
268-
newCode: 'console.log("Hello World");',
269-
origionalCodeHighlightRange: [{ line: 5, start: 0, end: 10 }],
270-
addedCharacterCount: 25,
271-
deletedCharacterCount: 0,
272-
}
257+
const mockSvgResult = createMockSvgResult()
273258
svgGenerationServiceStub.generateDiffSvg.resolves(mockSvgResult)
274259

275260
await showEdits(

0 commit comments

Comments
 (0)