2019-10-12 21:45:49 +00:00
|
|
|
import * as renderUtils from "../render-utils";
|
2019-10-06 20:04:33 +00:00
|
|
|
|
|
|
|
|
describe("Utils", function() {
|
|
|
|
|
describe("getHtmlId", function() {
|
|
|
|
|
it("should generate file unique id", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.getHtmlId({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "sample.js",
|
|
|
|
|
newName: "sample.js"
|
|
|
|
|
});
|
|
|
|
|
expect("d2h-960013").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
it("should generate file unique id for empty hashes", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.getHtmlId({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "sample.js",
|
|
|
|
|
newName: "sample.js"
|
|
|
|
|
});
|
|
|
|
|
expect("d2h-960013").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("getDiffName", function() {
|
|
|
|
|
it("should generate the file name for a changed file", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.filenameDiff({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "sample.js",
|
|
|
|
|
newName: "sample.js"
|
|
|
|
|
});
|
|
|
|
|
expect("sample.js").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
it("should generate the file name for a changed file and full rename", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.filenameDiff({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "sample1.js",
|
|
|
|
|
newName: "sample2.js"
|
|
|
|
|
});
|
|
|
|
|
expect("sample1.js → sample2.js").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
it("should generate the file name for a changed file and prefix rename", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.filenameDiff({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "src/path/sample.js",
|
|
|
|
|
newName: "source/path/sample.js"
|
|
|
|
|
});
|
|
|
|
|
expect("{src → source}/path/sample.js").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
it("should generate the file name for a changed file and suffix rename", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.filenameDiff({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "src/path/sample1.js",
|
|
|
|
|
newName: "src/path/sample2.js"
|
|
|
|
|
});
|
|
|
|
|
expect("src/path/{sample1.js → sample2.js}").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
it("should generate the file name for a changed file and middle rename", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.filenameDiff({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "src/really/big/path/sample.js",
|
|
|
|
|
newName: "src/small/path/sample.js"
|
|
|
|
|
});
|
|
|
|
|
expect("src/{really/big → small}/path/sample.js").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
it("should generate the file name for a deleted file", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.filenameDiff({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "src/my/file.js",
|
|
|
|
|
newName: "/dev/null"
|
|
|
|
|
});
|
|
|
|
|
expect("src/my/file.js").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
it("should generate the file name for a new file", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.filenameDiff({
|
2019-10-06 20:04:33 +00:00
|
|
|
oldName: "/dev/null",
|
|
|
|
|
newName: "src/my/file.js"
|
|
|
|
|
});
|
|
|
|
|
expect("src/my/file.js").toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("diffHighlight", function() {
|
|
|
|
|
it("should highlight two lines", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.diffHighlight("-var myVar = 2;", "+var myVariable = 3;", false, {
|
|
|
|
|
matching: "words"
|
|
|
|
|
});
|
2019-10-06 20:04:33 +00:00
|
|
|
|
2019-10-12 21:45:49 +00:00
|
|
|
expect(result).toEqual({
|
|
|
|
|
oldLine: {
|
2019-10-06 20:04:33 +00:00
|
|
|
prefix: "-",
|
2019-10-12 21:45:49 +00:00
|
|
|
content: "var <del>myVar</del> = <del>2</del>;"
|
2019-10-06 20:04:33 +00:00
|
|
|
},
|
2019-10-12 21:45:49 +00:00
|
|
|
newLine: {
|
2019-10-06 20:04:33 +00:00
|
|
|
prefix: "+",
|
2019-10-12 21:45:49 +00:00
|
|
|
content: "var <ins>myVariable</ins> = <ins>3</ins>;"
|
2019-10-06 20:04:33 +00:00
|
|
|
}
|
2019-10-12 21:45:49 +00:00
|
|
|
});
|
2019-10-06 20:04:33 +00:00
|
|
|
});
|
|
|
|
|
it("should highlight two lines char by char", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.diffHighlight("-var myVar = 2;", "+var myVariable = 3;", false, { diffStyle: "char" });
|
2019-10-06 20:04:33 +00:00
|
|
|
|
|
|
|
|
expect({
|
2019-10-12 21:45:49 +00:00
|
|
|
oldLine: {
|
2019-10-06 20:04:33 +00:00
|
|
|
prefix: "-",
|
2019-10-12 21:45:49 +00:00
|
|
|
content: "var myVar = <del>2</del>;"
|
2019-10-06 20:04:33 +00:00
|
|
|
},
|
2019-10-12 21:45:49 +00:00
|
|
|
newLine: {
|
2019-10-06 20:04:33 +00:00
|
|
|
prefix: "+",
|
2019-10-12 21:45:49 +00:00
|
|
|
content: "var myVar<ins>iable</ins> = <ins>3</ins>;"
|
2019-10-06 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
}).toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
it("should highlight combined diff lines", function() {
|
2019-10-12 21:45:49 +00:00
|
|
|
const result = renderUtils.diffHighlight(" -var myVar = 2;", " +var myVariable = 3;", true, {
|
2019-10-06 20:04:33 +00:00
|
|
|
diffStyle: "word",
|
|
|
|
|
matching: "words",
|
|
|
|
|
matchWordsThreshold: 1.0
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect({
|
2019-10-12 21:45:49 +00:00
|
|
|
oldLine: {
|
2019-10-06 20:04:33 +00:00
|
|
|
prefix: " -",
|
2019-10-12 21:45:49 +00:00
|
|
|
content: 'var <del class="d2h-change">myVar</del> = <del class="d2h-change">2</del>;'
|
2019-10-06 20:04:33 +00:00
|
|
|
},
|
2019-10-12 21:45:49 +00:00
|
|
|
newLine: {
|
2019-10-06 20:04:33 +00:00
|
|
|
prefix: " +",
|
2019-10-12 21:45:49 +00:00
|
|
|
content: 'var <ins class="d2h-change">myVariable</ins> = <ins class="d2h-change">3</ins>;'
|
2019-10-06 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
}).toEqual(result);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|