2019-10-06 20:04:33 +00:00
|
|
|
const SideBySidePrinter = require("../side-by-side-printer.js").SideBySidePrinter;
|
2015-12-22 15:48:33 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
describe("SideBySidePrinter", function() {
|
|
|
|
|
describe("generateEmptyDiff", function() {
|
|
|
|
|
it("should return an empty diff", function() {
|
|
|
|
|
const sideBySidePrinter = new SideBySidePrinter({});
|
|
|
|
|
const fileHtml = sideBySidePrinter.generateEmptyDiff();
|
|
|
|
|
const expectedRight = "";
|
|
|
|
|
const expectedLeft =
|
|
|
|
|
"<tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-info">\n' +
|
|
|
|
|
' <div class="d2h-code-side-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-06 20:04:33 +00:00
|
|
|
expect(expectedRight).toEqual(fileHtml.right);
|
|
|
|
|
expect(expectedLeft).toEqual(fileHtml.left);
|
2015-12-22 15:48:33 +00:00
|
|
|
});
|
|
|
|
|
});
|
2015-12-23 16:05:30 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
describe("generateSideBySideFileHtml", function() {
|
|
|
|
|
it("should generate lines with the right prefixes", function() {
|
|
|
|
|
const sideBySidePrinter = new SideBySidePrinter({});
|
2015-12-23 16:05:30 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const file = {
|
|
|
|
|
blocks: [
|
2016-12-17 23:39:21 +00:00
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
lines: [
|
2016-12-17 23:39:21 +00:00
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: " context",
|
|
|
|
|
type: "d2h-cntx",
|
|
|
|
|
oldNumber: 19,
|
|
|
|
|
newNumber: 19
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "-removed",
|
|
|
|
|
type: "d2h-del",
|
|
|
|
|
oldNumber: 20,
|
|
|
|
|
newNumber: null
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "+added",
|
|
|
|
|
type: "d2h-ins",
|
|
|
|
|
oldNumber: null,
|
|
|
|
|
newNumber: 20
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "+another added",
|
|
|
|
|
type: "d2h-ins",
|
|
|
|
|
oldNumber: null,
|
|
|
|
|
newNumber: 21
|
2016-12-17 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
],
|
2019-10-06 20:04:33 +00:00
|
|
|
oldStartLine: "19",
|
|
|
|
|
newStartLine: "19",
|
|
|
|
|
header: "@@ -19,7 +19,7 @@"
|
2016-12-17 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
],
|
2019-10-06 20:04:33 +00:00
|
|
|
deletedLines: 1,
|
|
|
|
|
addedLines: 1,
|
|
|
|
|
checksumBefore: "fc56817",
|
|
|
|
|
checksumAfter: "e8e7e49",
|
|
|
|
|
mode: "100644",
|
|
|
|
|
oldName: "coverage.init",
|
|
|
|
|
language: "init",
|
|
|
|
|
newName: "coverage.init",
|
|
|
|
|
isCombined: false
|
2015-12-23 16:05:30 +00:00
|
|
|
};
|
|
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const fileHtml = sideBySidePrinter.generateSideBySideFileHtml(file);
|
2015-12-23 16:05:30 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expectedLeft =
|
|
|
|
|
"<tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-info"></td>\n' +
|
|
|
|
|
' <td class="d2h-info">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-info">@@ -19,7 +19,7 @@</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-cntx">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 19\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-cntx">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-cntx">\n' +
|
2019-07-06 17:51:50 +00:00
|
|
|
' <span class="d2h-code-line-prefix"> </span>\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <span class="d2h-code-line-ctn">context</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 20\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-del">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-del">\n' +
|
|
|
|
|
' <span class="d2h-code-line-prefix">-</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"><del>removed</del></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2018-11-14 21:18:39 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-code-side-emptyplaceholder d2h-cntx d2h-emptyplaceholder">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" " +
|
|
|
|
|
"\n" +
|
|
|
|
|
" </td>\n" +
|
2018-11-14 21:18:39 +00:00
|
|
|
' <td class="d2h-cntx d2h-emptyplaceholder">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-code-side-emptyplaceholder d2h-cntx d2h-emptyplaceholder">\n' +
|
2019-12-22 17:35:29 +00:00
|
|
|
' <span class="d2h-code-line-prefix"> </span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"> </span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2015-12-23 19:34:39 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expectedRight =
|
|
|
|
|
"<tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-info"></td>\n' +
|
|
|
|
|
' <td class="d2h-info">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-info"></div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-cntx">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 19\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-cntx">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-cntx">\n' +
|
2019-07-06 17:51:50 +00:00
|
|
|
' <span class="d2h-code-line-prefix"> </span>\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <span class="d2h-code-line-ctn">context</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-ins">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 20\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-ins">\n' +
|
|
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn"><ins>added</ins></span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-ins">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 21\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-ins">\n' +
|
|
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
2016-09-05 21:13:51 +00:00
|
|
|
' <span class="d2h-code-line-ctn">another added</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2015-12-23 16:05:30 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
expect(expectedLeft).toEqual(fileHtml.left);
|
|
|
|
|
expect(expectedRight).toEqual(fileHtml.right);
|
2015-12-23 16:05:30 +00:00
|
|
|
});
|
|
|
|
|
});
|
2015-12-30 21:01:41 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
describe("generateSingleLineHtml", function() {
|
|
|
|
|
it("should work for insertions", function() {
|
|
|
|
|
const diffParser = require("../diff-parser.js").DiffParser;
|
|
|
|
|
const sideBySidePrinter = new SideBySidePrinter({});
|
|
|
|
|
const fileHtml = sideBySidePrinter.generateSingleLineHtml(false, diffParser.LINE_TYPE.INSERTS, 30, "test", "+");
|
|
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-ins">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 30\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-ins">\n' +
|
|
|
|
|
' <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-30 21:01:41 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
expect(expected).toEqual(fileHtml);
|
2015-12-30 21:01:41 +00:00
|
|
|
});
|
2019-10-06 20:04:33 +00:00
|
|
|
it("should work for deletions", function() {
|
|
|
|
|
const diffParser = require("../diff-parser.js").DiffParser;
|
|
|
|
|
const sideBySidePrinter = new SideBySidePrinter({});
|
|
|
|
|
const fileHtml = sideBySidePrinter.generateSingleLineHtml(false, diffParser.LINE_TYPE.DELETES, 30, "test", "-");
|
|
|
|
|
const expected =
|
|
|
|
|
"<tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 30\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-del">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-del">\n' +
|
|
|
|
|
' <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-30 21:01:41 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
expect(expected).toEqual(fileHtml);
|
2015-12-30 21:01:41 +00:00
|
|
|
});
|
|
|
|
|
});
|
2016-04-25 16:12:27 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
describe("generateSideBySideJsonHtml", function() {
|
|
|
|
|
it("should work for list of files", function() {
|
|
|
|
|
const exampleJson = [
|
2016-12-17 23:39:21 +00:00
|
|
|
{
|
|
|
|
|
blocks: [
|
2016-04-25 16:12:27 +00:00
|
|
|
{
|
2016-12-17 23:39:21 +00:00
|
|
|
lines: [
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "-test",
|
|
|
|
|
type: "d2h-del",
|
2016-12-17 23:39:21 +00:00
|
|
|
oldNumber: 1,
|
|
|
|
|
newNumber: null
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "+test1r",
|
|
|
|
|
type: "d2h-ins",
|
2016-12-17 23:39:21 +00:00
|
|
|
oldNumber: null,
|
|
|
|
|
newNumber: 1
|
|
|
|
|
}
|
|
|
|
|
],
|
2019-10-06 20:04:33 +00:00
|
|
|
oldStartLine: "1",
|
2016-12-17 23:39:21 +00:00
|
|
|
oldStartLine2: null,
|
2019-10-06 20:04:33 +00:00
|
|
|
newStartLine: "1",
|
|
|
|
|
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",
|
2016-12-17 23:39:21 +00:00
|
|
|
language: undefined,
|
2019-10-06 20:04:33 +00:00
|
|
|
newName: "sample",
|
2016-12-17 23:39:21 +00:00
|
|
|
isCombined: false
|
|
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 16:12:27 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const sideBySidePrinter = new SideBySidePrinter({ matching: "lines" });
|
|
|
|
|
const html = sideBySidePrinter.generateSideBySideJsonHtml(exampleJson);
|
|
|
|
|
const expected =
|
2016-04-25 16:12:27 +00:00
|
|
|
'<div class="d2h-wrapper">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div id="d2h-675094" class="d2h-file-wrapper" data-lang="">\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-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-files-diff">\n' +
|
|
|
|
|
' <div class="d2h-file-side-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-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-info"></td>\n' +
|
|
|
|
|
' <td class="d2h-info">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-info">@@ -1 +1 @@</div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2019-06-14 15:18:09 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 1\n" +
|
|
|
|
|
" </td>\n" +
|
2019-06-14 15:18:09 +00:00
|
|
|
' <td class="d2h-del">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-del">\n' +
|
2016-05-21 00:34:03 +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>\n" +
|
|
|
|
|
" </tbody>\n" +
|
|
|
|
|
" </table>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-file-side-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-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-info"></td>\n' +
|
|
|
|
|
' <td class="d2h-info">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-info"></div>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr><tr>\n" +
|
2019-06-14 15:18:09 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-ins">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 1\n" +
|
|
|
|
|
" </td>\n" +
|
2019-06-14 15:18:09 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-ins">\n' +
|
2016-05-21 00:34:03 +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>\n" +
|
|
|
|
|
"</div>";
|
2016-04-25 16:12:27 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
expect(expected).toEqual(html);
|
2016-04-25 16:12:27 +00:00
|
|
|
});
|
2019-10-06 20:04:33 +00:00
|
|
|
it("should work for files without blocks", function() {
|
|
|
|
|
const exampleJson = [
|
|
|
|
|
{
|
|
|
|
|
blocks: [],
|
|
|
|
|
oldName: "sample",
|
|
|
|
|
language: "js",
|
|
|
|
|
newName: "sample",
|
|
|
|
|
isCombined: false
|
|
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 18:24:35 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const sideBySidePrinter = new SideBySidePrinter();
|
|
|
|
|
const html = sideBySidePrinter.generateSideBySideJsonHtml(exampleJson);
|
|
|
|
|
const expected =
|
2016-04-25 18:24:35 +00:00
|
|
|
'<div class="d2h-wrapper">\n' +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <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-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-files-diff">\n' +
|
|
|
|
|
' <div class="d2h-file-side-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-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-info">\n' +
|
|
|
|
|
' <div class="d2h-code-side-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" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <div class="d2h-file-side-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
|
|
|
" \n" +
|
|
|
|
|
" </tbody>\n" +
|
|
|
|
|
" </table>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
" </div>\n" +
|
|
|
|
|
"</div>\n" +
|
|
|
|
|
"</div>";
|
2016-04-25 18:24:35 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
expect(expected).toEqual(html);
|
2016-04-25 18:24:35 +00:00
|
|
|
});
|
2016-04-25 16:12:27 +00:00
|
|
|
});
|
2016-04-25 16:33:43 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
describe("processLines", function() {
|
|
|
|
|
it("should process file lines", function() {
|
|
|
|
|
const oldLines = [
|
|
|
|
|
{
|
|
|
|
|
content: "-test",
|
|
|
|
|
type: "d2h-del",
|
|
|
|
|
oldNumber: 1,
|
|
|
|
|
newNumber: null
|
|
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 16:33:43 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const newLines = [
|
|
|
|
|
{
|
|
|
|
|
content: "+test1r",
|
|
|
|
|
type: "d2h-ins",
|
|
|
|
|
oldNumber: null,
|
|
|
|
|
newNumber: 1
|
|
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 16:33:43 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const sideBySidePrinter = new SideBySidePrinter({ matching: "lines" });
|
|
|
|
|
const html = sideBySidePrinter.processLines(false, oldLines, newLines);
|
|
|
|
|
const expectedLeft =
|
|
|
|
|
"<tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-del">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 1\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-del">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-del">\n' +
|
|
|
|
|
' <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-04-25 16:33:43 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
const expectedRight =
|
|
|
|
|
"<tr>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-code-side-linenumber d2h-ins">\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" 1\n" +
|
|
|
|
|
" </td>\n" +
|
2016-05-21 00:34:03 +00:00
|
|
|
' <td class="d2h-ins">\n' +
|
|
|
|
|
' <div class="d2h-code-side-line d2h-ins">\n' +
|
|
|
|
|
' <span class="d2h-code-line-prefix">+</span>\n' +
|
|
|
|
|
' <span class="d2h-code-line-ctn">test1r</span>\n' +
|
2019-10-06 20:04:33 +00:00
|
|
|
" </div>\n" +
|
|
|
|
|
" </td>\n" +
|
|
|
|
|
"</tr>";
|
2016-04-25 16:33:43 +00:00
|
|
|
|
2019-10-06 20:04:33 +00:00
|
|
|
expect(expectedLeft).toEqual(html.left);
|
|
|
|
|
expect(expectedRight).toEqual(html.right);
|
2016-04-25 16:33:43 +00:00
|
|
|
});
|
|
|
|
|
});
|
2015-12-22 15:48:33 +00:00
|
|
|
});
|