Add marker for expansion hunks

This commit is contained in:
René Pfeuffer
2020-06-09 13:57:44 +02:00
parent 5d7641f129
commit d909ff4ae4
3 changed files with 22 additions and 14 deletions

View File

@@ -289,9 +289,12 @@ describe("with hunks the diff expander", () => {
expect(fetchMock.done()).toBe(true);
expect(newFile!.hunks!.length).toBe(oldHunkCount + 1);
expect(newFile!.hunks![1]).toBe(expandedHunk);
const newHunk = newFile!.hunks![2].changes;
expect(newHunk.length).toBe(1);
expect(newHunk[0].content).toBe("new line 1");
const newHunk = newFile!.hunks![2];
expect(newHunk.changes.length).toBe(1);
expect(newHunk.changes[0].content).toBe("new line 1");
expect(newHunk.expansion).toBe(true);
expect(newFile!.hunks![3]).toBe(subsequentHunk);
});
it("should create new hunk with new line from api client at the top", async () => {
@@ -313,16 +316,18 @@ describe("with hunks the diff expander", () => {
expect(newFile!.hunks![0]).toBe(preceedingHunk);
expect(newFile!.hunks![2]).toBe(expandedHunk);
expect(newFile!.hunks![1].changes.length).toBe(5);
expect(newFile!.hunks![1].changes[0].content).toBe("new line 9");
expect(newFile!.hunks![1].changes[0].oldLineNumber).toBe(9);
expect(newFile!.hunks![1].changes[0].newLineNumber).toBe(9);
expect(newFile!.hunks![1].changes[1].content).toBe("new line 10");
expect(newFile!.hunks![1].changes[1].oldLineNumber).toBe(10);
expect(newFile!.hunks![1].changes[1].newLineNumber).toBe(10);
expect(newFile!.hunks![1].changes[4].content).toBe("new line 13");
expect(newFile!.hunks![1].changes[4].oldLineNumber).toBe(13);
expect(newFile!.hunks![1].changes[4].newLineNumber).toBe(13);
const newHunk = newFile!.hunks![1];
expect(newHunk.changes.length).toBe(5);
expect(newHunk.changes[0].content).toBe("new line 9");
expect(newHunk.changes[0].oldLineNumber).toBe(9);
expect(newHunk.changes[0].newLineNumber).toBe(9);
expect(newHunk.changes[1].content).toBe("new line 10");
expect(newHunk.changes[1].oldLineNumber).toBe(10);
expect(newHunk.changes[1].newLineNumber).toBe(10);
expect(newHunk.changes[4].content).toBe("new line 13");
expect(newHunk.changes[4].oldLineNumber).toBe(13);
expect(newHunk.changes[4].newLineNumber).toBe(13);
expect(newHunk.expansion).toBe(true);
});
it("should set fully expanded to true if expanded completely", async () => {
const oldHunkCount = diffExpander.hunkCount();

View File

@@ -133,7 +133,8 @@ class DiffExpander {
newStart: minNewLineNumberOfNewHunk,
oldLines: lines.length,
newLines: lines.length,
changes: newChanges
changes: newChanges,
expansion: true
};
const newHunks: Hunk[] = [];
this.file.hunks!.forEach((oldHunk: Hunk, i: number) => {
@@ -178,6 +179,7 @@ class DiffExpander {
newStart: maxNewLineNumberFromPrecedingHunk + 1,
oldLines: lines.length,
newLines: lines.length,
expansion: true,
fullyExpanded: requestedLines < 0 || lines.length < requestedLines
};

View File

@@ -58,6 +58,7 @@ export type Hunk = {
oldLines?: number;
newLines?: number;
fullyExpanded?: boolean;
expansion?: boolean;
};
export type ChangeType = "insert" | "delete" | "normal" | "conflict";