2022-06-19 00:25:21 +00:00
|
|
|
import {expect} from "chai";
|
|
|
|
import merge from "../../../../../client/js/helpers/ircmessageparser/merge";
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
describe("merge", () => {
|
|
|
|
it("should split style information", () => {
|
2019-07-17 09:33:59 +00:00
|
|
|
const textParts = [
|
|
|
|
{
|
|
|
|
start: 0,
|
|
|
|
end: 10,
|
|
|
|
flag1: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
start: 10,
|
|
|
|
end: 20,
|
|
|
|
flag2: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const styleFragments = [
|
|
|
|
{
|
2017-03-18 08:18:47 +00:00
|
|
|
start: 0,
|
|
|
|
end: 5,
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "01234",
|
2019-07-17 09:33:59 +00:00
|
|
|
},
|
|
|
|
{
|
2017-03-18 08:18:47 +00:00
|
|
|
start: 5,
|
|
|
|
end: 15,
|
2019-07-17 09:33:59 +00:00
|
|
|
text: "5678901234",
|
|
|
|
},
|
|
|
|
{
|
2017-03-18 08:18:47 +00:00
|
|
|
start: 15,
|
|
|
|
end: 20,
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "56789",
|
2019-07-17 09:33:59 +00:00
|
|
|
},
|
|
|
|
];
|
2017-03-18 08:18:47 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
const expected = [
|
|
|
|
{
|
|
|
|
start: 0,
|
|
|
|
end: 10,
|
|
|
|
flag1: true,
|
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
start: 0,
|
|
|
|
end: 5,
|
|
|
|
text: "01234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
start: 5,
|
|
|
|
end: 10,
|
|
|
|
text: "56789",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
start: 10,
|
|
|
|
end: 20,
|
|
|
|
flag2: true,
|
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
start: 10,
|
|
|
|
end: 15,
|
|
|
|
text: "01234",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
start: 15,
|
|
|
|
end: 20,
|
|
|
|
text: "56789",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const actual = merge(
|
2022-06-19 00:25:21 +00:00
|
|
|
textParts as any,
|
2019-07-17 09:33:59 +00:00
|
|
|
styleFragments,
|
|
|
|
styleFragments.map((fragment) => fragment.text).join("")
|
|
|
|
);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
2018-05-07 18:19:54 +00:00
|
|
|
|
|
|
|
it("should not drop clean text", () => {
|
2019-07-17 09:33:59 +00:00
|
|
|
const textParts = [
|
|
|
|
{
|
2018-05-07 18:19:54 +00:00
|
|
|
start: 0,
|
|
|
|
end: 52,
|
2019-07-17 09:33:59 +00:00
|
|
|
link: "https://github.com/xPaw/PHP-Source-Query/runs/175079",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const styleFragments = [
|
|
|
|
{
|
2018-05-07 18:19:54 +00:00
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
2019-07-17 09:33:59 +00:00
|
|
|
text: "https://github.com/xPaw/PHP-Source-Query/runs/175079 here's some text",
|
|
|
|
start: 0,
|
|
|
|
end: 69,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const expected = [
|
|
|
|
{
|
|
|
|
link: "https://github.com/xPaw/PHP-Source-Query/runs/175079",
|
|
|
|
start: 0,
|
|
|
|
end: 52,
|
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "https://github.com/xPaw/PHP-Source-Query/runs/175079",
|
|
|
|
start: 0,
|
|
|
|
end: 52,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2018-05-07 18:19:54 +00:00
|
|
|
start: 52,
|
|
|
|
end: 69,
|
2019-07-17 09:33:59 +00:00
|
|
|
fragments: [
|
|
|
|
{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: " here's some text",
|
|
|
|
start: 52,
|
|
|
|
end: 69,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2018-05-07 18:19:54 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
const actual = merge(
|
|
|
|
textParts,
|
|
|
|
styleFragments,
|
|
|
|
styleFragments.map((fragment) => fragment.text).join("")
|
|
|
|
);
|
2018-05-07 18:19:54 +00:00
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
2017-03-18 08:18:47 +00:00
|
|
|
});
|