forked from microsoft/sample-app-aoai-chatGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[upgrade] Start Jest test coverage (microsoft#785)
Co-authored-by: Ian Seabock (Centific Technologies Inc) <[email protected]>
- Loading branch information
Showing
12 changed files
with
11,114 additions
and
3,011 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type {Config} from '@jest/types'; | ||
// Sync object | ||
const config: Config.InitialOptions = { | ||
verbose: true, | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
}; | ||
export default config; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { parseAnswer, ParsedAnswer, enumerateCitations } from "./AnswerParser"; // Update the path accordingly | ||
import { cloneDeep } from "lodash"; | ||
import { Citation, AskResponse } from "../../api"; // Ensure this path matches the location of your types | ||
|
||
const sampleCitations: Citation[] = [ | ||
{ | ||
id: "doc1", | ||
filepath: "file1.pdf", | ||
part_index: undefined, | ||
content: "", | ||
title: null, | ||
url: null, | ||
metadata: null, | ||
chunk_id: null, | ||
reindex_id: null, | ||
}, | ||
{ | ||
id: "doc2", | ||
filepath: "file1.pdf", | ||
part_index: undefined, | ||
content: "", | ||
title: null, | ||
url: null, | ||
metadata: null, | ||
chunk_id: null, | ||
reindex_id: null, | ||
}, | ||
{ | ||
id: "doc3", | ||
filepath: "file2.pdf", | ||
part_index: undefined, | ||
content: "", | ||
title: null, | ||
url: null, | ||
metadata: null, | ||
chunk_id: null, | ||
reindex_id: null, | ||
}, | ||
]; | ||
|
||
const sampleAnswer: AskResponse = { | ||
answer: "This is an example answer with citations [doc1] and [doc2].", | ||
citations: cloneDeep(sampleCitations), | ||
}; | ||
|
||
describe("enumerateCitations", () => { | ||
it("assigns unique part_index based on filepath", () => { | ||
const results = enumerateCitations(cloneDeep(sampleCitations)); | ||
expect(results[0].part_index).toEqual(1); | ||
expect(results[1].part_index).toEqual(2); | ||
expect(results[2].part_index).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe("parseAnswer", () => { | ||
it("reformats the answer text and reindexes citations", () => { | ||
const parsed: ParsedAnswer = parseAnswer(sampleAnswer); | ||
expect(parsed.markdownFormatText).toBe( | ||
"This is an example answer with citations ^1^ and ^2^ ." | ||
); | ||
expect(parsed.citations.length).toBe(2); | ||
expect(parsed.citations[0].id).toBe("1"); | ||
expect(parsed.citations[0].reindex_id).toBe("1"); | ||
expect(parsed.citations[1].id).toBe("2"); | ||
expect(parsed.citations[1].reindex_id).toBe("2"); | ||
expect(parsed.citations[0].part_index).toBe(1); | ||
expect(parsed.citations[1].part_index).toBe(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters