Debian Codegraph @

tests/js/sphinx_highlight.spec.js

raw
1 describe("highlightText", function () {
2 const cyrillicTerm = "шеллы";
3 const umlautTerm = "gänsefüßchen";
4
5 it("should highlight text incl. special characters correctly in HTML", function () {
6 const highlightTestSpan = new DOMParser().parseFromString(
7 "<span>This is the шеллы and Gänsefüßchen test!</span>",
8 "text/html",
9 ).body.firstChild;
10 _highlightText(highlightTestSpan, cyrillicTerm, "highlighted");
11 _highlightText(highlightTestSpan, umlautTerm, "highlighted");
12 const expectedHtmlString =
13 'This is the <span class=\"highlighted\">шеллы</span> and '
14 + '<span class=\"highlighted\">Gänsefüßchen</span> test!';
15 expect(highlightTestSpan.innerHTML).toEqual(expectedHtmlString);
16 });
17
18 it("should highlight text incl. special characters correctly in SVG", function () {
19 const highlightTestSvg = new DOMParser().parseFromString(
20 '<span id="svg-highlight-test">'
21 + '<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">'
22 + '<text x="0" y="15">'
23 + "This is the шеллы and Gänsefüßchen test!"
24 + "</text>"
25 + "</svg>"
26 + "</span>",
27 "text/html",
28 ).body.firstChild;
29 _highlightText(highlightTestSvg, cyrillicTerm, "highlighted");
30 _highlightText(highlightTestSvg, umlautTerm, "highlighted");
31 /* Note wild cards and ``toMatch``; allowing for some variability
32 seems to be necessary, even between different FF versions */
33 const expectedSvgString =
34 '<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">'
35 + '<rect x=".*" y=".*" width=".*" height=".*" class="highlighted"/>'
36 + '<rect x=".*" y=".*" width=".*" height=".*" class="highlighted"/>'
37 + '<text x=".*" y=".*">This is the <tspan>шеллы</tspan> and '
38 + "<tspan>Gänsefüßchen</tspan> test!</text></svg>";
39 expect(
40 new XMLSerializer().serializeToString(highlightTestSvg.firstChild),
41 ).toMatch(new RegExp(expectedSvgString));
42 });
43 });