Skip to content

Commit a032adc

Browse files
committed
added test cases for new parseDiff logic
1 parent 0bf481e commit a032adc

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

packages/amazonq/test/unit/amazonqGumby/transformationResultsHandler.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('DiffModel', function () {
1515
let parsedTestDescription: PatchInfo
1616
beforeEach(() => {
1717
parsedTestDescription = JSON.parse(
18-
'{"name": "Added file", "fileName": "resources/files/addedFile.diffs", "isSuccessful": true}'
18+
'{"name": "Added file", "fileName": "resources/files/addedFile.diff", "isSuccessful": true}'
1919
)
2020
})
2121

@@ -43,7 +43,37 @@ describe('DiffModel', function () {
4343
parsedTestDescription
4444
)
4545

46+
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
4647
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
48+
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescription.name)
49+
const change = testDiffModel.patchFileNodes[0].children[0]
50+
51+
assert.strictEqual(change instanceof AddedChangeNode, true)
52+
})
53+
54+
it('WHEN parsing a diff patch with no diff.json where a file was added THEN returns an array representing the added file', async function () {
55+
const testDiffModel = new DiffModel()
56+
57+
const workspacePath = 'workspace'
58+
59+
sinon.replace(fs, 'exists', async (path) => {
60+
const pathStr = path.toString()
61+
if (pathStr.includes(workspacePath)) {
62+
return false
63+
}
64+
65+
return true
66+
})
67+
68+
testDiffModel.parseDiff(
69+
getTestResourceFilePath('resources/files/addedFile.diff'),
70+
workspacePath,
71+
parsedTestDescription
72+
)
73+
74+
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
75+
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
76+
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescription.name)
4777
const change = testDiffModel.patchFileNodes[0].children[0]
4878

4979
assert.strictEqual(change instanceof AddedChangeNode, true)
@@ -67,7 +97,9 @@ describe('DiffModel', function () {
6797
parsedTestDescription
6898
)
6999

100+
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
70101
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
102+
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescription.name)
71103
const change = testDiffModel.patchFileNodes[0].children[0]
72104

73105
assert.strictEqual(change instanceof ModifiedChangeNode, true)

0 commit comments

Comments
 (0)