2019-10-12 21:45:49 +00:00
|
|
|
import SideBySideRenderer from "../side-by-side-renderer";
|
|
|
|
|
import HoganJsUtils from "../hoganjs-utils";
|
2019-10-21 22:37:42 +00:00
|
|
|
import { LineType, DiffLine, DiffFile, LineMatchingType } from "../types";
|
|
|
|
|
import { CSSLineClass } from "../render-utils";
|
2015-12-22 15:48:33 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
describe("SideBySideRenderer", () => {
|
|
|
|
|
describe("generateEmptyDiff", () => {
|
|
|
|
|
it("should return an empty diff", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, {});
|
|
|
|
|
const fileHtml = sideBySideRenderer.generateEmptyDiff();
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(fileHtml).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"left": "<tr>
|
|
|
|
|
<td class=\\"d2h-info\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-info\\">
|
|
|
|
|
File without changes
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
"right": "",
|
|
|
|
|
}
|
|
|
|
|
`);
|
2015-12-22 15:48:33 +00:00
|
|
|
});
|
|
|
|
|
});
|
2015-12-23 16:05:30 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
describe("generateSideBySideFileHtml", () => {
|
|
|
|
|
it("should generate lines with the right prefixes", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, {});
|
2015-12-23 16:05:30 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const file: DiffFile = {
|
|
|
|
|
isGitDiff: true,
|
2019-10-06 20:04:33 +00:00
|
|
|
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",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.CONTEXT,
|
2019-10-06 20:04:33 +00:00
|
|
|
oldNumber: 19,
|
|
|
|
|
newNumber: 19
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "-removed",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.DELETE,
|
2019-10-06 20:04:33 +00:00
|
|
|
oldNumber: 20,
|
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: "+added",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2019-10-06 20:04:33 +00:00
|
|
|
newNumber: 20
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-06 20:04:33 +00:00
|
|
|
content: "+another added",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2019-10-06 20:04:33 +00:00
|
|
|
newNumber: 21
|
2016-12-17 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
],
|
2019-10-12 21:45:49 +00:00
|
|
|
oldStartLine: 19,
|
|
|
|
|
newStartLine: 19,
|
2019-10-06 20:04:33 +00:00
|
|
|
header: "@@ -19,7 +19,7 @@"
|
2016-12-17 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
],
|
2019-10-06 20:04:33 +00:00
|
|
|
deletedLines: 1,
|
2019-10-12 21:45:49 +00:00
|
|
|
addedLines: 2,
|
2019-10-06 20:04:33 +00:00
|
|
|
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-11-26 19:02:25 +00:00
|
|
|
const fileHtml = sideBySideRenderer.generateFileHtml(file);
|
2015-12-23 16:05:30 +00:00
|
|
|
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(fileHtml).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"left": "<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-info\\"></td>
|
|
|
|
|
<td class=\\"d2h-info\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-info\\">@@ -19,7 +19,7 @@</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-cntx\\">
|
|
|
|
|
19
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-cntx\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-cntx\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\"> </span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\">context</span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-del d2h-change\\">
|
|
|
|
|
20
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-del d2h-change\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-del d2h-change\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">-</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"><del>removed</del></span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-code-side-emptyplaceholder d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-code-side-emptyplaceholder d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\"> </span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"> </span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
"right": "<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-info\\"></td>
|
|
|
|
|
<td class=\\"d2h-info\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-info\\"></div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-cntx\\">
|
|
|
|
|
19
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-cntx\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-cntx\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\"> </span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\">context</span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-ins d2h-change\\">
|
|
|
|
|
20
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-ins d2h-change\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-ins d2h-change\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">+</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"><ins>added</ins></span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-ins\\">
|
|
|
|
|
21
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-ins\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-ins\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">+</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\">another added</span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
}
|
|
|
|
|
`);
|
2015-12-23 16:05:30 +00:00
|
|
|
});
|
|
|
|
|
});
|
2015-12-30 21:01:41 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
describe("generateSingleLineHtml", () => {
|
|
|
|
|
it("should work for insertions", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, {});
|
2019-11-26 23:57:47 +00:00
|
|
|
const fileHtml = sideBySideRenderer.generateLineHtml(undefined, {
|
2019-11-26 19:02:25 +00:00
|
|
|
type: CSSLineClass.INSERTS,
|
|
|
|
|
prefix: "+",
|
|
|
|
|
content: "test",
|
|
|
|
|
number: 30
|
|
|
|
|
});
|
|
|
|
|
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(fileHtml).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"left": "<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-code-side-emptyplaceholder d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-code-side-emptyplaceholder d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\"> </span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"> </span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
"right": "<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-ins\\">
|
|
|
|
|
30
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-ins\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-ins\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">+</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\">test</span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
}
|
|
|
|
|
`);
|
2015-12-30 21:01:41 +00:00
|
|
|
});
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should work for deletions", () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, {});
|
2019-11-26 23:57:47 +00:00
|
|
|
const fileHtml = sideBySideRenderer.generateLineHtml(
|
2019-11-26 19:02:25 +00:00
|
|
|
{
|
|
|
|
|
type: CSSLineClass.DELETES,
|
|
|
|
|
prefix: "-",
|
|
|
|
|
content: "test",
|
|
|
|
|
number: 30
|
|
|
|
|
},
|
|
|
|
|
undefined
|
|
|
|
|
);
|
2015-12-30 21:01:41 +00:00
|
|
|
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(fileHtml).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"left": "<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-del\\">
|
|
|
|
|
30
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-del\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-del\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">-</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\">test</span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
"right": "<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-code-side-emptyplaceholder d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-code-side-emptyplaceholder d2h-cntx d2h-emptyplaceholder\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\"> </span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"> </span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
}
|
|
|
|
|
`);
|
2015-12-30 21:01:41 +00:00
|
|
|
});
|
|
|
|
|
});
|
2016-04-25 16:12:27 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
describe("generateSideBySideJsonHtml", () => {
|
|
|
|
|
it("should work for list of files", () => {
|
|
|
|
|
const exampleJson: DiffFile[] = [
|
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",
|
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",
|
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-12-17 23:39:21 +00:00
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 16:12:27 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const hoganUtils = new HoganJsUtils({});
|
2019-10-21 22:37:42 +00:00
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, { matching: LineMatchingType.LINES });
|
2019-10-12 21:45:49 +00:00
|
|
|
const html = sideBySideRenderer.render(exampleJson);
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(html).toMatchInlineSnapshot(`
|
|
|
|
|
"<div class=\\"d2h-wrapper\\">
|
|
|
|
|
<div id=\\"d2h-675094\\" class=\\"d2h-file-wrapper\\" data-lang=\\"txt\\">
|
|
|
|
|
<div class=\\"d2h-file-header\\">
|
|
|
|
|
<span class=\\"d2h-file-name-wrapper\\">
|
|
|
|
|
<svg aria-hidden=\\"true\\" class=\\"d2h-icon\\" height=\\"16\\" version=\\"1.1\\" viewBox=\\"0 0 12 16\\" width=\\"12\\">
|
|
|
|
|
<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>
|
|
|
|
|
</svg> <span class=\\"d2h-file-name\\">sample</span>
|
|
|
|
|
<span class=\\"d2h-tag d2h-changed d2h-changed-tag\\">CHANGED</span></span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class=\\"d2h-files-diff\\">
|
|
|
|
|
<div class=\\"d2h-file-side-diff\\">
|
|
|
|
|
<div class=\\"d2h-code-wrapper\\">
|
|
|
|
|
<table class=\\"d2h-diff-table\\">
|
|
|
|
|
<tbody class=\\"d2h-diff-tbody\\">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-info\\"></td>
|
|
|
|
|
<td class=\\"d2h-info\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-info\\">@@ -1 +1 @@</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-del d2h-change\\">
|
|
|
|
|
1
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-del d2h-change\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-del d2h-change\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">-</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"><del>test</del></span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class=\\"d2h-file-side-diff\\">
|
|
|
|
|
<div class=\\"d2h-code-wrapper\\">
|
|
|
|
|
<table class=\\"d2h-diff-table\\">
|
|
|
|
|
<tbody class=\\"d2h-diff-tbody\\">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-info\\"></td>
|
|
|
|
|
<td class=\\"d2h-info\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-info\\"></div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-ins d2h-change\\">
|
|
|
|
|
1
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-ins d2h-change\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-ins d2h-change\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">+</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"><ins>test1r</ins></span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>"
|
|
|
|
|
`);
|
2016-04-25 16:12:27 +00:00
|
|
|
});
|
2019-10-12 21:45:49 +00:00
|
|
|
it("should work for files without blocks", () => {
|
|
|
|
|
const exampleJson: DiffFile[] = [
|
2019-10-06 20:04:33 +00:00
|
|
|
{
|
|
|
|
|
blocks: [],
|
|
|
|
|
oldName: "sample",
|
|
|
|
|
language: "js",
|
|
|
|
|
newName: "sample",
|
2019-10-12 21:45:49 +00:00
|
|
|
isCombined: false,
|
|
|
|
|
addedLines: 0,
|
|
|
|
|
deletedLines: 0,
|
|
|
|
|
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 sideBySideRenderer = new SideBySideRenderer(hoganUtils, {});
|
|
|
|
|
const html = sideBySideRenderer.render(exampleJson);
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(html).toMatchInlineSnapshot(`
|
|
|
|
|
"<div class=\\"d2h-wrapper\\">
|
|
|
|
|
<div id=\\"d2h-675094\\" class=\\"d2h-file-wrapper\\" data-lang=\\"js\\">
|
|
|
|
|
<div class=\\"d2h-file-header\\">
|
|
|
|
|
<span class=\\"d2h-file-name-wrapper\\">
|
|
|
|
|
<svg aria-hidden=\\"true\\" class=\\"d2h-icon\\" height=\\"16\\" version=\\"1.1\\" viewBox=\\"0 0 12 16\\" width=\\"12\\">
|
|
|
|
|
<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>
|
|
|
|
|
</svg> <span class=\\"d2h-file-name\\">sample</span>
|
|
|
|
|
<span class=\\"d2h-tag d2h-changed d2h-changed-tag\\">CHANGED</span></span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class=\\"d2h-files-diff\\">
|
|
|
|
|
<div class=\\"d2h-file-side-diff\\">
|
|
|
|
|
<div class=\\"d2h-code-wrapper\\">
|
|
|
|
|
<table class=\\"d2h-diff-table\\">
|
|
|
|
|
<tbody class=\\"d2h-diff-tbody\\">
|
|
|
|
|
<tr>
|
|
|
|
|
<td class=\\"d2h-info\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-info\\">
|
|
|
|
|
File without changes
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class=\\"d2h-file-side-diff\\">
|
|
|
|
|
<div class=\\"d2h-code-wrapper\\">
|
|
|
|
|
<table class=\\"d2h-diff-table\\">
|
|
|
|
|
<tbody class=\\"d2h-diff-tbody\\">
|
|
|
|
|
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>"
|
|
|
|
|
`);
|
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-12 21:45:49 +00:00
|
|
|
describe("processLines", () => {
|
|
|
|
|
it("should process file lines", () => {
|
|
|
|
|
const oldLines: DiffLine[] = [
|
2019-10-06 20:04:33 +00:00
|
|
|
{
|
|
|
|
|
content: "-test",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.DELETE,
|
2019-10-06 20:04:33 +00:00
|
|
|
oldNumber: 1,
|
2019-10-12 21:45:49 +00:00
|
|
|
newNumber: undefined
|
2019-10-06 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 16:33:43 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const newLines: DiffLine[] = [
|
2019-10-06 20:04:33 +00:00
|
|
|
{
|
|
|
|
|
content: "+test1r",
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2019-10-06 20:04:33 +00:00
|
|
|
newNumber: 1
|
|
|
|
|
}
|
|
|
|
|
];
|
2016-04-25 16:33:43 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
const hoganUtils = new HoganJsUtils({});
|
2019-10-21 22:37:42 +00:00
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, { matching: LineMatchingType.LINES });
|
2019-11-26 23:57:47 +00:00
|
|
|
const html = sideBySideRenderer.processChangedLines(false, oldLines, newLines);
|
2016-04-25 16:33:43 +00:00
|
|
|
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(html).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"left": "<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-del d2h-change\\">
|
|
|
|
|
1
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-del d2h-change\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-del d2h-change\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">-</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"><del>test</del></span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
"right": "<tr>
|
|
|
|
|
<td class=\\"d2h-code-side-linenumber d2h-ins d2h-change\\">
|
|
|
|
|
1
|
|
|
|
|
</td>
|
|
|
|
|
<td class=\\"d2h-ins d2h-change\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-ins d2h-change\\">
|
|
|
|
|
<span class=\\"d2h-code-line-prefix\\">+</span>
|
|
|
|
|
<span class=\\"d2h-code-line-ctn\\"><ins>test1r</ins></span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
}
|
|
|
|
|
`);
|
2016-04-25 16:33:43 +00:00
|
|
|
});
|
|
|
|
|
});
|
2015-12-22 15:48:33 +00:00
|
|
|
});
|