2019-10-12 21:45:49 +00:00
|
|
|
import LineByLineRenderer from "../line-by-line-renderer";
|
|
|
|
|
import HoganJsUtils from "../hoganjs-utils";
|
2019-11-26 16:07:53 +00:00
|
|
|
import { LineType, DiffFile, LineMatchingType } from "../types";
|
2019-10-21 22:37:42 +00:00
|
|
|
import { CSSLineClass } from "../render-utils";
|
2019-10-12 21:45:49 +00:00
|
|
|
|
|
|
|
|
describe("LineByLineRenderer", () => {
|
|
|
|
|
describe("_generateEmptyDiff", () => {
|
|
|
|
|
it("should return an empty diff", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
|
|
|
|
const fileHtml = lineByLineRenderer.generateEmptyDiff();
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-info">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-info">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" File without changes\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2015-12-22 15:48:33 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2015-12-27 10:08:24 +00:00
|
|
|
});
|
|
|
|
|
});
|
2016-04-25 15:51:27 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
describe("makeLineHtml", () => {
|
|
|
|
|
it("should work for insertions", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2019-11-26 16:07:53 +00:00
|
|
|
let fileHtml = lineByLineRenderer.makeLineHtml(CSSLineClass.INSERTS, "+", "test", undefined, 30);
|
2019-10-06 20:04:33 +00:00
|
|
|
fileHtml = fileHtml.replace(/\n\n+/g, "\n");
|
|
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1"></div>\n' +
|
|
|
|
|
'<div class="line-num2">30</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-ins">\n' +
|
2016-09-05 21:13:51 +00:00
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn">test</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2015-12-27 10:08:24 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2015-12-27 10:08:24 +00:00
|
|
|
});
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should work for deletions", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2019-11-26 16:07:53 +00:00
|
|
|
let fileHtml = lineByLineRenderer.makeLineHtml(CSSLineClass.DELETES, "-", "test", 30, undefined);
|
2019-10-06 20:04:33 +00:00
|
|
|
fileHtml = fileHtml.replace(/\n\n+/g, "\n");
|
|
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-del">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1">30</div>\n' +
|
|
|
|
|
'<div class="line-num2"></div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-del">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-del">\n' +
|
2016-09-05 21:13:51 +00:00
|
|
|
' <span class="d2h-code-line-prefix">-</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn">test</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2015-12-27 10:08:24 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2016-01-28 15:03:20 +00:00
|
|
|
});
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should convert indents into non breakin spaces (2 white spaces)", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2019-11-26 16:07:53 +00:00
|
|
|
let fileHtml = lineByLineRenderer.makeLineHtml(CSSLineClass.INSERTS, "+", " test", undefined, 30);
|
2019-10-06 20:04:33 +00:00
|
|
|
fileHtml = fileHtml.replace(/\n\n+/g, "\n");
|
|
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1"></div>\n' +
|
|
|
|
|
'<div class="line-num2">30</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-ins">\n' +
|
2016-09-05 21:13:51 +00:00
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"> test</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2016-01-28 15:03:20 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2016-01-28 15:03:20 +00:00
|
|
|
});
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should convert indents into non breakin spaces (4 white spaces)", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2019-11-26 16:07:53 +00:00
|
|
|
let fileHtml = lineByLineRenderer.makeLineHtml(CSSLineClass.INSERTS, "+", " test", undefined, 30);
|
2019-10-06 20:04:33 +00:00
|
|
|
fileHtml = fileHtml.replace(/\n\n+/g, "\n");
|
|
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1"></div>\n' +
|
|
|
|
|
'<div class="line-num2">30</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-ins">\n' +
|
2016-09-05 21:13:51 +00:00
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"> test</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2016-01-28 15:03:20 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2016-01-28 15:03:20 +00:00
|
|
|
});
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should preserve tabs", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2019-11-26 16:07:53 +00:00
|
|
|
let fileHtml = lineByLineRenderer.makeLineHtml(CSSLineClass.INSERTS, "+", "\ttest", undefined, 30);
|
2019-10-06 20:04:33 +00:00
|
|
|
fileHtml = fileHtml.replace(/\n\n+/g, "\n");
|
|
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1"></div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
"" +
|
2016-05-21 00:34:03 +00:00
|
|
|
'<div class="line-num2">30</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2016-02-24 00:13:43 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-ins">\n' +
|
2016-09-05 21:13:51 +00:00
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
2019-04-15 16:17:55 +00:00
|
|
|
' <span class="d2h-code-line-ctn">\ttest</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2016-01-28 15:03:20 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2015-12-22 15:48:33 +00:00
|
|
|
});
|
|
|
|
|
});
|
2016-04-25 15:51:27 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
describe("makeFileDiffHtml", () => {
|
|
|
|
|
it("should work for simple file", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2016-04-25 15:51:27 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const file = {
|
2016-04-25 15:51:27 +00:00
|
|
|
addedLines: 12,
|
|
|
|
|
deletedLines: 41,
|
2019-10-06 20:04:33 +00:00
|
|
|
language: "js",
|
|
|
|
|
oldName: "my/file/name.js",
|
2019-10-12 21:45:49 +00:00
|
|
|
newName: "my/file/name.js",
|
|
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: false,
|
|
|
|
|
blocks: []
|
2016-04-25 15:51:27 +00:00
|
|
|
};
|
2019-10-06 20:04:33 +00:00
|
|
|
const diffs = "<span>Random Html</span>";
|
2016-04-25 15:51:27 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const fileHtml = lineByLineRenderer.makeFileDiffHtml(file, diffs);
|
2016-04-25 15:51:27 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected =
|
2016-05-21 00:34:03 +00:00
|
|
|
'<div id="d2h-781444" class="d2h-file-wrapper" data-lang="js">\n' +
|
|
|
|
|
' <div class="d2h-file-header">\n' +
|
|
|
|
|
' <span class="d2h-file-name-wrapper">\n' +
|
2018-11-18 15:38:46 +00:00
|
|
|
' <svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">\n' +
|
|
|
|
|
' <path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>\n' +
|
|
|
|
|
' </svg> <span class="d2h-file-name">my/file/name.js</span>\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-file-diff">\n' +
|
|
|
|
|
' <div class="d2h-code-wrapper">\n' +
|
|
|
|
|
' <table class="d2h-diff-table">\n' +
|
|
|
|
|
' <tbody class="d2h-diff-tbody">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" <span>Random Html</span>\n" +
|
|
|
|
|
" </tbody>\n" +
|
|
|
|
|
" </table>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
"</div>";
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2016-05-21 00:34:03 +00:00
|
|
|
});
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should work for simple added file", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const file = {
|
2016-05-21 00:34:03 +00:00
|
|
|
addedLines: 12,
|
|
|
|
|
deletedLines: 0,
|
2019-10-06 20:04:33 +00:00
|
|
|
language: "js",
|
|
|
|
|
oldName: "dev/null",
|
|
|
|
|
newName: "my/file/name.js",
|
2019-10-12 21:45:49 +00:00
|
|
|
isNew: true,
|
|
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: false,
|
|
|
|
|
blocks: []
|
2016-05-21 00:34:03 +00:00
|
|
|
};
|
2019-10-06 20:04:33 +00:00
|
|
|
const diffs = "<span>Random Html</span>";
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const fileHtml = lineByLineRenderer.makeFileDiffHtml(file, diffs);
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected =
|
2016-05-21 00:34:03 +00:00
|
|
|
'<div id="d2h-781444" class="d2h-file-wrapper" data-lang="js">\n' +
|
|
|
|
|
' <div class="d2h-file-header">\n' +
|
|
|
|
|
' <span class="d2h-file-name-wrapper">\n' +
|
2018-11-18 15:38:46 +00:00
|
|
|
' <svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">\n' +
|
|
|
|
|
' <path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>\n' +
|
|
|
|
|
' </svg> <span class="d2h-file-name">my/file/name.js</span>\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <span class="d2h-tag d2h-added d2h-added-tag">ADDED</span></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-file-diff">\n' +
|
|
|
|
|
' <div class="d2h-code-wrapper">\n' +
|
|
|
|
|
' <table class="d2h-diff-table">\n' +
|
|
|
|
|
' <tbody class="d2h-diff-tbody">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" <span>Random Html</span>\n" +
|
|
|
|
|
" </tbody>\n" +
|
|
|
|
|
" </table>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
"</div>";
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2016-05-21 00:34:03 +00:00
|
|
|
});
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should work for simple deleted file", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const file = {
|
2016-05-21 00:34:03 +00:00
|
|
|
addedLines: 0,
|
|
|
|
|
deletedLines: 41,
|
2019-10-06 20:04:33 +00:00
|
|
|
language: "js",
|
|
|
|
|
oldName: "my/file/name.js",
|
|
|
|
|
newName: "dev/null",
|
2019-10-12 21:45:49 +00:00
|
|
|
isDeleted: true,
|
|
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: false,
|
|
|
|
|
blocks: []
|
2016-05-21 00:34:03 +00:00
|
|
|
};
|
2019-10-06 20:04:33 +00:00
|
|
|
const diffs = "<span>Random Html</span>";
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const fileHtml = lineByLineRenderer.makeFileDiffHtml(file, diffs);
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected =
|
2016-05-21 00:34:03 +00:00
|
|
|
'<div id="d2h-781444" class="d2h-file-wrapper" data-lang="js">\n' +
|
|
|
|
|
' <div class="d2h-file-header">\n' +
|
|
|
|
|
' <span class="d2h-file-name-wrapper">\n' +
|
2018-11-18 15:38:46 +00:00
|
|
|
' <svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">\n' +
|
|
|
|
|
' <path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>\n' +
|
|
|
|
|
' </svg> <span class="d2h-file-name">my/file/name.js</span>\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <span class="d2h-tag d2h-deleted d2h-deleted-tag">DELETED</span></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-file-diff">\n' +
|
|
|
|
|
' <div class="d2h-code-wrapper">\n' +
|
|
|
|
|
' <table class="d2h-diff-table">\n' +
|
|
|
|
|
' <tbody class="d2h-diff-tbody">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" <span>Random Html</span>\n" +
|
|
|
|
|
" </tbody>\n" +
|
|
|
|
|
" </table>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
"</div>";
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2016-05-21 00:34:03 +00:00
|
|
|
});
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should work for simple renamed file", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const file = {
|
2016-05-21 00:34:03 +00:00
|
|
|
addedLines: 12,
|
|
|
|
|
deletedLines: 41,
|
2019-10-06 20:04:33 +00:00
|
|
|
language: "js",
|
|
|
|
|
oldName: "my/file/name1.js",
|
|
|
|
|
newName: "my/file/name2.js",
|
2019-10-12 21:45:49 +00:00
|
|
|
isRename: true,
|
|
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: false,
|
|
|
|
|
blocks: []
|
2016-05-21 00:34:03 +00:00
|
|
|
};
|
2019-10-06 20:04:33 +00:00
|
|
|
const diffs = "<span>Random Html</span>";
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const fileHtml = lineByLineRenderer.makeFileDiffHtml(file, diffs);
|
2016-05-21 00:34:03 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected =
|
2016-05-21 00:34:03 +00:00
|
|
|
'<div id="d2h-662683" class="d2h-file-wrapper" data-lang="js">\n' +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <div class="d2h-file-header">\n' +
|
|
|
|
|
' <span class="d2h-file-name-wrapper">\n' +
|
2018-11-18 15:38:46 +00:00
|
|
|
' <svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">\n' +
|
|
|
|
|
' <path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>\n' +
|
|
|
|
|
' </svg> <span class="d2h-file-name">my/file/{name1.js → name2.js}</span>\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <span class="d2h-tag d2h-moved d2h-moved-tag">RENAMED</span></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <div class="d2h-file-diff">\n' +
|
|
|
|
|
' <div class="d2h-code-wrapper">\n' +
|
|
|
|
|
' <table class="d2h-diff-table">\n' +
|
|
|
|
|
' <tbody class="d2h-diff-tbody">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" <span>Random Html</span>\n" +
|
|
|
|
|
" </tbody>\n" +
|
|
|
|
|
" </table>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
"</div>";
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2019-01-31 23:58:48 +00:00
|
|
|
});
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should return empty when option renderNothingWhenEmpty is true and file blocks not present", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {
|
2019-02-01 00:18:24 +00:00
|
|
|
renderNothingWhenEmpty: true
|
2019-01-31 23:58:48 +00:00
|
|
|
});
|
|
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const file = {
|
2019-10-12 21:45:49 +00:00
|
|
|
addedLines: 0,
|
|
|
|
|
deletedLines: 0,
|
|
|
|
|
language: "js",
|
|
|
|
|
oldName: "my/file/name1.js",
|
|
|
|
|
newName: "my/file/name2.js",
|
|
|
|
|
isRename: true,
|
|
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: false,
|
2019-02-01 00:18:24 +00:00
|
|
|
blocks: []
|
2019-01-31 23:58:48 +00:00
|
|
|
};
|
|
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const diffs = "<span>Random Html</span>";
|
2019-01-31 23:58:48 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const fileHtml = lineByLineRenderer.makeFileDiffHtml(file, diffs);
|
2019-01-31 23:58:48 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected = "";
|
2019-01-31 23:58:48 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(fileHtml).toEqual(expected);
|
2016-04-25 15:51:27 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
describe("generateLineByLineJsonHtml", () => {
|
|
|
|
|
it("should work for list of files", () => {
|
|
|
|
|
const exampleJson: DiffFile[] = [
|
2016-12-17 23:39:21 +00:00
|
|
|
{
|
|
|
|
|
blocks: [
|
2016-04-25 15:51:27 +00:00
|
|
|
{
|
2016-12-17 23:39:21 +00:00
|
|
|
lines: [
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "-test",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.DELETE,
|
2016-12-17 23:39:21 +00:00
|
|
|
oldNumber: 1,
|
2019-10-12 21:45:49 +00:00
|
|
|
newNumber: undefined
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "+test1r",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2016-12-17 23:39:21 +00:00
|
|
|
newNumber: 1
|
|
|
|
|
}
|
|
|
|
|
],
|
2019-10-12 21:45:49 +00:00
|
|
|
oldStartLine: 1,
|
|
|
|
|
oldStartLine2: undefined,
|
|
|
|
|
newStartLine: 1,
|
2019-10-06 20:04:33 +00:00
|
|
|
header: "@@ -1 +1 @@"
|
2016-12-17 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
deletedLines: 1,
|
|
|
|
|
addedLines: 1,
|
2019-10-06 20:04:33 +00:00
|
|
|
checksumBefore: "0000001",
|
|
|
|
|
checksumAfter: "0ddf2ba",
|
|
|
|
|
oldName: "sample",
|
|
|
|
|
newName: "sample",
|
2019-10-12 21:45:49 +00:00
|
|
|
language: "txt",
|
|
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: true
|
2016-12-17 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 15:51:27 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {
|
2019-10-21 22:37:42 +00:00
|
|
|
matching: LineMatchingType.LINES
|
2019-10-12 21:45:49 +00:00
|
|
|
});
|
|
|
|
|
const html = lineByLineRenderer.render(exampleJson);
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected =
|
2016-04-25 15:51:27 +00:00
|
|
|
'<div class="d2h-wrapper">\n' +
|
2019-10-12 21:45:49 +00:00
|
|
|
' <div id="d2h-675094" class="d2h-file-wrapper" data-lang="txt">\n' +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <div class="d2h-file-header">\n' +
|
|
|
|
|
' <span class="d2h-file-name-wrapper">\n' +
|
2018-11-18 15:38:46 +00:00
|
|
|
' <svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">\n' +
|
|
|
|
|
' <path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>\n' +
|
|
|
|
|
' </svg> <span class="d2h-file-name">sample</span>\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <div class="d2h-file-diff">\n' +
|
|
|
|
|
' <div class="d2h-code-wrapper">\n' +
|
|
|
|
|
' <table class="d2h-diff-table">\n' +
|
|
|
|
|
' <tbody class="d2h-diff-tbody">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" <tr>\n" +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-info"></td>\n' +
|
|
|
|
|
' <td class="d2h-info">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-code-line d2h-info">@@ -1 +1 @@</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2019-10-12 21:45:49 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-del d2h-change">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1">1</div>\n' +
|
|
|
|
|
'<div class="line-num2"></div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2019-10-12 21:45:49 +00:00
|
|
|
' <td class="d2h-del d2h-change">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-del d2h-change">\n' +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <span class="d2h-code-line-prefix">-</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"><del>test</del></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2019-10-12 21:45:49 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-ins d2h-change">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1"></div>\n' +
|
|
|
|
|
'<div class="line-num2">1</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2019-10-12 21:45:49 +00:00
|
|
|
' <td class="d2h-ins d2h-change">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-ins d2h-change">\n' +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"><ins>test1r</ins></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>\n" +
|
|
|
|
|
" </tbody>\n" +
|
|
|
|
|
" </table>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
"</div>\n" +
|
|
|
|
|
"</div>";
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(html).toEqual(expected);
|
2016-04-25 15:51:27 +00:00
|
|
|
});
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should work for empty blocks", () => {
|
2019-10-06 20:04:33 +00:00
|
|
|
const exampleJson = [
|
|
|
|
|
{
|
|
|
|
|
blocks: [],
|
|
|
|
|
deletedLines: 0,
|
|
|
|
|
addedLines: 0,
|
|
|
|
|
oldName: "sample",
|
|
|
|
|
language: "js",
|
|
|
|
|
newName: "sample",
|
2019-10-12 21:45:49 +00:00
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: false
|
2019-10-06 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 18:24:35 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {
|
|
|
|
|
renderNothingWhenEmpty: false
|
|
|
|
|
});
|
|
|
|
|
const html = lineByLineRenderer.render(exampleJson);
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected =
|
2016-04-25 18:24:35 +00:00
|
|
|
'<div class="d2h-wrapper">\n' +
|
|
|
|
|
' <div id="d2h-675094" class="d2h-file-wrapper" data-lang="js">\n' +
|
|
|
|
|
' <div class="d2h-file-header">\n' +
|
|
|
|
|
' <span class="d2h-file-name-wrapper">\n' +
|
2018-11-18 15:38:46 +00:00
|
|
|
' <svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">\n' +
|
|
|
|
|
' <path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>\n' +
|
|
|
|
|
' </svg> <span class="d2h-file-name">sample</span>\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
2016-04-25 18:24:35 +00:00
|
|
|
' <div class="d2h-file-diff">\n' +
|
|
|
|
|
' <div class="d2h-code-wrapper">\n' +
|
|
|
|
|
' <table class="d2h-diff-table">\n' +
|
|
|
|
|
' <tbody class="d2h-diff-tbody">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" <tr>\n" +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <td class="d2h-info">\n' +
|
2016-04-25 18:24:35 +00:00
|
|
|
' <div class="d2h-code-line d2h-info">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" File without changes\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>\n" +
|
|
|
|
|
" </tbody>\n" +
|
|
|
|
|
" </table>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
"</div>\n" +
|
|
|
|
|
"</div>";
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(html).toEqual(expected);
|
2016-04-25 15:51:27 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
describe("_generateFileHtml", () => {
|
|
|
|
|
it("should work for simple file", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const lineByLineRenderer = new LineByLineRenderer(hoganUtils, {});
|
|
|
|
|
const file: DiffFile = {
|
2016-12-17 23:39:21 +00:00
|
|
|
blocks: [
|
|
|
|
|
{
|
|
|
|
|
lines: [
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: " one context line",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.CONTEXT,
|
2016-12-17 23:39:21 +00:00
|
|
|
oldNumber: 1,
|
|
|
|
|
newNumber: 1
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "-test",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.DELETE,
|
2016-12-17 23:39:21 +00:00
|
|
|
oldNumber: 2,
|
2019-10-12 21:45:49 +00:00
|
|
|
newNumber: undefined
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "+test1r",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2016-12-17 23:39:21 +00:00
|
|
|
newNumber: 2
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "+test2r",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2016-12-17 23:39:21 +00:00
|
|
|
newNumber: 3
|
|
|
|
|
}
|
|
|
|
|
],
|
2019-10-12 21:45:49 +00:00
|
|
|
oldStartLine: 1,
|
|
|
|
|
oldStartLine2: undefined,
|
|
|
|
|
newStartLine: 1,
|
2019-10-06 20:04:33 +00:00
|
|
|
header: "@@ -1 +1 @@"
|
2016-12-17 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
],
|
2016-04-25 15:51:27 +00:00
|
|
|
deletedLines: 1,
|
|
|
|
|
addedLines: 1,
|
2019-10-06 20:04:33 +00:00
|
|
|
checksumBefore: "0000001",
|
|
|
|
|
checksumAfter: "0ddf2ba",
|
|
|
|
|
oldName: "sample",
|
2019-10-12 21:45:49 +00:00
|
|
|
language: "txt",
|
2019-10-06 20:04:33 +00:00
|
|
|
newName: "sample",
|
2019-10-12 21:45:49 +00:00
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: true
|
2016-04-25 15:51:27 +00:00
|
|
|
};
|
|
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const html = lineByLineRenderer.generateFileHtml(file);
|
2016-04-25 15:51:27 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-info"></td>\n' +
|
|
|
|
|
' <td class="d2h-info">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-code-line d2h-info">@@ -1 +1 @@</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2016-04-25 18:24:35 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-cntx">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1">1</div>\n' +
|
|
|
|
|
'<div class="line-num2">1</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2016-04-25 18:24:35 +00:00
|
|
|
' <td class="d2h-cntx">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-cntx">\n' +
|
2019-07-06 17:51:50 +00:00
|
|
|
' <span class="d2h-code-line-prefix"> </span>\n' +
|
2016-09-05 21:13:51 +00:00
|
|
|
' <span class="d2h-code-line-ctn">one context line</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2019-11-26 16:07:53 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-del d2h-change">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1">2</div>\n' +
|
|
|
|
|
'<div class="line-num2"></div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2019-11-26 16:07:53 +00:00
|
|
|
' <td class="d2h-del d2h-change">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-del d2h-change">\n' +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <span class="d2h-code-line-prefix">-</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"><del>test</del></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2019-11-26 16:07:53 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-ins d2h-change">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1"></div>\n' +
|
|
|
|
|
'<div class="line-num2">2</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2019-11-26 16:07:53 +00:00
|
|
|
' <td class="d2h-ins d2h-change">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-ins d2h-change">\n' +
|
2016-04-25 15:51:27 +00:00
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"><ins>test1r</ins></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2016-04-25 18:24:35 +00:00
|
|
|
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="line-num1"></div>\n' +
|
|
|
|
|
'<div class="line-num2">3</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
2016-04-25 18:24:35 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-line d2h-ins">\n' +
|
2016-09-05 21:13:51 +00:00
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn">test2r</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2016-04-25 15:51:27 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(html).toEqual(expected);
|
2016-04-25 15:51:27 +00:00
|
|
|
});
|
|
|
|
|
});
|
2015-12-22 15:48:33 +00:00
|
|
|
});
|