2019-12-29 22:31:32 +00:00
|
|
|
import SideBySideRenderer from '../side-by-side-renderer';
|
|
|
|
|
import HoganJsUtils from '../hoganjs-utils';
|
|
|
|
|
import { LineType, DiffLine, DiffFile, LineMatchingType } from '../types';
|
|
|
|
|
import { CSSLineClass } from '../render-utils';
|
2015-12-22 15:48:33 +00:00
|
|
|
|
2019-12-29 22:31:32 +00:00
|
|
|
describe('SideBySideRenderer', () => {
|
|
|
|
|
describe('generateEmptyDiff', () => {
|
|
|
|
|
it('should return an empty diff', () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
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
|
|
|
|
2021-02-25 19:08:18 +00:00
|
|
|
describe('_generateTooBigDiff', () => {
|
|
|
|
|
it('should return a diff with default "too big" message when no `diffTooBigMessage` is defined', () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, {});
|
|
|
|
|
const fileHtml = sideBySideRenderer.generateTooBigDiff(0);
|
|
|
|
|
expect(fileHtml).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"left": "<tr>
|
|
|
|
|
<td class=\\"d2h-info\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-info\\">
|
|
|
|
|
Diff too big to be displayed
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
"right": "",
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return a diff with custom "too big" message when `diffTooBigMessage` is defined', () => {
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const customMessageFn = (fIndex: number) => `Custom message for file ${fIndex} diff too big`;
|
|
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, { diffTooBigMessage: customMessageFn });
|
|
|
|
|
const fileHtml = sideBySideRenderer.generateTooBigDiff(0);
|
|
|
|
|
expect(fileHtml).toMatchInlineSnapshot(`
|
|
|
|
|
Object {
|
|
|
|
|
"left": "<tr>
|
|
|
|
|
<td class=\\"d2h-info\\">
|
|
|
|
|
<div class=\\"d2h-code-side-line d2h-info\\">
|
|
|
|
|
Custom message for file 0 diff too big
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
"right": "",
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2019-12-29 22:31:32 +00:00
|
|
|
describe('generateSideBySideFileHtml', () => {
|
|
|
|
|
it('should generate lines with the right prefixes', () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
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-12-29 22:31:32 +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,
|
2019-12-29 22:31:32 +00:00
|
|
|
newNumber: 19,
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-12-29 22:31:32 +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-12-29 22:31:32 +00:00
|
|
|
newNumber: undefined,
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-12-29 22:31:32 +00:00
|
|
|
content: '+added',
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2019-12-29 22:31:32 +00:00
|
|
|
newNumber: 20,
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-12-29 22:31:32 +00:00
|
|
|
content: '+another added',
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2019-12-29 22:31:32 +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-12-29 22:31:32 +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-12-29 22:31:32 +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(`
|
2021-01-23 15:07:14 +00:00
|
|
|
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\\"><br></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-12-29 22:31:32 +00:00
|
|
|
describe('generateSingleLineHtml', () => {
|
|
|
|
|
it('should work for insertions', () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
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,
|
2019-12-29 22:31:32 +00:00
|
|
|
prefix: '+',
|
|
|
|
|
content: 'test',
|
|
|
|
|
number: 30,
|
2019-11-26 19:02:25 +00:00
|
|
|
});
|
|
|
|
|
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(fileHtml).toMatchInlineSnapshot(`
|
2021-01-23 15:07:14 +00:00
|
|
|
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\\"><br></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-12-29 22:31:32 +00:00
|
|
|
it('should work for deletions', () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
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,
|
2019-12-29 22:31:32 +00:00
|
|
|
prefix: '-',
|
|
|
|
|
content: 'test',
|
|
|
|
|
number: 30,
|
2019-11-26 19:02:25 +00:00
|
|
|
},
|
2019-12-29 22:31:32 +00:00
|
|
|
undefined,
|
2019-11-26 19:02:25 +00:00
|
|
|
);
|
2015-12-30 21:01:41 +00:00
|
|
|
|
2019-12-22 19:52:51 +00:00
|
|
|
expect(fileHtml).toMatchInlineSnapshot(`
|
2021-01-23 15:07:14 +00:00
|
|
|
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\\"><br></span>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>",
|
|
|
|
|
}
|
|
|
|
|
`);
|
2015-12-30 21:01:41 +00:00
|
|
|
});
|
|
|
|
|
});
|
2016-04-25 16:12:27 +00:00
|
|
|
|
2019-12-29 22:31:32 +00:00
|
|
|
describe('generateSideBySideJsonHtml', () => {
|
|
|
|
|
it('should work for list of files', () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
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-12-29 22:31:32 +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-12-29 22:31:32 +00:00
|
|
|
newNumber: undefined,
|
2016-12-17 23:39:21 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-12-29 22:31:32 +00:00
|
|
|
content: '+test1r',
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2019-12-29 22:31:32 +00:00
|
|
|
newNumber: 1,
|
|
|
|
|
},
|
2016-12-17 23:39:21 +00:00
|
|
|
],
|
2019-10-12 21:45:49 +00:00
|
|
|
oldStartLine: 1,
|
|
|
|
|
oldStartLine2: undefined,
|
|
|
|
|
newStartLine: 1,
|
2019-12-29 22:31:32 +00:00
|
|
|
header: '@@ -1 +1 @@',
|
|
|
|
|
},
|
2016-12-17 23:39:21 +00:00
|
|
|
],
|
|
|
|
|
deletedLines: 1,
|
|
|
|
|
addedLines: 1,
|
2019-12-29 22:31:32 +00:00
|
|
|
checksumBefore: '0000001',
|
|
|
|
|
checksumAfter: '0ddf2ba',
|
|
|
|
|
oldName: 'sample',
|
|
|
|
|
language: 'txt',
|
|
|
|
|
newName: 'sample',
|
2019-10-12 21:45:49 +00:00
|
|
|
isCombined: false,
|
2019-12-29 22:31:32 +00:00
|
|
|
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>
|
2021-01-23 15:07:14 +00:00
|
|
|
<label class=\\"d2h-file-collapse\\">
|
|
|
|
|
<input class=\\"d2h-file-collapse-input\\" type=\\"checkbox\\" name=\\"viewed\\" value=\\"viewed\\">
|
|
|
|
|
Viewed
|
|
|
|
|
</label>
|
2019-12-22 19:52:51 +00:00
|
|
|
</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-12-29 22:31:32 +00:00
|
|
|
it('should work for files without blocks', () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
const exampleJson: DiffFile[] = [
|
2019-10-06 20:04:33 +00:00
|
|
|
{
|
|
|
|
|
blocks: [],
|
2019-12-29 22:31:32 +00:00
|
|
|
oldName: 'sample',
|
|
|
|
|
language: 'js',
|
|
|
|
|
newName: 'sample',
|
2019-10-12 21:45:49 +00:00
|
|
|
isCombined: false,
|
|
|
|
|
addedLines: 0,
|
|
|
|
|
deletedLines: 0,
|
2019-12-29 22:31:32 +00:00
|
|
|
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>
|
2021-01-23 15:07:14 +00:00
|
|
|
<label class=\\"d2h-file-collapse\\">
|
|
|
|
|
<input class=\\"d2h-file-collapse-input\\" type=\\"checkbox\\" name=\\"viewed\\" value=\\"viewed\\">
|
|
|
|
|
Viewed
|
|
|
|
|
</label>
|
2019-12-22 19:52:51 +00:00
|
|
|
</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>
|
2021-02-25 19:08:18 +00:00
|
|
|
</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>"
|
|
|
|
|
`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should work for too big file diff and no custom message fn', () => {
|
|
|
|
|
const exampleJson = [
|
|
|
|
|
{
|
|
|
|
|
blocks: [],
|
|
|
|
|
deletedLines: 0,
|
|
|
|
|
addedLines: 0,
|
|
|
|
|
oldName: 'sample',
|
|
|
|
|
language: 'js',
|
|
|
|
|
newName: 'sample',
|
|
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: false,
|
|
|
|
|
isTooBig: true,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils);
|
|
|
|
|
const html = sideBySideRenderer.render(exampleJson);
|
|
|
|
|
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>
|
|
|
|
|
<label class=\\"d2h-file-collapse\\">
|
|
|
|
|
<input class=\\"d2h-file-collapse-input\\" type=\\"checkbox\\" name=\\"viewed\\" value=\\"viewed\\">
|
|
|
|
|
Viewed
|
|
|
|
|
</label>
|
|
|
|
|
</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\\">
|
|
|
|
|
Diff too big to be displayed
|
|
|
|
|
</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>"
|
|
|
|
|
`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should work for too big file diff and custom message fn', () => {
|
|
|
|
|
const exampleJson = [
|
|
|
|
|
{
|
|
|
|
|
blocks: [],
|
|
|
|
|
deletedLines: 0,
|
|
|
|
|
addedLines: 0,
|
|
|
|
|
oldName: 'sample',
|
|
|
|
|
language: 'js',
|
|
|
|
|
newName: 'sample',
|
|
|
|
|
isCombined: false,
|
|
|
|
|
isGitDiff: false,
|
|
|
|
|
isTooBig: true,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const hoganUtils = new HoganJsUtils({});
|
|
|
|
|
const customMessageFn = (fIndex: number) => `Custom message for file ${fIndex} diff too big`;
|
|
|
|
|
const sideBySideRenderer = new SideBySideRenderer(hoganUtils, { diffTooBigMessage: customMessageFn });
|
|
|
|
|
const html = sideBySideRenderer.render(exampleJson);
|
|
|
|
|
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>
|
|
|
|
|
<label class=\\"d2h-file-collapse\\">
|
|
|
|
|
<input class=\\"d2h-file-collapse-input\\" type=\\"checkbox\\" name=\\"viewed\\" value=\\"viewed\\">
|
|
|
|
|
Viewed
|
|
|
|
|
</label>
|
|
|
|
|
</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\\">
|
|
|
|
|
Custom message for file 0 diff too big
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
2019-12-22 19:52:51 +00:00
|
|
|
</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-12-29 22:31:32 +00:00
|
|
|
describe('processLines', () => {
|
|
|
|
|
it('should process file lines', () => {
|
2019-10-12 21:45:49 +00:00
|
|
|
const oldLines: DiffLine[] = [
|
2019-10-06 20:04:33 +00:00
|
|
|
{
|
2019-12-29 22:31:32 +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-12-29 22:31:32 +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
|
|
|
{
|
2019-12-29 22:31:32 +00:00
|
|
|
content: '+test1r',
|
2019-10-12 21:45:49 +00:00
|
|
|
type: LineType.INSERT,
|
|
|
|
|
oldNumber: undefined,
|
2019-12-29 22:31:32 +00:00
|
|
|
newNumber: 1,
|
|
|
|
|
},
|
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 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
|
|
|
});
|